cropper

view callbacks.c @ 10:5e282003f0c1

minor changes; besser indenting
author meillo@marmaro.de
date Thu, 04 Mar 2010 13:54:17 +0100
parents 7e1cf00de1df
children c18ba4ea1514
line source
1 #include <gtk/gtk.h>
2 #include <gdk-pixbuf/gdk-pixbuf.h>
4 #include "main.h"
5 #include "callbacks.h"
6 #include "support.h"
8 int image_width;
9 int image_height;
10 float inc = 0.3;
11 /*
12 void update_spin_button_ratio(GtkWidget* spinbutton) {
13 g_print("ratio change: %f\n", ratio);
14 on_ratio_w_spinbutton_value_changed(spinbutton, NULL);
15 }
21 void on_ratio_none_activate (GtkMenuItem* menuitem, gpointer user_data) {
22 ratio = 1;
23 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
24 }
27 void on_ratio_square_activate (GtkMenuItem* menuitem, gpointer user_data) {
28 ratio = 1;
29 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
30 }
33 void on_ratio_4x3_activate (GtkMenuItem* menuitem, gpointer user_data) {
34 ratio = 4.0/3.0;
35 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
36 }
39 void on_ratio_3x2_activate (GtkMenuItem* menuitem, gpointer user_data) {
40 ratio = 1.5;
41 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
42 }
45 void on_ratio_custom_activate (GtkMenuItem* menuitem, gpointer user_data) {
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"));
47 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
48 }
49 */
59 /*
60 static void ratio_optionmenu_changed_cb (GtkOptionMenu* optionmenu, gpointer unser_data) {
61 int idx = gtk_option_menu_get_history (optionmenu);
62 int w = 1, h = 1;
63 gboolean use_ratio = TRUE;
65 switch (idx) {
66 case GTH_CROP_RATIO_NONE:
67 use_ratio = FALSE;
68 break;
69 case GTH_CROP_RATIO_SQUARE:
70 w = h = 1;
71 break;
72 case GTH_CROP_RATIO_IMAGE:
73 w = lookup_widget(cropper_window, "image_width");
74 h = lookup_widget(cropper_window, "image_height");
75 break;
76 case GTH_CROP_RATIO_DISPLAY:
77 w = lookup_widget(cropper_window, "display_width");
78 h = lookup_widget(cropper_window, "display_height");
79 break;
80 case GTH_CROP_RATIO_4_3:
81 w = 4;
82 h = 3;
83 break;
84 case GTH_CROP_RATIO_4_6:
85 w = 4;
86 h = 6;
87 break;
88 case GTH_CROP_RATIO_CUSTOM:
89 default:
90 w = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (lookup_widget(cropper_window, "ratio_w_spinbutton")));
91 h = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (lookup_widget(cropper_window, "ratio_h_spinbutton")));
92 break;
93 }
95 gtk_widget_set_sensitive (lookup_widget(cropper_window, "custom_ratio_box"), idx == GTH_CROP_RATIO_CUSTOM);
96 set_spin_value (cropper_window, lookup_widget(cropper_window, "ratio_w_spinbutton"), w);
97 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);
100 }
103 static void ratio_value_changed_cb (GtkSpinButton* spin, gpointer unser_data) {
104 int w, h;
106 w = gtk_spin_button_get_value_as_int (lookup_widget(cropper_window, "ratio_w_spinbutton"));
107 h = gtk_spin_button_get_value_as_int (lookup_widget(cropper_window, "ratio_h_spinbutton"));
109 gth_image_selector_set_ratio (GTH_IMAGE_SELECTOR (lookup_widget(cropper_window, "crop_image")), TRUE, (double) w / h);
110 }
113 static void ratio_swap_button_cb (GtkButton* button, gpointer unser_data) {
114 int w, h;
116 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"));
119 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);
122 gth_image_selector_set_ratio(GTH_IMAGE_SELECTOR (lookup_widget(cropper_window, "crop_image")), TRUE, (double) h / w);
123 }
125 */
134 /*
135 void on_ratio_w_spinbutton_value_changed (GtkSpinButton* spinbutton, gpointer user_data) {
136 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);
138 }
141 void on_ratio_w_spinbutton_change_value (GtkSpinButton* spinbutton, GtkScrollType scroll, gpointer user_data) {
142 }
145 void on_ratio_h_spinbutton_change_value (GtkSpinButton* spinbutton, GtkScrollType scroll, gpointer user_data) {
146 }
149 void on_ratio_h_spinbutton_value_changed (GtkSpinButton* spinbutton, gpointer user_data) {
150 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);
153 }
156 void on_ratio_swap_button_clicked (GtkButton* button, gpointer user_data) {
158 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")));
160 gtk_spin_button_update(lookup_widget(cropper_window, "ratio_w_spinbutton"));
162 }
163 */
167 /* zoom */
168 void set_zoom() {
169 static GdkPixbuf* pixbuf_new;
170 g_object_unref(pixbuf_new);
172 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);
174 }
176 void on_zoom_in_button_clicked(GtkObject* object, gpointer user_data) {
177 image_width *= 1 + inc;
178 image_height *= 1 + inc;
179 set_zoom();
180 }
182 void on_zoom_out_button_clicked(GtkObject* object, gpointer user_data) {
183 image_width *= 1 - inc;
184 image_height *= 1 - inc;
185 set_zoom();
186 }
188 void on_zoom_100_button_clicked(GtkObject* object, gpointer user_data) {
189 image_width = gdk_pixbuf_get_width(image_buffer);
190 image_height = gdk_pixbuf_get_height(image_buffer);
191 set_zoom();
192 }
194 void on_zoom_fit_button_clicked(GtkObject* object, gpointer user_data) {
195 int w, h;
196 GtkWidget* image_a;
198 image_a = (GtkWidget*) lookup_widget(cropper_window, "image_area");
199 gdk_drawable_get_size (image_a->window, &w, &h);
201 image_width = w - 200;
202 image_height = h - 150;
203 set_zoom();
204 }
212 void on_crop_clicked(GtkButton* button, gpointer user_data) {
213 char crop_call[256];
215 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")),
217 gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window, "crop_height_spinbutton")),
218 gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window, "crop_x_spinbutton")),
219 gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window, "crop_y_spinbutton")),
220 image_filename,
221 image_filename
222 );
223 system(crop_call);
224 gtk_main_quit();
225 }
227 void on_cropper_window_create(GtkObject* object, gpointer user_data) {
228 image_width = gdk_pixbuf_get_width(image_buffer);
229 image_height = gdk_pixbuf_get_height(image_buffer);
231 /*
232 image_buffer = gdk_pixbuf_new_from_file(image_filename, NULL);
233 image_area = gtk_image_new_from_pixbuf(image_buffer);
235 int w, h;
236 GtkWidget* image_a;
238 image_a = (GtkWidget*) lookup_widget(cropper_window, "image_area");
239 gdk_drawable_get_size (image_a->window, &w, &h);
241 image_width = w - 200;
242 image_height = h - 150;
243 set_zoom();
244 */
245 }
247 void on_cropper_window_destroy(GtkObject* object, gpointer user_data) {
248 gtk_main_quit();
249 }