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