cropper

view callbacks.c @ 12:75a30c850ea0

more cosmetic changes
author meillo@marmaro.de
date Thu, 04 Mar 2010 14:23:30 +0100
parents 5e282003f0c1
children 13bc21684b8a
line source
1 #include <gtk/gtk.h>
2 #include <gdk-pixbuf/gdk-pixbuf.h>
3 #include "main.h"
4 #include "callbacks.h"
5 #include "support.h"
7 int image_width;
8 int image_height;
9 float inc = 0.3;
12 /*
13 void
14 update_spin_button_ratio(GtkWidget* spinbutton)
15 {
16 g_print("ratio change: %f\n", ratio);
17 on_ratio_w_spinbutton_value_changed(spinbutton, NULL);
18 }
21 void
22 on_ratio_none_activate(GtkMenuItem* menuitem, gpointer user_data)
23 {
24 ratio = 1;
25 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
26 }
29 void
30 on_ratio_square_activate(GtkMenuItem* menuitem, gpointer user_data)
31 {
32 ratio = 1;
33 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
34 }
37 void
38 on_ratio_4x3_activate(GtkMenuItem* menuitem, gpointer user_data)
39 {
40 ratio = 4.0/3.0;
41 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
42 }
45 void
46 on_ratio_3x2_activate(GtkMenuItem* menuitem, gpointer user_data)
47 {
48 ratio = 1.5;
49 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
50 }
53 void
54 on_ratio_custom_activate(GtkMenuItem* menuitem, gpointer user_data)
55 {
56 ratio = gtk_spin_button_get_value(lookup_widget(cropper_window, "ratio_w_spinbutton"))
57 / gtk_spin_button_get_value(lookup_widget(cropper_window, "ratio_h_spinbutton"));
58 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
59 }
60 */
70 /*
71 static void
72 ratio_optionmenu_changed_cb(GtkOptionMenu* optionmenu, gpointer unser_data)
73 {
74 int idx = gtk_option_menu_get_history(optionmenu);
75 int w = 1, h = 1;
76 gboolean use_ratio = TRUE;
78 switch (idx) {
79 case GTH_CROP_RATIO_NONE:
80 use_ratio = FALSE;
81 break;
82 case GTH_CROP_RATIO_SQUARE:
83 w = h = 1;
84 break;
85 case GTH_CROP_RATIO_IMAGE:
86 w = lookup_widget(cropper_window, "image_width");
87 h = lookup_widget(cropper_window, "image_height");
88 break;
89 case GTH_CROP_RATIO_DISPLAY:
90 w = lookup_widget(cropper_window, "display_width");
91 h = lookup_widget(cropper_window, "display_height");
92 break;
93 case GTH_CROP_RATIO_4_3:
94 w = 4;
95 h = 3;
96 break;
97 case GTH_CROP_RATIO_4_6:
98 w = 4;
99 h = 6;
100 break;
101 case GTH_CROP_RATIO_CUSTOM:
102 default:
103 w = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(
104 lookup_widget(cropper_window, "ratio_w_spinbutton")));
105 h = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(
106 lookup_widget(cropper_window, "ratio_h_spinbutton")));
107 break;
108 }
110 gtk_widget_set_sensitive(lookup_widget(cropper_window, "custom_ratio_box"),
111 idx == GTH_CROP_RATIO_CUSTOM);
112 set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_w_spinbutton"), w);
113 set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_h_spinbutton"), h);
115 gth_image_selector_set_ratio(GTH_IMAGE_SELECTOR(lookup_widget(cropper_window, "crop_image")),
116 use_ratio, (double) w / h);
117 }
120 static void
121 ratio_value_changed_cb(GtkSpinButton* spin, gpointer unser_data)
122 {
123 int w, h;
125 w = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_w_spinbutton"));
126 h = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_h_spinbutton"));
128 gth_image_selector_set_ratio(GTH_IMAGE_SELECTOR(
129 lookup_widget(cropper_window, "crop_image")), TRUE, (double) w / h);
130 }
133 static void
134 ratio_swap_button_cb(GtkButton* button, gpointer unser_data)
135 {
136 int w, h;
138 w = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_w_spinbutton"));
139 h = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_h_spinbutton"));
141 set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_w_spinbutton"), h);
142 set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_h_spinbutton"), w);
144 gth_image_selector_set_ratio(GTH_IMAGE_SELECTOR(lookup_widget(cropper_window,
145 "crop_image")), TRUE, (double) h / w);
146 }
148 */
157 /*
158 void
159 on_ratio_w_spinbutton_value_changed(GtkSpinButton* spinbutton, gpointer user_data)
160 {
161 g_print("spinbutton W - ratio: %f\n", ratio);
162 gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_h_spinbutton"),
163 gtk_spin_button_get_value(spinbutton) / ratio);
164 }
167 void
168 on_ratio_w_spinbutton_change_value(GtkSpinButton* spinbutton, GtkScrollType scroll, gpointer user_data)
169 {
170 }
173 void
174 on_ratio_h_spinbutton_change_value(GtkSpinButton* spinbutton, GtkScrollType scroll, gpointer user_data)
175 {
176 }
179 void
180 on_ratio_h_spinbutton_value_changed(GtkSpinButton* spinbutton, gpointer user_data)
181 {
182 g_print("spinbutton H - ratio: %f\n", ratio);
183 gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_w_spinbutton"),
184 gtk_spin_button_get_value(spinbutton) * ratio);
186 }
189 void
190 on_ratio_swap_button_clicked(GtkButton* button, gpointer user_data)
191 {
193 ratio = 1.0 / ratio;
194 gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_w_spinbutton"),
195 gtk_spin_button_get_value(lookup_widget(cropper_window,
196 "ratio_h_spinbutton")));
197 gtk_spin_button_update(lookup_widget(cropper_window, "ratio_w_spinbutton"));
199 }
200 */
204 /* zoom */
205 void
206 set_zoom()
207 {
208 static GdkPixbuf* pixbuf_new;
209 g_object_unref(pixbuf_new);
211 pixbuf_new = gdk_pixbuf_scale_simple(image_buffer, image_width, image_height, GDK_INTERP_BILINEAR);
212 gtk_image_set_from_pixbuf((GtkImage*) lookup_widget(cropper_window, "image_area"), pixbuf_new);
213 }
215 void
216 on_zoom_in_button_clicked(GtkObject* object, gpointer user_data)
217 {
218 image_width *= 1 + inc;
219 image_height *= 1 + inc;
220 set_zoom();
221 }
223 void
224 on_zoom_out_button_clicked(GtkObject* object, gpointer user_data)
225 {
226 image_width *= 1 - inc;
227 image_height *= 1 - inc;
228 set_zoom();
229 }
231 void
232 on_zoom_100_button_clicked(GtkObject* object, gpointer user_data)
233 {
234 image_width = gdk_pixbuf_get_width(image_buffer);
235 image_height = gdk_pixbuf_get_height(image_buffer);
236 set_zoom();
237 }
239 void
240 on_zoom_fit_button_clicked(GtkObject* object, gpointer user_data)
241 {
242 int w, h;
243 GtkWidget* image_a;
245 image_a = (GtkWidget*) lookup_widget(cropper_window, "image_area");
246 gdk_drawable_get_size(image_a->window, &w, &h);
248 image_width = w - 200;
249 image_height = h - 150;
250 set_zoom();
251 }
259 void
260 on_crop_clicked(GtkButton* button, gpointer user_data)
261 {
262 char crop_call[256];
264 sprintf(crop_call, "echo \"convert -crop %ix%i+%i+%i %s cropped_%s\"",
265 gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window,
266 "crop_width_spinbutton")),
267 gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window,
268 "crop_height_spinbutton")),
269 gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window,
270 "crop_x_spinbutton")),
271 gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window,
272 "crop_y_spinbutton")),
273 image_filename,
274 image_filename
275 );
276 system(crop_call);
277 gtk_main_quit();
278 }
281 void
282 on_cropper_window_create(GtkObject* object, gpointer user_data)
283 {
284 image_width = gdk_pixbuf_get_width(image_buffer);
285 image_height = gdk_pixbuf_get_height(image_buffer);
287 /*
288 image_buffer = gdk_pixbuf_new_from_file(image_filename, NULL);
289 image_area = gtk_image_new_from_pixbuf(image_buffer);
291 int w, h;
292 GtkWidget* image_a;
294 image_a = (GtkWidget*) lookup_widget(cropper_window, "image_area");
295 gdk_drawable_get_size(image_a->window, &w, &h);
297 image_width = w - 200;
298 image_height = h - 150;
299 set_zoom();
300 */
301 }
303 void
304 on_cropper_window_destroy(GtkObject* object, gpointer user_data)
305 {
306 gtk_main_quit();
307 }