1298
|
1 /*
|
|
2 * Geeqie
|
|
3 * (C) 2004 John Ellis
|
|
4 * Copyright (C) 2008 - 2009 The Geeqie Team
|
|
5 *
|
|
6 * Author: Vladimir Nadvornik
|
|
7 *
|
|
8 * This software is released under the GNU General Public License (GNU GPL).
|
|
9 * Please read the included file COPYING for more information.
|
|
10 * This software comes with no warranty of any kind, use at your own risk!
|
|
11 */
|
|
12
|
|
13
|
|
14 #include "main.h"
|
|
15 #include "bar_comment.h"
|
|
16
|
|
17 #include "bar.h"
|
|
18 #include "metadata.h"
|
|
19 #include "filedata.h"
|
|
20 #include "ui_menu.h"
|
|
21 #include "ui_misc.h"
|
|
22 #include "histogram.h"
|
1309
|
23 #include "rcfile.h"
|
1298
|
24
|
|
25 /*
|
|
26 *-------------------------------------------------------------------
|
|
27 * keyword / comment utils
|
|
28 *-------------------------------------------------------------------
|
|
29 */
|
|
30
|
|
31
|
|
32
|
|
33 typedef struct _PaneHistogramData PaneHistogramData;
|
|
34 struct _PaneHistogramData
|
|
35 {
|
|
36 PaneData pane;
|
|
37 GtkWidget *widget;
|
|
38 GtkWidget *drawing_area;
|
|
39 Histogram *histogram;
|
|
40 gint histogram_width;
|
|
41 gint histogram_height;
|
|
42 GdkPixbuf *pixbuf;
|
|
43 FileData *fd;
|
|
44 };
|
|
45
|
|
46
|
|
47 static void bar_pane_histogram_update(PaneHistogramData *phd)
|
|
48 {
|
|
49 const HistMap *histmap;
|
|
50 if (phd->pixbuf) g_object_unref(phd->pixbuf);
|
|
51 phd->pixbuf = NULL;
|
|
52
|
|
53 if (!phd->histogram_width || !phd->histogram_height || !phd->fd) return;
|
|
54
|
|
55 gtk_widget_queue_draw_area(GTK_WIDGET(phd->drawing_area), 0, 0, phd->histogram_width, phd->histogram_height);
|
|
56
|
|
57 histmap = histmap_get(phd->fd);
|
|
58
|
|
59 if (!histmap) return;
|
|
60
|
|
61 phd->pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, phd->histogram_width, phd->histogram_height);
|
|
62 gdk_pixbuf_fill(phd->pixbuf, 0xffffffff);
|
|
63 histogram_draw(phd->histogram, histmap, phd->pixbuf, 0, 0, phd->histogram_width, phd->histogram_height);
|
|
64 }
|
|
65
|
|
66
|
|
67 static void bar_pane_histogram_set_fd(GtkWidget *pane, FileData *fd)
|
|
68 {
|
|
69 PaneHistogramData *phd;
|
|
70
|
|
71 phd = g_object_get_data(G_OBJECT(pane), "pane_data");
|
|
72 if (!phd) return;
|
|
73
|
|
74 file_data_unref(phd->fd);
|
|
75 phd->fd = file_data_ref(fd);
|
|
76
|
|
77 bar_pane_histogram_update(phd);
|
|
78 }
|
|
79
|
1309
|
80 static void bar_pane_histogram_write_config(GtkWidget *pane, GString *outstr, gint indent)
|
|
81 {
|
|
82 PaneHistogramData *phd;
|
|
83
|
|
84 phd = g_object_get_data(G_OBJECT(pane), "pane_data");
|
|
85 if (!phd) return;
|
|
86
|
|
87 write_indent(outstr, indent);
|
|
88 g_string_append_printf(outstr, "<pane_histogram\n");
|
|
89 indent++;
|
|
90 WRITE_CHAR(*phd, pane.title);
|
|
91 WRITE_BOOL(*phd, pane.expanded);
|
|
92 indent--;
|
|
93 write_indent(outstr, indent);
|
|
94 g_string_append_printf(outstr, "/>\n");
|
|
95 }
|
|
96
|
|
97
|
1298
|
98 static void bar_pane_histogram_notify_cb(FileData *fd, NotifyType type, gpointer data)
|
|
99 {
|
|
100 PaneHistogramData *phd = data;
|
|
101 if (fd == phd->fd) bar_pane_histogram_update(phd);
|
|
102 }
|
|
103
|
|
104 static gboolean bar_pane_histogram_expose_event_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data)
|
|
105 {
|
|
106 PaneHistogramData *phd = data;
|
|
107 if (!phd || !phd->pixbuf) return TRUE;
|
|
108
|
|
109 gdk_draw_pixbuf(widget->window,
|
|
110 widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
|
|
111 phd->pixbuf,
|
|
112 0, 0,
|
|
113 0, 0,
|
|
114 -1, -1,
|
|
115 GDK_RGB_DITHER_NORMAL, 0, 0);
|
|
116 return TRUE;
|
|
117 }
|
|
118
|
|
119 static void bar_pane_histogram_size_cb(GtkWidget *widget, GtkAllocation *allocation, gpointer data)
|
|
120 {
|
|
121 PaneHistogramData *phd = data;
|
|
122
|
|
123 phd->histogram_width = allocation->width;
|
|
124 phd->histogram_height = allocation->height;
|
|
125 bar_pane_histogram_update(phd);
|
|
126 }
|
|
127
|
|
128 static void bar_pane_histogram_close(GtkWidget *pane)
|
|
129 {
|
|
130 PaneHistogramData *phd;
|
|
131
|
|
132 phd = g_object_get_data(G_OBJECT(pane), "pane_data");
|
|
133 if (!phd) return;
|
|
134
|
|
135 gtk_widget_destroy(phd->widget);
|
|
136 }
|
|
137
|
|
138 static void bar_pane_histogram_destroy(GtkWidget *widget, gpointer data)
|
|
139 {
|
|
140 PaneHistogramData *phd = data;
|
|
141
|
|
142 file_data_unregister_notify_func(bar_pane_histogram_notify_cb, phd);
|
|
143
|
|
144 file_data_unref(phd->fd);
|
|
145 g_free(phd->pane.title);
|
|
146 histogram_free(phd->histogram);
|
|
147 if (phd->pixbuf) g_object_unref(phd->pixbuf);
|
|
148
|
|
149 g_free(phd);
|
|
150 }
|
|
151
|
|
152
|
1309
|
153 GtkWidget *bar_pane_histogram_new(const gchar *title, gint height, gint expanded)
|
1298
|
154 {
|
|
155 PaneHistogramData *phd;
|
|
156
|
|
157 phd = g_new0(PaneHistogramData, 1);
|
|
158
|
|
159 phd->pane.pane_set_fd = bar_pane_histogram_set_fd;
|
1309
|
160 phd->pane.pane_write_config = bar_pane_histogram_write_config;
|
1298
|
161 phd->pane.title = g_strdup(title);
|
1309
|
162 phd->pane.expanded = expanded;
|
1298
|
163
|
|
164 phd->histogram = histogram_new();
|
|
165
|
|
166 phd->widget = gtk_vbox_new(FALSE, PREF_PAD_GAP);
|
|
167
|
|
168 g_object_set_data(G_OBJECT(phd->widget), "pane_data", phd);
|
|
169 g_signal_connect(G_OBJECT(phd->widget), "destroy",
|
|
170 G_CALLBACK(bar_pane_histogram_destroy), phd);
|
|
171
|
|
172
|
|
173 gtk_widget_set_size_request(GTK_WIDGET(phd->widget), -1, height);
|
|
174
|
|
175 phd->drawing_area = gtk_drawing_area_new();
|
|
176 g_signal_connect_after(G_OBJECT(phd->drawing_area), "size_allocate",
|
|
177 G_CALLBACK(bar_pane_histogram_size_cb), phd);
|
|
178
|
|
179 g_signal_connect(G_OBJECT(phd->drawing_area), "expose_event",
|
|
180 G_CALLBACK(bar_pane_histogram_expose_event_cb), phd);
|
|
181
|
|
182 gtk_box_pack_start(GTK_BOX(phd->widget), phd->drawing_area, TRUE, TRUE, 0);
|
|
183 gtk_widget_show(phd->drawing_area);
|
|
184
|
|
185
|
|
186 gtk_widget_show(phd->widget);
|
|
187
|
|
188 file_data_register_notify_func(bar_pane_histogram_notify_cb, phd, NOTIFY_PRIORITY_LOW);
|
|
189
|
|
190 return phd->widget;
|
|
191 }
|
|
192
|
1309
|
193 GtkWidget *bar_pane_histogram_new_from_config(const gchar **attribute_names, const gchar **attribute_values)
|
|
194 {
|
|
195 gchar *title = g_strdup(_("NoName"));
|
|
196 gboolean expanded = TRUE;
|
|
197 gint height = 80;
|
|
198
|
|
199 while (*attribute_names)
|
|
200 {
|
|
201 const gchar *option = *attribute_names++;
|
|
202 const gchar *value = *attribute_values++;
|
|
203
|
|
204 READ_CHAR_FULL("pane.title", title);
|
|
205 READ_BOOL_FULL("pane.expanded", expanded);
|
|
206
|
|
207
|
|
208 DEBUG_1("unknown attribute %s = %s", option, value);
|
|
209 }
|
|
210
|
|
211 return bar_pane_histogram_new(title, height, expanded);
|
|
212 }
|
|
213
|
|
214
|
1298
|
215 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
|