cropper
diff callbacks.c @ 11:c18ba4ea1514
just cosmetic changes
author | meillo@marmaro.de |
---|---|
date | Thu, 04 Mar 2010 14:18:19 +0100 |
parents | 5e282003f0c1 |
children | 13bc21684b8a |
line diff
1.1 --- a/callbacks.c Thu Mar 04 13:54:17 2010 +0100 1.2 +++ b/callbacks.c Thu Mar 04 14:18:19 2010 +0100 1.3 @@ -1,6 +1,5 @@ 1.4 #include <gtk/gtk.h> 1.5 #include <gdk-pixbuf/gdk-pixbuf.h> 1.6 - 1.7 #include "main.h" 1.8 #include "callbacks.h" 1.9 #include "support.h" 1.10 @@ -8,42 +7,54 @@ 1.11 int image_width; 1.12 int image_height; 1.13 float inc = 0.3; 1.14 + 1.15 + 1.16 /* 1.17 -void update_spin_button_ratio(GtkWidget* spinbutton) { 1.18 +void 1.19 +update_spin_button_ratio(GtkWidget* spinbutton) 1.20 +{ 1.21 g_print("ratio change: %f\n", ratio); 1.22 on_ratio_w_spinbutton_value_changed(spinbutton, NULL); 1.23 } 1.24 1.25 1.26 - 1.27 - 1.28 - 1.29 -void on_ratio_none_activate (GtkMenuItem* menuitem, gpointer user_data) { 1.30 +void 1.31 +on_ratio_none_activate(GtkMenuItem* menuitem, gpointer user_data) 1.32 +{ 1.33 ratio = 1; 1.34 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton")); 1.35 } 1.36 1.37 1.38 -void on_ratio_square_activate (GtkMenuItem* menuitem, gpointer user_data) { 1.39 +void 1.40 +on_ratio_square_activate(GtkMenuItem* menuitem, gpointer user_data) 1.41 +{ 1.42 ratio = 1; 1.43 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton")); 1.44 } 1.45 1.46 1.47 -void on_ratio_4x3_activate (GtkMenuItem* menuitem, gpointer user_data) { 1.48 +void 1.49 +on_ratio_4x3_activate(GtkMenuItem* menuitem, gpointer user_data) 1.50 +{ 1.51 ratio = 4.0/3.0; 1.52 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton")); 1.53 } 1.54 1.55 1.56 -void on_ratio_3x2_activate (GtkMenuItem* menuitem, gpointer user_data) { 1.57 +void 1.58 +on_ratio_3x2_activate(GtkMenuItem* menuitem, gpointer user_data) 1.59 +{ 1.60 ratio = 1.5; 1.61 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton")); 1.62 } 1.63 1.64 1.65 -void on_ratio_custom_activate (GtkMenuItem* menuitem, gpointer user_data) { 1.66 - 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")); 1.67 +void 1.68 +on_ratio_custom_activate(GtkMenuItem* menuitem, gpointer user_data) 1.69 +{ 1.70 + ratio = gtk_spin_button_get_value(lookup_widget(cropper_window, "ratio_w_spinbutton")) 1.71 + / gtk_spin_button_get_value(lookup_widget(cropper_window, "ratio_h_spinbutton")); 1.72 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton")); 1.73 } 1.74 */ 1.75 @@ -57,8 +68,10 @@ 1.76 1.77 1.78 /* 1.79 -static void ratio_optionmenu_changed_cb (GtkOptionMenu* optionmenu, gpointer unser_data) { 1.80 - int idx = gtk_option_menu_get_history (optionmenu); 1.81 +static void 1.82 +ratio_optionmenu_changed_cb(GtkOptionMenu* optionmenu, gpointer unser_data) 1.83 +{ 1.84 + int idx = gtk_option_menu_get_history(optionmenu); 1.85 int w = 1, h = 1; 1.86 gboolean use_ratio = TRUE; 1.87 1.88 @@ -87,30 +100,39 @@ 1.89 break; 1.90 case GTH_CROP_RATIO_CUSTOM: 1.91 default: 1.92 - w = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (lookup_widget(cropper_window, "ratio_w_spinbutton"))); 1.93 - h = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (lookup_widget(cropper_window, "ratio_h_spinbutton"))); 1.94 + w = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON( 1.95 + lookup_widget(cropper_window, "ratio_w_spinbutton"))); 1.96 + h = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON( 1.97 + lookup_widget(cropper_window, "ratio_h_spinbutton"))); 1.98 break; 1.99 } 1.100 1.101 - gtk_widget_set_sensitive (lookup_widget(cropper_window, "custom_ratio_box"), idx == GTH_CROP_RATIO_CUSTOM); 1.102 - set_spin_value (cropper_window, lookup_widget(cropper_window, "ratio_w_spinbutton"), w); 1.103 - set_spin_value (cropper_window, lookup_widget(cropper_window, "ratio_h_spinbutton"), h); 1.104 + gtk_widget_set_sensitive(lookup_widget(cropper_window, "custom_ratio_box"), 1.105 + idx == GTH_CROP_RATIO_CUSTOM); 1.106 + set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_w_spinbutton"), w); 1.107 + set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_h_spinbutton"), h); 1.108 1.109 - gth_image_selector_set_ratio (GTH_IMAGE_SELECTOR (lookup_widget(cropper_window, "crop_image")), use_ratio, (double) w / h); 1.110 + gth_image_selector_set_ratio(GTH_IMAGE_SELECTOR(lookup_widget(cropper_window, "crop_image")), 1.111 + use_ratio, (double) w / h); 1.112 } 1.113 1.114 1.115 -static void ratio_value_changed_cb (GtkSpinButton* spin, gpointer unser_data) { 1.116 +static void 1.117 +ratio_value_changed_cb(GtkSpinButton* spin, gpointer unser_data) 1.118 +{ 1.119 int w, h; 1.120 1.121 - w = gtk_spin_button_get_value_as_int (lookup_widget(cropper_window, "ratio_w_spinbutton")); 1.122 - h = gtk_spin_button_get_value_as_int (lookup_widget(cropper_window, "ratio_h_spinbutton")); 1.123 + w = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_w_spinbutton")); 1.124 + h = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_h_spinbutton")); 1.125 1.126 - gth_image_selector_set_ratio (GTH_IMAGE_SELECTOR (lookup_widget(cropper_window, "crop_image")), TRUE, (double) w / h); 1.127 + gth_image_selector_set_ratio(GTH_IMAGE_SELECTOR( 1.128 + lookup_widget(cropper_window, "crop_image")), TRUE, (double) w / h); 1.129 } 1.130 1.131 1.132 -static void ratio_swap_button_cb (GtkButton* button, gpointer unser_data) { 1.133 +static void 1.134 +ratio_swap_button_cb(GtkButton* button, gpointer unser_data) 1.135 +{ 1.136 int w, h; 1.137 1.138 w = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_w_spinbutton")); 1.139 @@ -119,7 +141,8 @@ 1.140 set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_w_spinbutton"), h); 1.141 set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_h_spinbutton"), w); 1.142 1.143 - gth_image_selector_set_ratio(GTH_IMAGE_SELECTOR (lookup_widget(cropper_window, "crop_image")), TRUE, (double) h / w); 1.144 + gth_image_selector_set_ratio(GTH_IMAGE_SELECTOR(lookup_widget(cropper_window, 1.145 + "crop_image")), TRUE, (double) h / w); 1.146 } 1.147 1.148 */ 1.149 @@ -132,31 +155,45 @@ 1.150 1.151 1.152 /* 1.153 -void on_ratio_w_spinbutton_value_changed (GtkSpinButton* spinbutton, gpointer user_data) { 1.154 +void 1.155 +on_ratio_w_spinbutton_value_changed(GtkSpinButton* spinbutton, gpointer user_data) 1.156 +{ 1.157 g_print("spinbutton W - ratio: %f\n", ratio); 1.158 - gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_h_spinbutton"), gtk_spin_button_get_value(spinbutton) / ratio); 1.159 + gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_h_spinbutton"), 1.160 + gtk_spin_button_get_value(spinbutton) / ratio); 1.161 } 1.162 1.163 1.164 -void on_ratio_w_spinbutton_change_value (GtkSpinButton* spinbutton, GtkScrollType scroll, gpointer user_data) { 1.165 +void 1.166 +on_ratio_w_spinbutton_change_value(GtkSpinButton* spinbutton, GtkScrollType scroll, gpointer user_data) 1.167 +{ 1.168 } 1.169 1.170 1.171 -void on_ratio_h_spinbutton_change_value (GtkSpinButton* spinbutton, GtkScrollType scroll, gpointer user_data) { 1.172 +void 1.173 +on_ratio_h_spinbutton_change_value(GtkSpinButton* spinbutton, GtkScrollType scroll, gpointer user_data) 1.174 +{ 1.175 } 1.176 1.177 1.178 -void on_ratio_h_spinbutton_value_changed (GtkSpinButton* spinbutton, gpointer user_data) { 1.179 +void 1.180 +on_ratio_h_spinbutton_value_changed(GtkSpinButton* spinbutton, gpointer user_data) 1.181 +{ 1.182 g_print("spinbutton H - ratio: %f\n", ratio); 1.183 - gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_w_spinbutton"), gtk_spin_button_get_value(spinbutton) * ratio); 1.184 + gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_w_spinbutton"), 1.185 + gtk_spin_button_get_value(spinbutton) * ratio); 1.186 1.187 } 1.188 1.189 1.190 -void on_ratio_swap_button_clicked (GtkButton* button, gpointer user_data) { 1.191 +void 1.192 +on_ratio_swap_button_clicked(GtkButton* button, gpointer user_data) 1.193 +{ 1.194 1.195 ratio = 1.0 / ratio; 1.196 - gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_w_spinbutton"), gtk_spin_button_get_value(lookup_widget(cropper_window, "ratio_h_spinbutton"))); 1.197 + gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_w_spinbutton"), 1.198 + gtk_spin_button_get_value(lookup_widget(cropper_window, 1.199 + "ratio_h_spinbutton"))); 1.200 gtk_spin_button_update(lookup_widget(cropper_window, "ratio_w_spinbutton")); 1.201 1.202 } 1.203 @@ -165,7 +202,9 @@ 1.204 1.205 1.206 /* zoom */ 1.207 -void set_zoom() { 1.208 +void 1.209 +set_zoom() 1.210 +{ 1.211 static GdkPixbuf* pixbuf_new; 1.212 g_object_unref(pixbuf_new); 1.213 1.214 @@ -173,30 +212,38 @@ 1.215 gtk_image_set_from_pixbuf((GtkImage*) lookup_widget(cropper_window, "image_area"), pixbuf_new); 1.216 } 1.217 1.218 -void on_zoom_in_button_clicked(GtkObject* object, gpointer user_data) { 1.219 +void 1.220 +on_zoom_in_button_clicked(GtkObject* object, gpointer user_data) 1.221 +{ 1.222 image_width *= 1 + inc; 1.223 image_height *= 1 + inc; 1.224 set_zoom(); 1.225 } 1.226 1.227 -void on_zoom_out_button_clicked(GtkObject* object, gpointer user_data) { 1.228 +void 1.229 +on_zoom_out_button_clicked(GtkObject* object, gpointer user_data) 1.230 +{ 1.231 image_width *= 1 - inc; 1.232 image_height *= 1 - inc; 1.233 set_zoom(); 1.234 } 1.235 1.236 -void on_zoom_100_button_clicked(GtkObject* object, gpointer user_data) { 1.237 +void 1.238 +on_zoom_100_button_clicked(GtkObject* object, gpointer user_data) 1.239 +{ 1.240 image_width = gdk_pixbuf_get_width(image_buffer); 1.241 image_height = gdk_pixbuf_get_height(image_buffer); 1.242 set_zoom(); 1.243 } 1.244 1.245 -void on_zoom_fit_button_clicked(GtkObject* object, gpointer user_data) { 1.246 +void 1.247 +on_zoom_fit_button_clicked(GtkObject* object, gpointer user_data) 1.248 +{ 1.249 int w, h; 1.250 GtkWidget* image_a; 1.251 1.252 image_a = (GtkWidget*) lookup_widget(cropper_window, "image_area"); 1.253 - gdk_drawable_get_size (image_a->window, &w, &h); 1.254 + gdk_drawable_get_size(image_a->window, &w, &h); 1.255 1.256 image_width = w - 200; 1.257 image_height = h - 150; 1.258 @@ -209,14 +256,20 @@ 1.259 1.260 1.261 1.262 -void on_crop_clicked(GtkButton* button, gpointer user_data) { 1.263 +void 1.264 +on_crop_clicked(GtkButton* button, gpointer user_data) 1.265 +{ 1.266 char crop_call[256]; 1.267 1.268 sprintf(crop_call, "echo \"convert -crop %ix%i+%i+%i %s cropped_%s\"", 1.269 - gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window, "crop_width_spinbutton")), 1.270 - gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window, "crop_height_spinbutton")), 1.271 - gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window, "crop_x_spinbutton")), 1.272 - gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window, "crop_y_spinbutton")), 1.273 + gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window, 1.274 + "crop_width_spinbutton")), 1.275 + gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window, 1.276 + "crop_height_spinbutton")), 1.277 + gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window, 1.278 + "crop_x_spinbutton")), 1.279 + gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window, 1.280 + "crop_y_spinbutton")), 1.281 image_filename, 1.282 image_filename 1.283 ); 1.284 @@ -224,19 +277,22 @@ 1.285 gtk_main_quit(); 1.286 } 1.287 1.288 -void on_cropper_window_create(GtkObject* object, gpointer user_data) { 1.289 + 1.290 +void 1.291 +on_cropper_window_create(GtkObject* object, gpointer user_data) 1.292 +{ 1.293 image_width = gdk_pixbuf_get_width(image_buffer); 1.294 image_height = gdk_pixbuf_get_height(image_buffer); 1.295 1.296 /* 1.297 - image_buffer = gdk_pixbuf_new_from_file(image_filename, NULL); 1.298 - image_area = gtk_image_new_from_pixbuf(image_buffer); 1.299 + image_buffer = gdk_pixbuf_new_from_file(image_filename, NULL); 1.300 + image_area = gtk_image_new_from_pixbuf(image_buffer); 1.301 1.302 int w, h; 1.303 GtkWidget* image_a; 1.304 1.305 image_a = (GtkWidget*) lookup_widget(cropper_window, "image_area"); 1.306 - gdk_drawable_get_size (image_a->window, &w, &h); 1.307 + gdk_drawable_get_size(image_a->window, &w, &h); 1.308 1.309 image_width = w - 200; 1.310 image_height = h - 150; 1.311 @@ -244,7 +300,9 @@ 1.312 */ 1.313 } 1.314 1.315 -void on_cropper_window_destroy(GtkObject* object, gpointer user_data) { 1.316 +void 1.317 +on_cropper_window_destroy(GtkObject* object, gpointer user_data) 1.318 +{ 1.319 gtk_main_quit(); 1.320 } 1.321