rev |
line source |
meillo@0
|
1 #include <gtk/gtk.h>
|
meillo@7
|
2 #include <gdk-pixbuf/gdk-pixbuf.h>
|
meillo@13
|
3 #include <gdk/gdkkeysyms.h>
|
meillo@2
|
4 #include "main.h"
|
meillo@0
|
5
|
meillo@7
|
6 int image_width;
|
meillo@7
|
7 int image_height;
|
meillo@10
|
8 float inc = 0.3;
|
meillo@13
|
9 float zoom = 1.0;
|
meillo@11
|
10
|
meillo@11
|
11
|
meillo@4
|
12 /*
|
meillo@11
|
13 void
|
meillo@11
|
14 update_spin_button_ratio(GtkWidget* spinbutton)
|
meillo@11
|
15 {
|
meillo@3
|
16 g_print("ratio change: %f\n", ratio);
|
meillo@3
|
17 on_ratio_w_spinbutton_value_changed(spinbutton, NULL);
|
meillo@3
|
18 }
|
meillo@2
|
19
|
meillo@4
|
20
|
meillo@11
|
21 void
|
meillo@11
|
22 on_ratio_none_activate(GtkMenuItem* menuitem, gpointer user_data)
|
meillo@11
|
23 {
|
meillo@4
|
24 ratio = 1;
|
meillo@3
|
25 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
|
meillo@2
|
26 }
|
meillo@2
|
27
|
meillo@2
|
28
|
meillo@11
|
29 void
|
meillo@11
|
30 on_ratio_square_activate(GtkMenuItem* menuitem, gpointer user_data)
|
meillo@11
|
31 {
|
meillo@4
|
32 ratio = 1;
|
meillo@3
|
33 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
|
meillo@2
|
34 }
|
meillo@2
|
35
|
meillo@2
|
36
|
meillo@11
|
37 void
|
meillo@11
|
38 on_ratio_4x3_activate(GtkMenuItem* menuitem, gpointer user_data)
|
meillo@11
|
39 {
|
meillo@4
|
40 ratio = 4.0/3.0;
|
meillo@3
|
41 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
|
meillo@2
|
42 }
|
meillo@2
|
43
|
meillo@2
|
44
|
meillo@11
|
45 void
|
meillo@11
|
46 on_ratio_3x2_activate(GtkMenuItem* menuitem, gpointer user_data)
|
meillo@11
|
47 {
|
meillo@4
|
48 ratio = 1.5;
|
meillo@3
|
49 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
|
meillo@2
|
50 }
|
meillo@2
|
51
|
meillo@2
|
52
|
meillo@11
|
53 void
|
meillo@11
|
54 on_ratio_custom_activate(GtkMenuItem* menuitem, gpointer user_data)
|
meillo@11
|
55 {
|
meillo@11
|
56 ratio = gtk_spin_button_get_value(lookup_widget(cropper_window, "ratio_w_spinbutton"))
|
meillo@11
|
57 / gtk_spin_button_get_value(lookup_widget(cropper_window, "ratio_h_spinbutton"));
|
meillo@3
|
58 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
|
meillo@3
|
59 }
|
meillo@4
|
60 */
|
meillo@3
|
61
|
meillo@3
|
62
|
meillo@3
|
63
|
meillo@3
|
64
|
meillo@3
|
65
|
meillo@4
|
66
|
meillo@4
|
67
|
meillo@4
|
68
|
meillo@4
|
69
|
meillo@4
|
70 /*
|
meillo@11
|
71 static void
|
meillo@11
|
72 ratio_optionmenu_changed_cb(GtkOptionMenu* optionmenu, gpointer unser_data)
|
meillo@11
|
73 {
|
meillo@11
|
74 int idx = gtk_option_menu_get_history(optionmenu);
|
meillo@4
|
75 int w = 1, h = 1;
|
meillo@4
|
76 gboolean use_ratio = TRUE;
|
meillo@4
|
77
|
meillo@4
|
78 switch (idx) {
|
meillo@4
|
79 case GTH_CROP_RATIO_NONE:
|
meillo@4
|
80 use_ratio = FALSE;
|
meillo@4
|
81 break;
|
meillo@4
|
82 case GTH_CROP_RATIO_SQUARE:
|
meillo@4
|
83 w = h = 1;
|
meillo@4
|
84 break;
|
meillo@4
|
85 case GTH_CROP_RATIO_IMAGE:
|
meillo@4
|
86 w = lookup_widget(cropper_window, "image_width");
|
meillo@4
|
87 h = lookup_widget(cropper_window, "image_height");
|
meillo@4
|
88 break;
|
meillo@4
|
89 case GTH_CROP_RATIO_DISPLAY:
|
meillo@4
|
90 w = lookup_widget(cropper_window, "display_width");
|
meillo@4
|
91 h = lookup_widget(cropper_window, "display_height");
|
meillo@4
|
92 break;
|
meillo@4
|
93 case GTH_CROP_RATIO_4_3:
|
meillo@4
|
94 w = 4;
|
meillo@4
|
95 h = 3;
|
meillo@4
|
96 break;
|
meillo@4
|
97 case GTH_CROP_RATIO_4_6:
|
meillo@4
|
98 w = 4;
|
meillo@4
|
99 h = 6;
|
meillo@4
|
100 break;
|
meillo@4
|
101 case GTH_CROP_RATIO_CUSTOM:
|
meillo@4
|
102 default:
|
meillo@11
|
103 w = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(
|
meillo@11
|
104 lookup_widget(cropper_window, "ratio_w_spinbutton")));
|
meillo@11
|
105 h = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(
|
meillo@11
|
106 lookup_widget(cropper_window, "ratio_h_spinbutton")));
|
meillo@4
|
107 break;
|
meillo@4
|
108 }
|
meillo@4
|
109
|
meillo@11
|
110 gtk_widget_set_sensitive(lookup_widget(cropper_window, "custom_ratio_box"),
|
meillo@11
|
111 idx == GTH_CROP_RATIO_CUSTOM);
|
meillo@11
|
112 set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_w_spinbutton"), w);
|
meillo@11
|
113 set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_h_spinbutton"), h);
|
meillo@4
|
114
|
meillo@11
|
115 gth_image_selector_set_ratio(GTH_IMAGE_SELECTOR(lookup_widget(cropper_window, "crop_image")),
|
meillo@11
|
116 use_ratio, (double) w / h);
|
meillo@4
|
117 }
|
meillo@4
|
118
|
meillo@4
|
119
|
meillo@11
|
120 static void
|
meillo@11
|
121 ratio_value_changed_cb(GtkSpinButton* spin, gpointer unser_data)
|
meillo@11
|
122 {
|
meillo@4
|
123 int w, h;
|
meillo@4
|
124
|
meillo@11
|
125 w = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_w_spinbutton"));
|
meillo@11
|
126 h = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_h_spinbutton"));
|
meillo@4
|
127
|
meillo@11
|
128 gth_image_selector_set_ratio(GTH_IMAGE_SELECTOR(
|
meillo@11
|
129 lookup_widget(cropper_window, "crop_image")), TRUE, (double) w / h);
|
meillo@4
|
130 }
|
meillo@4
|
131
|
meillo@4
|
132
|
meillo@11
|
133 static void
|
meillo@11
|
134 ratio_swap_button_cb(GtkButton* button, gpointer unser_data)
|
meillo@11
|
135 {
|
meillo@4
|
136 int w, h;
|
meillo@4
|
137
|
meillo@4
|
138 w = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_w_spinbutton"));
|
meillo@4
|
139 h = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_h_spinbutton"));
|
meillo@4
|
140
|
meillo@4
|
141 set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_w_spinbutton"), h);
|
meillo@4
|
142 set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_h_spinbutton"), w);
|
meillo@4
|
143
|
meillo@11
|
144 gth_image_selector_set_ratio(GTH_IMAGE_SELECTOR(lookup_widget(cropper_window,
|
meillo@11
|
145 "crop_image")), TRUE, (double) h / w);
|
meillo@4
|
146 }
|
meillo@4
|
147
|
meillo@4
|
148
|
meillo@4
|
149
|
meillo@4
|
150
|
meillo@4
|
151
|
meillo@4
|
152
|
meillo@4
|
153
|
meillo@4
|
154
|
meillo@11
|
155 void
|
meillo@11
|
156 on_ratio_w_spinbutton_value_changed(GtkSpinButton* spinbutton, gpointer user_data)
|
meillo@11
|
157 {
|
meillo@3
|
158 g_print("spinbutton W - ratio: %f\n", ratio);
|
meillo@11
|
159 gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_h_spinbutton"),
|
meillo@11
|
160 gtk_spin_button_get_value(spinbutton) / ratio);
|
meillo@3
|
161 }
|
meillo@3
|
162
|
meillo@3
|
163
|
meillo@11
|
164 void
|
meillo@11
|
165 on_ratio_w_spinbutton_change_value(GtkSpinButton* spinbutton, GtkScrollType scroll, gpointer user_data)
|
meillo@11
|
166 {
|
meillo@3
|
167 }
|
meillo@3
|
168
|
meillo@3
|
169
|
meillo@11
|
170 void
|
meillo@11
|
171 on_ratio_h_spinbutton_change_value(GtkSpinButton* spinbutton, GtkScrollType scroll, gpointer user_data)
|
meillo@11
|
172 {
|
meillo@3
|
173 }
|
meillo@3
|
174
|
meillo@3
|
175
|
meillo@11
|
176 void
|
meillo@11
|
177 on_ratio_h_spinbutton_value_changed(GtkSpinButton* spinbutton, gpointer user_data)
|
meillo@11
|
178 {
|
meillo@3
|
179 g_print("spinbutton H - ratio: %f\n", ratio);
|
meillo@11
|
180 gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_w_spinbutton"),
|
meillo@11
|
181 gtk_spin_button_get_value(spinbutton) * ratio);
|
meillo@0
|
182
|
meillo@0
|
183 }
|
meillo@0
|
184
|
meillo@0
|
185
|
meillo@11
|
186 void
|
meillo@11
|
187 on_ratio_swap_button_clicked(GtkButton* button, gpointer user_data)
|
meillo@11
|
188 {
|
meillo@3
|
189
|
meillo@3
|
190 ratio = 1.0 / ratio;
|
meillo@11
|
191 gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_w_spinbutton"),
|
meillo@11
|
192 gtk_spin_button_get_value(lookup_widget(cropper_window,
|
meillo@11
|
193 "ratio_h_spinbutton")));
|
meillo@3
|
194 gtk_spin_button_update(lookup_widget(cropper_window, "ratio_w_spinbutton"));
|
meillo@0
|
195
|
meillo@2
|
196 }
|
meillo@4
|
197 */
|
meillo@2
|
198
|
meillo@2
|
199
|
meillo@13
|
200 void
|
meillo@13
|
201 update_title(char* zoom)
|
meillo@13
|
202 {
|
meillo@13
|
203 char title[128];
|
meillo@13
|
204 snprintf(title, 128, "cropper (%s) %dx%d+%d+%d", zoom, w, h, x, y);
|
meillo@13
|
205 gtk_window_set_title(GTK_WINDOW(cropper_window), title);
|
meillo@13
|
206 }
|
meillo@13
|
207
|
meillo@2
|
208
|
meillo@7
|
209 /* zoom */
|
meillo@11
|
210 void
|
meillo@11
|
211 set_zoom()
|
meillo@11
|
212 {
|
meillo@8
|
213 static GdkPixbuf* pixbuf_new;
|
meillo@8
|
214 g_object_unref(pixbuf_new);
|
meillo@8
|
215
|
meillo@13
|
216 pixbuf_new = gdk_pixbuf_scale_simple(image_buffer, image_width*zoom, image_height*zoom,
|
meillo@13
|
217 GDK_INTERP_BILINEAR);
|
meillo@8
|
218 gtk_image_set_from_pixbuf((GtkImage*) lookup_widget(cropper_window, "image_area"), pixbuf_new);
|
meillo@8
|
219 }
|
meillo@8
|
220
|
meillo@11
|
221 void
|
meillo@11
|
222 on_zoom_in_button_clicked(GtkObject* object, gpointer user_data)
|
meillo@11
|
223 {
|
meillo@13
|
224 zoom *= 1 + inc;
|
meillo@8
|
225 set_zoom();
|
meillo@7
|
226 }
|
meillo@7
|
227
|
meillo@11
|
228 void
|
meillo@11
|
229 on_zoom_out_button_clicked(GtkObject* object, gpointer user_data)
|
meillo@11
|
230 {
|
meillo@13
|
231 zoom *= 1 - inc;
|
meillo@8
|
232 set_zoom();
|
meillo@7
|
233 }
|
meillo@7
|
234
|
meillo@11
|
235 void
|
meillo@11
|
236 on_zoom_100_button_clicked(GtkObject* object, gpointer user_data)
|
meillo@11
|
237 {
|
meillo@13
|
238 zoom = 1.0;
|
meillo@8
|
239 set_zoom();
|
meillo@7
|
240 }
|
meillo@7
|
241
|
meillo@11
|
242 void
|
meillo@11
|
243 on_zoom_fit_button_clicked(GtkObject* object, gpointer user_data)
|
meillo@11
|
244 {
|
meillo@8
|
245 int w, h;
|
meillo@13
|
246 float zw, zh;
|
meillo@8
|
247 GtkWidget* image_a;
|
meillo@8
|
248
|
meillo@8
|
249 image_a = (GtkWidget*) lookup_widget(cropper_window, "image_area");
|
meillo@11
|
250 gdk_drawable_get_size(image_a->window, &w, &h);
|
meillo@8
|
251
|
meillo@13
|
252 zw = w*1.0 / image_width;
|
meillo@13
|
253 zh = h*1.0 / image_height;
|
meillo@13
|
254
|
meillo@13
|
255 zoom = (zw < zh) ? zw : zh;
|
meillo@8
|
256 set_zoom();
|
meillo@7
|
257 }
|
meillo@7
|
258
|
meillo@7
|
259
|
meillo@7
|
260
|
meillo@7
|
261
|
meillo@7
|
262
|
meillo@7
|
263
|
meillo@7
|
264
|
meillo@11
|
265 void
|
meillo@14
|
266 crop(void)
|
meillo@11
|
267 {
|
meillo@4
|
268 char crop_call[256];
|
meillo@2
|
269
|
meillo@4
|
270 sprintf(crop_call, "echo \"convert -crop %ix%i+%i+%i %s cropped_%s\"",
|
meillo@11
|
271 gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window,
|
meillo@11
|
272 "crop_width_spinbutton")),
|
meillo@11
|
273 gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window,
|
meillo@11
|
274 "crop_height_spinbutton")),
|
meillo@11
|
275 gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window,
|
meillo@11
|
276 "crop_x_spinbutton")),
|
meillo@11
|
277 gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window,
|
meillo@11
|
278 "crop_y_spinbutton")),
|
meillo@4
|
279 image_filename,
|
meillo@4
|
280 image_filename
|
meillo@4
|
281 );
|
meillo@4
|
282 system(crop_call);
|
meillo@4
|
283 gtk_main_quit();
|
meillo@4
|
284 }
|
meillo@2
|
285
|
meillo@11
|
286
|
meillo@11
|
287 void
|
meillo@11
|
288 on_cropper_window_create(GtkObject* object, gpointer user_data)
|
meillo@11
|
289 {
|
meillo@7
|
290 image_width = gdk_pixbuf_get_width(image_buffer);
|
meillo@7
|
291 image_height = gdk_pixbuf_get_height(image_buffer);
|
meillo@10
|
292
|
meillo@10
|
293 /*
|
meillo@11
|
294 image_buffer = gdk_pixbuf_new_from_file(image_filename, NULL);
|
meillo@11
|
295 image_area = gtk_image_new_from_pixbuf(image_buffer);
|
meillo@10
|
296
|
meillo@10
|
297 int w, h;
|
meillo@10
|
298 GtkWidget* image_a;
|
meillo@10
|
299
|
meillo@10
|
300 image_a = (GtkWidget*) lookup_widget(cropper_window, "image_area");
|
meillo@11
|
301 gdk_drawable_get_size(image_a->window, &w, &h);
|
meillo@10
|
302
|
meillo@10
|
303 image_width = w - 200;
|
meillo@10
|
304 image_height = h - 150;
|
meillo@10
|
305 set_zoom();
|
meillo@10
|
306 */
|
meillo@7
|
307 }
|
meillo@0
|
308
|
meillo@11
|
309 void
|
meillo@11
|
310 on_cropper_window_destroy(GtkObject* object, gpointer user_data)
|
meillo@11
|
311 {
|
meillo@0
|
312 gtk_main_quit();
|
meillo@0
|
313 }
|
meillo@0
|
314
|
meillo@13
|
315
|
meillo@13
|
316
|
meillo@13
|
317
|
meillo@13
|
318 gboolean
|
meillo@13
|
319 on_key_press(GtkWidget* window, GdkEventKey* pKey, gpointer userdata)
|
meillo@13
|
320 {
|
meillo@13
|
321 if (pKey->type != GDK_KEY_PRESS) {
|
meillo@13
|
322 return FALSE;
|
meillo@13
|
323 }
|
meillo@13
|
324 switch (pKey->keyval) {
|
meillo@14
|
325 case GDK_q:
|
meillo@14
|
326 gtk_main_quit();
|
meillo@14
|
327 break;
|
meillo@14
|
328 case GDK_Return:
|
meillo@14
|
329 crop();
|
meillo@14
|
330 break;
|
meillo@13
|
331 case GDK_plus:
|
meillo@13
|
332 on_zoom_in_button_clicked(NULL, userdata);
|
meillo@13
|
333 break;
|
meillo@13
|
334 case GDK_minus:
|
meillo@13
|
335 on_zoom_out_button_clicked(NULL, userdata);
|
meillo@13
|
336 break;
|
meillo@13
|
337 case GDK_0:
|
meillo@13
|
338 on_zoom_100_button_clicked(NULL, userdata);
|
meillo@13
|
339 break;
|
meillo@13
|
340 case GDK_f:
|
meillo@13
|
341 on_zoom_fit_button_clicked(NULL, userdata);
|
meillo@13
|
342 break;
|
meillo@13
|
343 }
|
meillo@13
|
344 return TRUE;
|
meillo@13
|
345 }
|
meillo@13
|
346
|
meillo@13
|
347
|