27
27
#include "base/gimphistogram.h"
28
28
#include "base/pixel-region.h"
30
#include "config/gimpbaseconfig.h"
32
30
#include "core/gimp.h"
33
31
#include "core/gimpdrawable.h"
34
32
#include "core/gimpdrawable-histogram.h"
35
33
#include "core/gimpimage.h"
37
35
#include "gimpdocked.h"
38
#include "gimpenumcombobox.h"
39
#include "gimpenumstore.h"
40
36
#include "gimphelp-ids.h"
41
37
#include "gimphistogrambox.h"
42
38
#include "gimphistogrameditor.h"
43
39
#include "gimphistogramview.h"
44
#include "gimppropwidgets.h"
45
40
#include "gimpsessioninfo.h"
46
41
#include "gimpwidgets-utils.h"
48
43
#include "gimp-intl.h"
51
static void gimp_histogram_editor_class_init (GimpHistogramEditorClass *klass);
52
static void gimp_histogram_editor_init (GimpHistogramEditor *editor);
53
static void gimp_histogram_editor_docked_iface_init (GimpDockedInterface *docked_iface);
46
static void gimp_histogram_editor_docked_iface_init (GimpDockedInterface *iface);
54
48
static void gimp_histogram_editor_set_aux_info (GimpDocked *docked,
56
50
static GList * gimp_histogram_editor_get_aux_info (GimpDocked *docked);
58
52
static void gimp_histogram_editor_set_image (GimpImageEditor *editor,
60
static void gimp_histogram_editor_layer_changed (GimpImage *gimage,
54
static void gimp_histogram_editor_layer_changed (GimpImage *image,
61
55
GimpHistogramEditor *editor);
62
56
static void gimp_histogram_editor_update (GimpHistogramEditor *editor);
64
58
static gboolean gimp_histogram_editor_idle_update (GimpHistogramEditor *editor);
65
static gboolean gimp_histogram_editor_item_visible (GtkTreeModel *model,
59
static gboolean gimp_histogram_menu_sensitivity (gint value,
68
61
static void gimp_histogram_editor_menu_update (GimpHistogramEditor *editor);
62
static void gimp_histogram_editor_name_update (GimpHistogramEditor *editor);
69
63
static void gimp_histogram_editor_info_update (GimpHistogramEditor *editor);
72
static GimpImageEditorClass *parent_class = NULL;
73
static GimpDockedInterface *parent_docked_iface = NULL;
77
gimp_histogram_editor_get_type (void)
79
static GType editor_type = 0;
83
static const GTypeInfo editor_info =
85
sizeof (GimpHistogramEditorClass),
87
(GBaseFinalizeFunc) NULL,
88
(GClassInitFunc) gimp_histogram_editor_class_init,
89
NULL, /* class_finalize */
90
NULL, /* class_data */
91
sizeof (GimpHistogramEditor),
93
(GInstanceInitFunc) gimp_histogram_editor_init,
95
static const GInterfaceInfo docked_iface_info =
97
(GInterfaceInitFunc) gimp_histogram_editor_docked_iface_init,
98
NULL, /* iface_finalize */
102
editor_type = g_type_register_static (GIMP_TYPE_IMAGE_EDITOR,
103
"GimpHistogramEditor",
105
g_type_add_interface_static (editor_type, GIMP_TYPE_DOCKED,
65
static gboolean gimp_histogram_view_expose (GimpHistogramEditor *editor);
68
G_DEFINE_TYPE_WITH_CODE (GimpHistogramEditor, gimp_histogram_editor,
69
GIMP_TYPE_IMAGE_EDITOR,
70
G_IMPLEMENT_INTERFACE (GIMP_TYPE_DOCKED,
71
gimp_histogram_editor_docked_iface_init))
73
#define parent_class gimp_histogram_editor_parent_class
75
static GimpDockedInterface *parent_docked_iface = NULL;
113
79
gimp_histogram_editor_class_init (GimpHistogramEditorClass* klass)
115
81
GimpImageEditorClass *image_editor_class = GIMP_IMAGE_EDITOR_CLASS (klass);
117
parent_class = g_type_class_peek_parent (klass);
119
83
image_editor_class->set_image = gimp_histogram_editor_set_image;
142
106
editor->drawable = NULL;
143
107
editor->histogram = NULL;
108
editor->valid = FALSE;
144
109
editor->idle_id = 0;
145
110
editor->box = gimp_histogram_box_new ();
147
editor->name = label = gtk_label_new (_("(None)"));
148
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
149
gimp_label_set_attributes (GTK_LABEL (editor->name),
150
PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC,
152
gtk_box_pack_start (GTK_BOX (editor), label, FALSE, FALSE, 0);
153
gtk_widget_show (label);
112
gimp_editor_set_show_name (GIMP_EDITOR (editor), TRUE);
155
114
view = GIMP_HISTOGRAM_BOX (editor->box)->view;
168
127
gimp_enum_combo_box_set_stock_prefix (GIMP_ENUM_COMBO_BOX (menu),
170
gimp_enum_combo_box_set_visible (GIMP_ENUM_COMBO_BOX (editor->menu),
171
gimp_histogram_editor_item_visible,
129
gimp_int_combo_box_set_sensitivity (GIMP_INT_COMBO_BOX (editor->menu),
130
gimp_histogram_menu_sensitivity,
173
132
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (editor->menu),
175
134
gtk_box_pack_start (GTK_BOX (hbox), menu, FALSE, FALSE, 0);
184
143
gtk_box_pack_start (GTK_BOX (editor), editor->box, TRUE, TRUE, 0);
185
144
gtk_widget_show (GTK_WIDGET (editor->box));
187
g_signal_connect_swapped (view, "range_changed",
146
g_signal_connect_swapped (view, "range-changed",
188
147
G_CALLBACK (gimp_histogram_editor_info_update),
190
149
g_signal_connect_swapped (view, "notify::histogram-channel",
191
150
G_CALLBACK (gimp_histogram_editor_info_update),
153
g_signal_connect_swapped (view, "expose-event",
154
G_CALLBACK (gimp_histogram_view_expose),
194
157
table = gtk_table_new (3, 4, FALSE);
195
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
158
gtk_table_set_col_spacings (GTK_TABLE (table), 2);
159
gtk_table_set_col_spacing (GTK_TABLE (table), 1, 6);
196
160
gtk_box_pack_start (GTK_BOX (editor), table, FALSE, FALSE, 0);
197
161
gtk_widget_show (table);
202
166
gint y = (i % 3);
204
168
label = gtk_label_new (gettext (gimp_histogram_editor_labels[i]));
205
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
169
gimp_label_set_attributes (GTK_LABEL (label),
170
PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD,
171
PANGO_ATTR_SCALE, PANGO_SCALE_SMALL,
173
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
206
174
gtk_table_attach (GTK_TABLE (table), label, x, x + 1, y, y + 1,
207
GTK_FILL, GTK_FILL, 2, 2);
175
GTK_FILL | GTK_EXPAND, GTK_FILL, 2, 2);
208
176
gtk_widget_show (label);
210
editor->labels[i] = label = gtk_label_new (NULL);
211
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
179
label = g_object_new (GTK_TYPE_LABEL,
182
"width-chars", i > 2 ? 9 : 5,
184
gimp_label_set_attributes (GTK_LABEL (editor->labels[i]),
185
PANGO_ATTR_SCALE, PANGO_SCALE_SMALL,
212
187
gtk_table_attach (GTK_TABLE (table), label, x + 1, x + 2, y, y + 1,
213
188
GTK_FILL, GTK_FILL, 2, 2);
214
189
gtk_widget_show (label);
247
224
GimpHistogramView *view = GIMP_HISTOGRAM_BOX (editor->box)->view;
250
aux_info = gimp_session_info_aux_new_from_props (G_OBJECT (view),
227
aux_info = parent_docked_iface->get_aux_info (docked);
255
if (parent_docked_iface->get_aux_info)
256
return g_list_concat (parent_docked_iface->get_aux_info (docked),
229
return g_list_concat (aux_info,
230
gimp_session_info_aux_new_from_props (G_OBJECT (view),
263
237
gimp_histogram_editor_set_image (GimpImageEditor *image_editor,
266
240
GimpHistogramEditor *editor = GIMP_HISTOGRAM_EDITOR (image_editor);
267
241
GimpHistogramView *view = GIMP_HISTOGRAM_BOX (editor->box)->view;
269
if (image_editor->gimage)
243
if (image_editor->image)
271
245
if (editor->idle_id)
290
264
gimp_histogram_view_set_histogram (view, NULL);
293
GIMP_IMAGE_EDITOR_CLASS (parent_class)->set_image (image_editor, gimage);
267
GIMP_IMAGE_EDITOR_CLASS (parent_class)->set_image (image_editor, image);
298
gimp_histogram_new (GIMP_BASE_CONFIG (gimage->gimp->config));
271
editor->histogram = gimp_histogram_new ();
300
273
gimp_histogram_view_set_histogram (view, editor->histogram);
302
g_signal_connect_object (gimage, "mode_changed",
275
g_signal_connect_object (image, "mode-changed",
303
276
G_CALLBACK (gimp_histogram_editor_menu_update),
304
277
editor, G_CONNECT_SWAPPED);
305
g_signal_connect_object (gimage, "active_layer_changed",
278
g_signal_connect_object (image, "active-layer-changed",
306
279
G_CALLBACK (gimp_histogram_editor_layer_changed),
308
g_signal_connect_object (gimage, "mask_changed",
281
g_signal_connect_object (image, "mask-changed",
309
282
G_CALLBACK (gimp_histogram_editor_update),
310
283
editor, G_CONNECT_SWAPPED);
313
gimp_histogram_editor_layer_changed (gimage, editor);
286
gimp_histogram_editor_layer_changed (image, editor);
323
gimp_histogram_editor_layer_changed (GimpImage *gimage,
296
gimp_histogram_editor_layer_changed (GimpImage *image,
324
297
GimpHistogramEditor *editor)
328
299
if (editor->drawable)
330
301
g_signal_handlers_disconnect_by_func (editor->drawable,
302
gimp_histogram_editor_name_update,
304
g_signal_handlers_disconnect_by_func (editor->drawable,
331
305
gimp_histogram_editor_menu_update,
333
307
g_signal_handlers_disconnect_by_func (editor->drawable,
336
310
editor->drawable = NULL;
340
editor->drawable = (GimpDrawable *) gimp_image_get_active_layer (gimage);
314
editor->drawable = (GimpDrawable *) gimp_image_get_active_layer (image);
342
316
gimp_histogram_editor_menu_update (editor);
344
318
if (editor->drawable)
346
name = gimp_object_get_name (GIMP_OBJECT (editor->drawable));
348
g_signal_connect_object (editor->drawable, "invalidate_preview",
320
g_signal_connect_object (editor->drawable, "invalidate-preview",
349
321
G_CALLBACK (gimp_histogram_editor_update),
350
322
editor, G_CONNECT_SWAPPED);
351
g_signal_connect_object (editor->drawable, "alpha_changed",
323
g_signal_connect_object (editor->drawable, "alpha-changed",
352
324
G_CALLBACK (gimp_histogram_editor_menu_update),
353
325
editor, G_CONNECT_SWAPPED);
326
g_signal_connect_object (editor->drawable, "name-changed",
327
G_CALLBACK (gimp_histogram_editor_name_update),
328
editor, G_CONNECT_SWAPPED);
355
330
gimp_histogram_editor_update (editor);
332
else if (editor->histogram)
361
if (editor->histogram)
363
gimp_histogram_calculate (editor->histogram, NULL, NULL);
364
gtk_widget_queue_draw GTK_WIDGET (editor->box);
365
gimp_histogram_editor_info_update (editor);
334
editor->valid = FALSE;
335
gtk_widget_queue_draw (GTK_WIDGET (editor->box));
369
gtk_label_set_text (GTK_LABEL (editor->name), name);
338
gimp_histogram_editor_info_update (editor);
339
gimp_histogram_editor_name_update (editor);
425
gimp_histogram_editor_item_visible (GtkTreeModel *model,
396
gimp_histogram_menu_sensitivity (gint value,
429
GimpHistogramEditor *editor = GIMP_HISTOGRAM_EDITOR (data);
430
GimpHistogramChannel channel;
432
gtk_tree_model_get (model, iter,
433
GIMP_INT_STORE_VALUE, &channel,
436
return gimp_histogram_editor_channel_valid (editor, channel);
399
GimpHistogramEditor *editor = GIMP_HISTOGRAM_EDITOR (data);
400
GimpHistogramChannel channel = value;
402
if (editor->drawable)
403
return gimp_histogram_editor_channel_valid (editor, channel);
440
409
gimp_histogram_editor_menu_update (GimpHistogramEditor *editor)
442
411
GimpHistogramView *view = GIMP_HISTOGRAM_BOX (editor->box)->view;
445
model = gtk_combo_box_get_model (GTK_COMBO_BOX (editor->menu));
446
gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (model));
413
gtk_widget_queue_draw (editor->menu);
448
415
if (! gimp_histogram_editor_channel_valid (editor, view->channel))
467
445
count = gimp_histogram_get_count (hist, view->channel,
468
446
view->start, view->end);
470
g_snprintf (text, sizeof (text), "%3.1f",
448
g_snprintf (text, sizeof (text), "%.1f",
471
449
gimp_histogram_get_mean (hist, view->channel,
472
450
view->start, view->end));
473
451
gtk_label_set_text (GTK_LABEL (editor->labels[0]), text);
475
g_snprintf (text, sizeof (text), "%3.1f",
453
g_snprintf (text, sizeof (text), "%.1f",
476
454
gimp_histogram_get_std_dev (hist, view->channel,
477
455
view->start, view->end));
478
456
gtk_label_set_text (GTK_LABEL (editor->labels[1]), text);
480
g_snprintf (text, sizeof (text), "%3.1f",
458
g_snprintf (text, sizeof (text), "%.1f",
481
459
(gdouble) gimp_histogram_get_median (hist, view->channel,
484
462
gtk_label_set_text (GTK_LABEL (editor->labels[2]), text);
486
g_snprintf (text, sizeof (text), "%8d", (gint) pixels);
464
g_snprintf (text, sizeof (text), "%d", (gint) pixels);
487
465
gtk_label_set_text (GTK_LABEL (editor->labels[3]), text);
489
g_snprintf (text, sizeof (text), "%8d", (gint) count);
467
g_snprintf (text, sizeof (text), "%d", (gint) count);
490
468
gtk_label_set_text (GTK_LABEL (editor->labels[4]), text);
492
g_snprintf (text, sizeof (text), "%4.1f", (pixels > 0 ?
470
g_snprintf (text, sizeof (text), "%.1f", (pixels > 0 ?
493
471
(100.0 * count / pixels) :
495
473
gtk_label_set_text (GTK_LABEL (editor->labels[5]), text);