cropper
view callbacks.c @ 8:b0824876d379
memory is now freed aswell; added (a crappy) zoom2fit; did some casts to get rid of warnings
author | meillo@marmaro.de |
---|---|
date | Thu, 20 Mar 2008 19:31:44 +0100 |
parents | ec2d11d96fb0 |
children | 7e1cf00de1df |
line source
1 #include <gtk/gtk.h>
2 #include <gdk-pixbuf/gdk-pixbuf.h>
4 #include "main.h"
5 #include "callbacks.h"
6 #include "interface.h"
7 #include "support.h"
9 int image_width;
10 int image_height;
11 float inc = 0.1;
12 /*
13 void update_spin_button_ratio(GtkWidget* spinbutton) {
14 g_print("ratio change: %f\n", ratio);
15 on_ratio_w_spinbutton_value_changed(spinbutton, NULL);
16 }
22 void on_ratio_none_activate (GtkMenuItem* menuitem, gpointer user_data) {
23 ratio = 1;
24 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
25 }
28 void on_ratio_square_activate (GtkMenuItem* menuitem, gpointer user_data) {
29 ratio = 1;
30 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
31 }
34 void on_ratio_4x3_activate (GtkMenuItem* menuitem, gpointer user_data) {
35 ratio = 4.0/3.0;
36 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
37 }
40 void on_ratio_3x2_activate (GtkMenuItem* menuitem, gpointer user_data) {
41 ratio = 1.5;
42 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
43 }
46 void on_ratio_custom_activate (GtkMenuItem* menuitem, gpointer user_data) {
47 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"));
48 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
49 }
50 */
60 /*
61 static void ratio_optionmenu_changed_cb (GtkOptionMenu* optionmenu, gpointer unser_data) {
62 int idx = gtk_option_menu_get_history (optionmenu);
63 int w = 1, h = 1;
64 gboolean use_ratio = TRUE;
66 switch (idx) {
67 case GTH_CROP_RATIO_NONE:
68 use_ratio = FALSE;
69 break;
70 case GTH_CROP_RATIO_SQUARE:
71 w = h = 1;
72 break;
73 case GTH_CROP_RATIO_IMAGE:
74 w = lookup_widget(cropper_window, "image_width");
75 h = lookup_widget(cropper_window, "image_height");
76 break;
77 case GTH_CROP_RATIO_DISPLAY:
78 w = lookup_widget(cropper_window, "display_width");
79 h = lookup_widget(cropper_window, "display_height");
80 break;
81 case GTH_CROP_RATIO_4_3:
82 w = 4;
83 h = 3;
84 break;
85 case GTH_CROP_RATIO_4_6:
86 w = 4;
87 h = 6;
88 break;
89 case GTH_CROP_RATIO_CUSTOM:
90 default:
91 w = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (lookup_widget(cropper_window, "ratio_w_spinbutton")));
92 h = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (lookup_widget(cropper_window, "ratio_h_spinbutton")));
93 break;
94 }
96 gtk_widget_set_sensitive (lookup_widget(cropper_window, "custom_ratio_box"), idx == GTH_CROP_RATIO_CUSTOM);
97 set_spin_value (cropper_window, lookup_widget(cropper_window, "ratio_w_spinbutton"), w);
98 set_spin_value (cropper_window, lookup_widget(cropper_window, "ratio_h_spinbutton"), h);
100 gth_image_selector_set_ratio (GTH_IMAGE_SELECTOR (lookup_widget(cropper_window, "crop_image")), use_ratio, (double) w / h);
101 }
104 static void ratio_value_changed_cb (GtkSpinButton* spin, gpointer unser_data) {
105 int w, h;
107 w = gtk_spin_button_get_value_as_int (lookup_widget(cropper_window, "ratio_w_spinbutton"));
108 h = gtk_spin_button_get_value_as_int (lookup_widget(cropper_window, "ratio_h_spinbutton"));
110 gth_image_selector_set_ratio (GTH_IMAGE_SELECTOR (lookup_widget(cropper_window, "crop_image")), TRUE, (double) w / h);
111 }
114 static void ratio_swap_button_cb (GtkButton* button, gpointer unser_data) {
115 int w, h;
117 w = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_w_spinbutton"));
118 h = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_h_spinbutton"));
120 set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_w_spinbutton"), h);
121 set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_h_spinbutton"), w);
123 gth_image_selector_set_ratio(GTH_IMAGE_SELECTOR (lookup_widget(cropper_window, "crop_image")), TRUE, (double) h / w);
124 }
126 */
135 /*
136 void on_ratio_w_spinbutton_value_changed (GtkSpinButton* spinbutton, gpointer user_data) {
137 g_print("spinbutton W - ratio: %f\n", ratio);
138 gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_h_spinbutton"), gtk_spin_button_get_value(spinbutton) / ratio);
139 }
142 void on_ratio_w_spinbutton_change_value (GtkSpinButton* spinbutton, GtkScrollType scroll, gpointer user_data) {
143 }
146 void on_ratio_h_spinbutton_change_value (GtkSpinButton* spinbutton, GtkScrollType scroll, gpointer user_data) {
147 }
150 void on_ratio_h_spinbutton_value_changed (GtkSpinButton* spinbutton, gpointer user_data) {
151 g_print("spinbutton H - ratio: %f\n", ratio);
152 gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_w_spinbutton"), gtk_spin_button_get_value(spinbutton) * ratio);
154 }
157 void on_ratio_swap_button_clicked (GtkButton* button, gpointer user_data) {
159 ratio = 1.0 / ratio;
160 gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_w_spinbutton"), gtk_spin_button_get_value(lookup_widget(cropper_window, "ratio_h_spinbutton")));
161 gtk_spin_button_update(lookup_widget(cropper_window, "ratio_w_spinbutton"));
163 }
164 */
168 /* zoom */
169 void set_zoom() {
170 static GdkPixbuf* pixbuf_new;
171 g_object_unref(pixbuf_new);
173 pixbuf_new = gdk_pixbuf_scale_simple(image_buffer, image_width, image_height, GDK_INTERP_HYPER);
174 gtk_image_set_from_pixbuf((GtkImage*) lookup_widget(cropper_window, "image_area"), pixbuf_new);
175 }
177 void on_zoom_in_button_clicked(GtkObject* object, gpointer user_data) {
178 image_width *= 1 + inc;
179 image_height *= 1 + inc;
180 set_zoom();
181 }
183 void on_zoom_out_button_clicked(GtkObject* object, gpointer user_data) {
184 image_width *= 1 - inc;
185 image_height *= 1 - inc;
186 set_zoom();
187 }
189 void on_zoom_100_button_clicked(GtkObject* object, gpointer user_data) {
190 image_width = gdk_pixbuf_get_width(image_buffer);
191 image_height = gdk_pixbuf_get_height(image_buffer);
192 set_zoom();
193 }
195 void on_zoom_fit_button_clicked(GtkObject* object, gpointer user_data) {
196 int w, h;
197 GtkWidget* image_a;
199 image_a = (GtkWidget*) lookup_widget(cropper_window, "image_area");
200 gdk_drawable_get_size (image_a->window, &w, &h);
202 image_width = w - 200;
203 image_height = h - 150;
204 set_zoom();
205 }
213 void on_crop_clicked(GtkButton* button, gpointer user_data) {
214 char crop_call[256];
216 sprintf(crop_call, "echo \"convert -crop %ix%i+%i+%i %s cropped_%s\"",
217 gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window, "crop_width_spinbutton")),
218 gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window, "crop_height_spinbutton")),
219 gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window, "crop_x_spinbutton")),
220 gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window, "crop_y_spinbutton")),
221 image_filename,
222 image_filename
223 );
224 system(crop_call);
225 gtk_main_quit();
226 }
228 void on_cropper_window_create (GtkObject* object, gpointer user_data) {
229 image_width = gdk_pixbuf_get_width(image_buffer);
230 image_height = gdk_pixbuf_get_height(image_buffer);
231 }
233 void on_cropper_window_destroy (GtkObject* object, gpointer user_data) {
234 gtk_main_quit();
235 }