cropper
view callbacks.c @ 7:ec2d11d96fb0
image is now gdk-pixbuff; zoom implemented in a basic way
author | meillo@marmaro.de |
---|---|
date | Wed, 19 Mar 2008 23:01:43 +0100 |
parents | 2f11ab3e6047 |
children | b0824876d379 |
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 on_zoom_in_button_clicked(GtkObject* object, gpointer user_data) {
170 printf("zoom in clicked\n");
171 image_width *= 1 + inc;
172 image_height *= 1 + inc;
173 gtk_image_set_from_pixbuf(lookup_widget(cropper_window, "image_area"),
174 gdk_pixbuf_scale_simple(image_buffer, image_width, image_height, GDK_INTERP_BILINEAR));
175 }
177 void on_zoom_out_button_clicked(GtkObject* object, gpointer user_data) {
178 printf("zoom out clicked\n");
179 image_width *= 1 - inc;
180 image_height *= 1 - inc;
181 gtk_image_set_from_pixbuf(lookup_widget(cropper_window, "image_area"),
182 gdk_pixbuf_scale_simple(image_buffer, image_width, image_height, GDK_INTERP_BILINEAR));
183 }
185 void on_zoom_100_button_clicked(GtkObject* object, gpointer user_data) {
186 printf("zoom 100 clicked\n");
187 image_width = gdk_pixbuf_get_width(image_buffer);
188 image_height = gdk_pixbuf_get_height(image_buffer);
189 gtk_image_set_from_pixbuf(lookup_widget(cropper_window, "image_area"),
190 gdk_pixbuf_scale_simple(image_buffer, image_width, image_height, GDK_INTERP_BILINEAR));
191 }
193 void on_zoom_fit_button_clicked(GtkObject* object, gpointer user_data) {
194 printf("zoom fit clicked\n");
195 image_width = gdk_pixbuf_get_width(image_buffer) + 200; /* FIXME */
196 image_height = gdk_pixbuf_get_height(image_buffer) + 200; /* FIXME */
197 gtk_image_set_from_pixbuf(lookup_widget(cropper_window, "image_area"),
198 gdk_pixbuf_scale_simple(image_buffer, image_width, image_height, GDK_INTERP_BILINEAR));
199 }
207 void on_crop_clicked(GtkButton* button, gpointer user_data) {
208 char crop_call[256];
210 sprintf(crop_call, "echo \"convert -crop %ix%i+%i+%i %s cropped_%s\"",
211 gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "crop_width_spinbutton")),
212 gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "crop_height_spinbutton")),
213 gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "crop_x_spinbutton")),
214 gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "crop_y_spinbutton")),
215 image_filename,
216 image_filename
217 );
218 system(crop_call);
219 gtk_main_quit();
220 }
222 void on_cropper_window_create (GtkObject* object, gpointer user_data) {
223 image_width = gdk_pixbuf_get_width(image_buffer);
224 image_height = gdk_pixbuf_get_height(image_buffer);
225 }
227 void on_cropper_window_destroy (GtkObject* object, gpointer user_data) {
228 gtk_main_quit();
229 }