annotate src/bar_histogram.c @ 1309:55ea4962887a

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