Mercurial > cropper
comparison callbacks.c @ 11:c18ba4ea1514
just cosmetic changes
author | meillo@marmaro.de |
---|---|
date | Thu, 04 Mar 2010 14:18:19 +0100 |
parents | 5e282003f0c1 |
children | 13bc21684b8a |
comparison
equal
deleted
inserted
replaced
10:5e282003f0c1 | 11:c18ba4ea1514 |
---|---|
1 #include <gtk/gtk.h> | 1 #include <gtk/gtk.h> |
2 #include <gdk-pixbuf/gdk-pixbuf.h> | 2 #include <gdk-pixbuf/gdk-pixbuf.h> |
3 | |
4 #include "main.h" | 3 #include "main.h" |
5 #include "callbacks.h" | 4 #include "callbacks.h" |
6 #include "support.h" | 5 #include "support.h" |
7 | 6 |
8 int image_width; | 7 int image_width; |
9 int image_height; | 8 int image_height; |
10 float inc = 0.3; | 9 float inc = 0.3; |
10 | |
11 | |
11 /* | 12 /* |
12 void update_spin_button_ratio(GtkWidget* spinbutton) { | 13 void |
14 update_spin_button_ratio(GtkWidget* spinbutton) | |
15 { | |
13 g_print("ratio change: %f\n", ratio); | 16 g_print("ratio change: %f\n", ratio); |
14 on_ratio_w_spinbutton_value_changed(spinbutton, NULL); | 17 on_ratio_w_spinbutton_value_changed(spinbutton, NULL); |
15 } | 18 } |
16 | 19 |
17 | 20 |
18 | 21 void |
19 | 22 on_ratio_none_activate(GtkMenuItem* menuitem, gpointer user_data) |
20 | 23 { |
21 void on_ratio_none_activate (GtkMenuItem* menuitem, gpointer user_data) { | |
22 ratio = 1; | 24 ratio = 1; |
23 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton")); | 25 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton")); |
24 } | 26 } |
25 | 27 |
26 | 28 |
27 void on_ratio_square_activate (GtkMenuItem* menuitem, gpointer user_data) { | 29 void |
30 on_ratio_square_activate(GtkMenuItem* menuitem, gpointer user_data) | |
31 { | |
28 ratio = 1; | 32 ratio = 1; |
29 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton")); | 33 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton")); |
30 } | 34 } |
31 | 35 |
32 | 36 |
33 void on_ratio_4x3_activate (GtkMenuItem* menuitem, gpointer user_data) { | 37 void |
38 on_ratio_4x3_activate(GtkMenuItem* menuitem, gpointer user_data) | |
39 { | |
34 ratio = 4.0/3.0; | 40 ratio = 4.0/3.0; |
35 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton")); | 41 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton")); |
36 } | 42 } |
37 | 43 |
38 | 44 |
39 void on_ratio_3x2_activate (GtkMenuItem* menuitem, gpointer user_data) { | 45 void |
46 on_ratio_3x2_activate(GtkMenuItem* menuitem, gpointer user_data) | |
47 { | |
40 ratio = 1.5; | 48 ratio = 1.5; |
41 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton")); | 49 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton")); |
42 } | 50 } |
43 | 51 |
44 | 52 |
45 void on_ratio_custom_activate (GtkMenuItem* menuitem, gpointer user_data) { | 53 void |
46 ratio = gtk_spin_button_get_value(lookup_widget(cropper_window, "ratio_w_spinbutton")) / gtk_spin_button_get_value(lookup_widget(cropper_window, "ratio_h_spinbutton")); | 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")); | |
47 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton")); | 58 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton")); |
48 } | 59 } |
49 */ | 60 */ |
50 | 61 |
51 | 62 |
55 | 66 |
56 | 67 |
57 | 68 |
58 | 69 |
59 /* | 70 /* |
60 static void ratio_optionmenu_changed_cb (GtkOptionMenu* optionmenu, gpointer unser_data) { | 71 static void |
61 int idx = gtk_option_menu_get_history (optionmenu); | 72 ratio_optionmenu_changed_cb(GtkOptionMenu* optionmenu, gpointer unser_data) |
73 { | |
74 int idx = gtk_option_menu_get_history(optionmenu); | |
62 int w = 1, h = 1; | 75 int w = 1, h = 1; |
63 gboolean use_ratio = TRUE; | 76 gboolean use_ratio = TRUE; |
64 | 77 |
65 switch (idx) { | 78 switch (idx) { |
66 case GTH_CROP_RATIO_NONE: | 79 case GTH_CROP_RATIO_NONE: |
85 w = 4; | 98 w = 4; |
86 h = 6; | 99 h = 6; |
87 break; | 100 break; |
88 case GTH_CROP_RATIO_CUSTOM: | 101 case GTH_CROP_RATIO_CUSTOM: |
89 default: | 102 default: |
90 w = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (lookup_widget(cropper_window, "ratio_w_spinbutton"))); | 103 w = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON( |
91 h = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (lookup_widget(cropper_window, "ratio_h_spinbutton"))); | 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"))); | |
92 break; | 107 break; |
93 } | 108 } |
94 | 109 |
95 gtk_widget_set_sensitive (lookup_widget(cropper_window, "custom_ratio_box"), idx == GTH_CROP_RATIO_CUSTOM); | 110 gtk_widget_set_sensitive(lookup_widget(cropper_window, "custom_ratio_box"), |
96 set_spin_value (cropper_window, lookup_widget(cropper_window, "ratio_w_spinbutton"), w); | 111 idx == GTH_CROP_RATIO_CUSTOM); |
97 set_spin_value (cropper_window, lookup_widget(cropper_window, "ratio_h_spinbutton"), h); | 112 set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_w_spinbutton"), w); |
98 | 113 set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_h_spinbutton"), h); |
99 gth_image_selector_set_ratio (GTH_IMAGE_SELECTOR (lookup_widget(cropper_window, "crop_image")), use_ratio, (double) w / h); | 114 |
100 } | 115 gth_image_selector_set_ratio(GTH_IMAGE_SELECTOR(lookup_widget(cropper_window, "crop_image")), |
101 | 116 use_ratio, (double) w / h); |
102 | 117 } |
103 static void ratio_value_changed_cb (GtkSpinButton* spin, gpointer unser_data) { | 118 |
104 int w, h; | 119 |
105 | 120 static void |
106 w = gtk_spin_button_get_value_as_int (lookup_widget(cropper_window, "ratio_w_spinbutton")); | 121 ratio_value_changed_cb(GtkSpinButton* spin, gpointer unser_data) |
107 h = gtk_spin_button_get_value_as_int (lookup_widget(cropper_window, "ratio_h_spinbutton")); | 122 { |
108 | |
109 gth_image_selector_set_ratio (GTH_IMAGE_SELECTOR (lookup_widget(cropper_window, "crop_image")), TRUE, (double) w / h); | |
110 } | |
111 | |
112 | |
113 static void ratio_swap_button_cb (GtkButton* button, gpointer unser_data) { | |
114 int w, h; | 123 int w, h; |
115 | 124 |
116 w = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_w_spinbutton")); | 125 w = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_w_spinbutton")); |
117 h = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_h_spinbutton")); | 126 h = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_h_spinbutton")); |
127 | |
128 gth_image_selector_set_ratio(GTH_IMAGE_SELECTOR( | |
129 lookup_widget(cropper_window, "crop_image")), TRUE, (double) w / h); | |
130 } | |
131 | |
132 | |
133 static void | |
134 ratio_swap_button_cb(GtkButton* button, gpointer unser_data) | |
135 { | |
136 int w, h; | |
137 | |
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")); | |
118 | 140 |
119 set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_w_spinbutton"), h); | 141 set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_w_spinbutton"), h); |
120 set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_h_spinbutton"), w); | 142 set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_h_spinbutton"), w); |
121 | 143 |
122 gth_image_selector_set_ratio(GTH_IMAGE_SELECTOR (lookup_widget(cropper_window, "crop_image")), TRUE, (double) h / w); | 144 gth_image_selector_set_ratio(GTH_IMAGE_SELECTOR(lookup_widget(cropper_window, |
145 "crop_image")), TRUE, (double) h / w); | |
123 } | 146 } |
124 | 147 |
125 */ | 148 */ |
126 | 149 |
127 | 150 |
130 | 153 |
131 | 154 |
132 | 155 |
133 | 156 |
134 /* | 157 /* |
135 void on_ratio_w_spinbutton_value_changed (GtkSpinButton* spinbutton, gpointer user_data) { | 158 void |
159 on_ratio_w_spinbutton_value_changed(GtkSpinButton* spinbutton, gpointer user_data) | |
160 { | |
136 g_print("spinbutton W - ratio: %f\n", ratio); | 161 g_print("spinbutton W - ratio: %f\n", ratio); |
137 gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_h_spinbutton"), gtk_spin_button_get_value(spinbutton) / ratio); | 162 gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_h_spinbutton"), |
138 } | 163 gtk_spin_button_get_value(spinbutton) / ratio); |
139 | 164 } |
140 | 165 |
141 void on_ratio_w_spinbutton_change_value (GtkSpinButton* spinbutton, GtkScrollType scroll, gpointer user_data) { | 166 |
142 } | 167 void |
143 | 168 on_ratio_w_spinbutton_change_value(GtkSpinButton* spinbutton, GtkScrollType scroll, gpointer user_data) |
144 | 169 { |
145 void on_ratio_h_spinbutton_change_value (GtkSpinButton* spinbutton, GtkScrollType scroll, gpointer user_data) { | 170 } |
146 } | 171 |
147 | 172 |
148 | 173 void |
149 void on_ratio_h_spinbutton_value_changed (GtkSpinButton* spinbutton, gpointer user_data) { | 174 on_ratio_h_spinbutton_change_value(GtkSpinButton* spinbutton, GtkScrollType scroll, gpointer user_data) |
175 { | |
176 } | |
177 | |
178 | |
179 void | |
180 on_ratio_h_spinbutton_value_changed(GtkSpinButton* spinbutton, gpointer user_data) | |
181 { | |
150 g_print("spinbutton H - ratio: %f\n", ratio); | 182 g_print("spinbutton H - ratio: %f\n", ratio); |
151 gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_w_spinbutton"), gtk_spin_button_get_value(spinbutton) * ratio); | 183 gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_w_spinbutton"), |
152 | 184 gtk_spin_button_get_value(spinbutton) * ratio); |
153 } | 185 |
154 | 186 } |
155 | 187 |
156 void on_ratio_swap_button_clicked (GtkButton* button, gpointer user_data) { | 188 |
189 void | |
190 on_ratio_swap_button_clicked(GtkButton* button, gpointer user_data) | |
191 { | |
157 | 192 |
158 ratio = 1.0 / ratio; | 193 ratio = 1.0 / ratio; |
159 gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_w_spinbutton"), gtk_spin_button_get_value(lookup_widget(cropper_window, "ratio_h_spinbutton"))); | 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"))); | |
160 gtk_spin_button_update(lookup_widget(cropper_window, "ratio_w_spinbutton")); | 197 gtk_spin_button_update(lookup_widget(cropper_window, "ratio_w_spinbutton")); |
161 | 198 |
162 } | 199 } |
163 */ | 200 */ |
164 | 201 |
165 | 202 |
166 | 203 |
167 /* zoom */ | 204 /* zoom */ |
168 void set_zoom() { | 205 void |
206 set_zoom() | |
207 { | |
169 static GdkPixbuf* pixbuf_new; | 208 static GdkPixbuf* pixbuf_new; |
170 g_object_unref(pixbuf_new); | 209 g_object_unref(pixbuf_new); |
171 | 210 |
172 pixbuf_new = gdk_pixbuf_scale_simple(image_buffer, image_width, image_height, GDK_INTERP_BILINEAR); | 211 pixbuf_new = gdk_pixbuf_scale_simple(image_buffer, image_width, image_height, GDK_INTERP_BILINEAR); |
173 gtk_image_set_from_pixbuf((GtkImage*) lookup_widget(cropper_window, "image_area"), pixbuf_new); | 212 gtk_image_set_from_pixbuf((GtkImage*) lookup_widget(cropper_window, "image_area"), pixbuf_new); |
174 } | 213 } |
175 | 214 |
176 void on_zoom_in_button_clicked(GtkObject* object, gpointer user_data) { | 215 void |
216 on_zoom_in_button_clicked(GtkObject* object, gpointer user_data) | |
217 { | |
177 image_width *= 1 + inc; | 218 image_width *= 1 + inc; |
178 image_height *= 1 + inc; | 219 image_height *= 1 + inc; |
179 set_zoom(); | 220 set_zoom(); |
180 } | 221 } |
181 | 222 |
182 void on_zoom_out_button_clicked(GtkObject* object, gpointer user_data) { | 223 void |
224 on_zoom_out_button_clicked(GtkObject* object, gpointer user_data) | |
225 { | |
183 image_width *= 1 - inc; | 226 image_width *= 1 - inc; |
184 image_height *= 1 - inc; | 227 image_height *= 1 - inc; |
185 set_zoom(); | 228 set_zoom(); |
186 } | 229 } |
187 | 230 |
188 void on_zoom_100_button_clicked(GtkObject* object, gpointer user_data) { | 231 void |
232 on_zoom_100_button_clicked(GtkObject* object, gpointer user_data) | |
233 { | |
189 image_width = gdk_pixbuf_get_width(image_buffer); | 234 image_width = gdk_pixbuf_get_width(image_buffer); |
190 image_height = gdk_pixbuf_get_height(image_buffer); | 235 image_height = gdk_pixbuf_get_height(image_buffer); |
191 set_zoom(); | 236 set_zoom(); |
192 } | 237 } |
193 | 238 |
194 void on_zoom_fit_button_clicked(GtkObject* object, gpointer user_data) { | 239 void |
240 on_zoom_fit_button_clicked(GtkObject* object, gpointer user_data) | |
241 { | |
195 int w, h; | 242 int w, h; |
196 GtkWidget* image_a; | 243 GtkWidget* image_a; |
197 | 244 |
198 image_a = (GtkWidget*) lookup_widget(cropper_window, "image_area"); | 245 image_a = (GtkWidget*) lookup_widget(cropper_window, "image_area"); |
199 gdk_drawable_get_size (image_a->window, &w, &h); | 246 gdk_drawable_get_size(image_a->window, &w, &h); |
200 | 247 |
201 image_width = w - 200; | 248 image_width = w - 200; |
202 image_height = h - 150; | 249 image_height = h - 150; |
203 set_zoom(); | 250 set_zoom(); |
204 } | 251 } |
207 | 254 |
208 | 255 |
209 | 256 |
210 | 257 |
211 | 258 |
212 void on_crop_clicked(GtkButton* button, gpointer user_data) { | 259 void |
260 on_crop_clicked(GtkButton* button, gpointer user_data) | |
261 { | |
213 char crop_call[256]; | 262 char crop_call[256]; |
214 | 263 |
215 sprintf(crop_call, "echo \"convert -crop %ix%i+%i+%i %s cropped_%s\"", | 264 sprintf(crop_call, "echo \"convert -crop %ix%i+%i+%i %s cropped_%s\"", |
216 gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window, "crop_width_spinbutton")), | 265 gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window, |
217 gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window, "crop_height_spinbutton")), | 266 "crop_width_spinbutton")), |
218 gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window, "crop_x_spinbutton")), | 267 gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window, |
219 gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window, "crop_y_spinbutton")), | 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")), | |
220 image_filename, | 273 image_filename, |
221 image_filename | 274 image_filename |
222 ); | 275 ); |
223 system(crop_call); | 276 system(crop_call); |
224 gtk_main_quit(); | 277 gtk_main_quit(); |
225 } | 278 } |
226 | 279 |
227 void on_cropper_window_create(GtkObject* object, gpointer user_data) { | 280 |
281 void | |
282 on_cropper_window_create(GtkObject* object, gpointer user_data) | |
283 { | |
228 image_width = gdk_pixbuf_get_width(image_buffer); | 284 image_width = gdk_pixbuf_get_width(image_buffer); |
229 image_height = gdk_pixbuf_get_height(image_buffer); | 285 image_height = gdk_pixbuf_get_height(image_buffer); |
230 | 286 |
231 /* | 287 /* |
232 image_buffer = gdk_pixbuf_new_from_file(image_filename, NULL); | 288 image_buffer = gdk_pixbuf_new_from_file(image_filename, NULL); |
233 image_area = gtk_image_new_from_pixbuf(image_buffer); | 289 image_area = gtk_image_new_from_pixbuf(image_buffer); |
234 | 290 |
235 int w, h; | 291 int w, h; |
236 GtkWidget* image_a; | 292 GtkWidget* image_a; |
237 | 293 |
238 image_a = (GtkWidget*) lookup_widget(cropper_window, "image_area"); | 294 image_a = (GtkWidget*) lookup_widget(cropper_window, "image_area"); |
239 gdk_drawable_get_size (image_a->window, &w, &h); | 295 gdk_drawable_get_size(image_a->window, &w, &h); |
240 | 296 |
241 image_width = w - 200; | 297 image_width = w - 200; |
242 image_height = h - 150; | 298 image_height = h - 150; |
243 set_zoom(); | 299 set_zoom(); |
244 */ | 300 */ |
245 } | 301 } |
246 | 302 |
247 void on_cropper_window_destroy(GtkObject* object, gpointer user_data) { | 303 void |
304 on_cropper_window_destroy(GtkObject* object, gpointer user_data) | |
305 { | |
248 gtk_main_quit(); | 306 gtk_main_quit(); |
249 } | 307 } |
250 | 308 |