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