comparison src/bar_histogram.c @ 1319:358685fb9dc9

Add a contextual menu on bar pane histogram allowing to change channels and mode. More work needed.
author zas_
date Tue, 24 Feb 2009 21:08:16 +0000
parents c1d108ab3388
children 50ab4016ae0b
comparison
equal deleted inserted replaced
1318:fb76c291b00f 1319:358685fb9dc9
15 #include "bar_comment.h" 15 #include "bar_comment.h"
16 16
17 #include "bar.h" 17 #include "bar.h"
18 #include "metadata.h" 18 #include "metadata.h"
19 #include "filedata.h" 19 #include "filedata.h"
20 #include "menu.h"
20 #include "ui_menu.h" 21 #include "ui_menu.h"
21 #include "ui_misc.h" 22 #include "ui_misc.h"
22 #include "histogram.h" 23 #include "histogram.h"
23 #include "rcfile.h" 24 #include "rcfile.h"
24 25
145 if (phd->pixbuf) g_object_unref(phd->pixbuf); 146 if (phd->pixbuf) g_object_unref(phd->pixbuf);
146 147
147 g_free(phd); 148 g_free(phd);
148 } 149 }
149 150
151 static void bar_pane_histogram_popup_channels_cb(GtkWidget *widget, gpointer data)
152 {
153 PaneHistogramData *phd;
154 gint channel;
155
156 phd = submenu_item_get_data(widget);
157
158 if (!phd) return;
159
160 channel = GPOINTER_TO_INT(data);
161 histogram_set_channel(phd->histogram, channel);
162 bar_pane_histogram_update(phd);
163 }
164
165 static void bar_pane_histogram_popup_logmode_cb(GtkWidget *widget, gpointer data)
166 {
167 PaneHistogramData *phd;
168 gint logmode;
169
170 phd = submenu_item_get_data(widget);
171
172 if (!phd) return;
173
174 logmode = GPOINTER_TO_INT(data);
175 histogram_set_mode(phd->histogram, logmode);
176 bar_pane_histogram_update(phd);
177 }
178
179 static GtkWidget *bar_pane_histogram_add_radio(GtkWidget *menu, GtkWidget *parent,
180 const gchar *label,
181 GCallback func, gint value,
182 gboolean show_current, gint show_value)
183 {
184 GtkWidget *item;
185
186 if (show_current)
187 {
188 item = menu_item_add_radio(menu, parent,
189 label, (value == show_value),
190 func, GINT_TO_POINTER((gint)value));
191 }
192 else
193 {
194 item = menu_item_add(menu, label,
195 func, GINT_TO_POINTER((gint)value));
196 }
197
198 return item;
199 }
200
201 GtkWidget *bar_pane_histogram_add_channels(GtkWidget *menu, GCallback func, gpointer data,
202 gboolean show_current, gint value)
203 {
204 GtkWidget *submenu;
205 GtkWidget *parent;
206
207 submenu = gtk_menu_new();
208 g_object_set_data(G_OBJECT(submenu), "submenu_data", data);
209
210 parent = bar_pane_histogram_add_radio(submenu, NULL, _("_Red"), func, HCHAN_R, show_current, value);
211 bar_pane_histogram_add_radio(submenu, parent, _("_Green"), func, HCHAN_G, show_current, value);
212 bar_pane_histogram_add_radio(submenu, parent, _("_Blue"),func, HCHAN_B, show_current, value);
213 bar_pane_histogram_add_radio(submenu, parent, _("_RGB"),func, HCHAN_RGB, show_current, value);
214 bar_pane_histogram_add_radio(submenu, parent, _("_Value"),func, HCHAN_MAX, show_current, value);
215
216 if (menu)
217 {
218 GtkWidget *item;
219
220 item = menu_item_add(menu, _("Channels"), NULL, NULL);
221 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
222 return item;
223 }
224
225 return submenu;
226 }
227 GtkWidget *bar_pane_histogram_add_logmode(GtkWidget *menu, GCallback func, gpointer data,
228 gboolean show_current, gint value)
229 {
230 GtkWidget *submenu;
231 GtkWidget *parent;
232
233 submenu = gtk_menu_new();
234 g_object_set_data(G_OBJECT(submenu), "submenu_data", data);
235
236 parent = bar_pane_histogram_add_radio(submenu, NULL, _("_Linear"), func, 0, show_current, value);
237 bar_pane_histogram_add_radio(submenu, parent, _("Lo_garithmical"), func, 1, show_current, value);
238
239 if (menu)
240 {
241 GtkWidget *item;
242
243 item = menu_item_add(menu, _("Mode"), NULL, NULL);
244 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
245 return item;
246 }
247
248 return submenu;
249 }
250
251
252 static GtkWidget *bar_pane_histogram_menu(PaneHistogramData *phd)
253 {
254 GtkWidget *menu;
255 static gboolean show_current = FALSE; /* FIXME: TRUE -> buggy behavior */
256
257 menu = popup_menu_short_lived();
258 bar_pane_histogram_add_channels(menu, G_CALLBACK(bar_pane_histogram_popup_channels_cb), phd,
259 show_current, histogram_get_channel(phd->histogram));
260 bar_pane_histogram_add_logmode(menu, G_CALLBACK(bar_pane_histogram_popup_logmode_cb), phd,
261 show_current, histogram_get_mode(phd->histogram));
262
263 return menu;
264 }
265
266 static gboolean bar_pane_histogram_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
267 {
268 PaneHistogramData *phd = data;
269
270 if (bevent->button == MOUSE_BUTTON_RIGHT)
271 {
272 GtkWidget *menu;
273
274 menu = bar_pane_histogram_menu(phd);
275 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, bevent->button, bevent->time);
276 return TRUE;
277 }
278
279 return FALSE;
280 }
281
150 282
151 GtkWidget *bar_pane_histogram_new(const gchar *title, gint height, gint expanded) 283 GtkWidget *bar_pane_histogram_new(const gchar *title, gint height, gint expanded)
152 { 284 {
153 PaneHistogramData *phd; 285 PaneHistogramData *phd;
154 286
158 phd->pane.pane_write_config = bar_pane_histogram_write_config; 290 phd->pane.pane_write_config = bar_pane_histogram_write_config;
159 phd->pane.title = g_strdup(title); 291 phd->pane.title = g_strdup(title);
160 phd->pane.expanded = expanded; 292 phd->pane.expanded = expanded;
161 293
162 phd->histogram = histogram_new(); 294 phd->histogram = histogram_new();
163 295
296 histogram_set_channel(phd->histogram, HCHAN_RGB);
297 histogram_set_mode(phd->histogram, 0);
298
164 phd->widget = gtk_vbox_new(FALSE, PREF_PAD_GAP); 299 phd->widget = gtk_vbox_new(FALSE, PREF_PAD_GAP);
165 300
166 g_object_set_data(G_OBJECT(phd->widget), "pane_data", phd); 301 g_object_set_data(G_OBJECT(phd->widget), "pane_data", phd);
167 g_signal_connect(G_OBJECT(phd->widget), "destroy", 302 g_signal_connect(G_OBJECT(phd->widget), "destroy",
168 G_CALLBACK(bar_pane_histogram_destroy), phd); 303 G_CALLBACK(bar_pane_histogram_destroy), phd);
177 g_signal_connect(G_OBJECT(phd->drawing_area), "expose_event", 312 g_signal_connect(G_OBJECT(phd->drawing_area), "expose_event",
178 G_CALLBACK(bar_pane_histogram_expose_event_cb), phd); 313 G_CALLBACK(bar_pane_histogram_expose_event_cb), phd);
179 314
180 gtk_box_pack_start(GTK_BOX(phd->widget), phd->drawing_area, TRUE, TRUE, 0); 315 gtk_box_pack_start(GTK_BOX(phd->widget), phd->drawing_area, TRUE, TRUE, 0);
181 gtk_widget_show(phd->drawing_area); 316 gtk_widget_show(phd->drawing_area);
182 317 gtk_widget_add_events(phd->drawing_area, GDK_BUTTON_PRESS_MASK);
318
319 g_signal_connect(G_OBJECT(phd->drawing_area), "button_press_event", G_CALLBACK(bar_pane_histogram_press_cb), phd);
183 320
184 gtk_widget_show(phd->widget); 321 gtk_widget_show(phd->widget);
185 322
186 file_data_register_notify_func(bar_pane_histogram_notify_cb, phd, NOTIFY_PRIORITY_LOW); 323 file_data_register_notify_func(bar_pane_histogram_notify_cb, phd, NOTIFY_PRIORITY_LOW);
187 324