cropper

view callbacks.c @ 5:61e5a1727231

added image widget, that displays the image
author meillo@marmaro.de
date Fri, 07 Dec 2007 21:35:49 +0100
parents 6aaba3a61563
children ec2d11d96fb0
line source
1 #include <gtk/gtk.h>
3 #include "main.h"
4 #include "callbacks.h"
5 #include "interface.h"
6 #include "support.h"
8 /*
9 void update_spin_button_ratio(GtkWidget* spinbutton) {
10 g_print("ratio change: %f\n", ratio);
11 on_ratio_w_spinbutton_value_changed(spinbutton, NULL);
12 }
18 void on_ratio_none_activate (GtkMenuItem* menuitem, gpointer user_data) {
19 ratio = 1;
20 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
21 }
24 void on_ratio_square_activate (GtkMenuItem* menuitem, gpointer user_data) {
25 ratio = 1;
26 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
27 }
30 void on_ratio_4x3_activate (GtkMenuItem* menuitem, gpointer user_data) {
31 ratio = 4.0/3.0;
32 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
33 }
36 void on_ratio_3x2_activate (GtkMenuItem* menuitem, gpointer user_data) {
37 ratio = 1.5;
38 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
39 }
42 void on_ratio_custom_activate (GtkMenuItem* menuitem, gpointer user_data) {
43 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"));
44 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
45 }
46 */
56 /*
57 static void ratio_optionmenu_changed_cb (GtkOptionMenu* optionmenu, gpointer unser_data) {
58 int idx = gtk_option_menu_get_history (optionmenu);
59 int w = 1, h = 1;
60 gboolean use_ratio = TRUE;
62 switch (idx) {
63 case GTH_CROP_RATIO_NONE:
64 use_ratio = FALSE;
65 break;
66 case GTH_CROP_RATIO_SQUARE:
67 w = h = 1;
68 break;
69 case GTH_CROP_RATIO_IMAGE:
70 w = lookup_widget(cropper_window, "image_width");
71 h = lookup_widget(cropper_window, "image_height");
72 break;
73 case GTH_CROP_RATIO_DISPLAY:
74 w = lookup_widget(cropper_window, "display_width");
75 h = lookup_widget(cropper_window, "display_height");
76 break;
77 case GTH_CROP_RATIO_4_3:
78 w = 4;
79 h = 3;
80 break;
81 case GTH_CROP_RATIO_4_6:
82 w = 4;
83 h = 6;
84 break;
85 case GTH_CROP_RATIO_CUSTOM:
86 default:
87 w = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (lookup_widget(cropper_window, "ratio_w_spinbutton")));
88 h = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (lookup_widget(cropper_window, "ratio_h_spinbutton")));
89 break;
90 }
92 gtk_widget_set_sensitive (lookup_widget(cropper_window, "custom_ratio_box"), idx == GTH_CROP_RATIO_CUSTOM);
93 set_spin_value (cropper_window, lookup_widget(cropper_window, "ratio_w_spinbutton"), w);
94 set_spin_value (cropper_window, lookup_widget(cropper_window, "ratio_h_spinbutton"), h);
96 gth_image_selector_set_ratio (GTH_IMAGE_SELECTOR (lookup_widget(cropper_window, "crop_image")), use_ratio, (double) w / h);
97 }
100 static void ratio_value_changed_cb (GtkSpinButton* spin, gpointer unser_data) {
101 int w, h;
103 w = gtk_spin_button_get_value_as_int (lookup_widget(cropper_window, "ratio_w_spinbutton"));
104 h = gtk_spin_button_get_value_as_int (lookup_widget(cropper_window, "ratio_h_spinbutton"));
106 gth_image_selector_set_ratio (GTH_IMAGE_SELECTOR (lookup_widget(cropper_window, "crop_image")), TRUE, (double) w / h);
107 }
110 static void ratio_swap_button_cb (GtkButton* button, gpointer unser_data) {
111 int w, h;
113 w = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_w_spinbutton"));
114 h = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_h_spinbutton"));
116 set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_w_spinbutton"), h);
117 set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_h_spinbutton"), w);
119 gth_image_selector_set_ratio(GTH_IMAGE_SELECTOR (lookup_widget(cropper_window, "crop_image")), TRUE, (double) h / w);
120 }
122 */
131 /*
132 void on_ratio_w_spinbutton_value_changed (GtkSpinButton* spinbutton, gpointer user_data) {
133 g_print("spinbutton W - ratio: %f\n", ratio);
134 gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_h_spinbutton"), gtk_spin_button_get_value(spinbutton) / ratio);
135 }
138 void on_ratio_w_spinbutton_change_value (GtkSpinButton* spinbutton, GtkScrollType scroll, gpointer user_data) {
139 }
142 void on_ratio_h_spinbutton_change_value (GtkSpinButton* spinbutton, GtkScrollType scroll, gpointer user_data) {
143 }
146 void on_ratio_h_spinbutton_value_changed (GtkSpinButton* spinbutton, gpointer user_data) {
147 g_print("spinbutton H - ratio: %f\n", ratio);
148 gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_w_spinbutton"), gtk_spin_button_get_value(spinbutton) * ratio);
150 }
153 void on_ratio_swap_button_clicked (GtkButton* button, gpointer user_data) {
155 ratio = 1.0 / ratio;
156 gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_w_spinbutton"), gtk_spin_button_get_value(lookup_widget(cropper_window, "ratio_h_spinbutton")));
157 gtk_spin_button_update(lookup_widget(cropper_window, "ratio_w_spinbutton"));
159 }
160 */
164 void on_crop_clicked(GtkButton* button, gpointer user_data) {
165 char crop_call[256];
167 sprintf(crop_call, "echo \"convert -crop %ix%i+%i+%i %s cropped_%s\"",
168 gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "crop_width_spinbutton")),
169 gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "crop_height_spinbutton")),
170 gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "crop_x_spinbutton")),
171 gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "crop_y_spinbutton")),
172 image_filename,
173 image_filename
174 );
175 system(crop_call);
176 gtk_main_quit();
177 }
180 void on_cropper_window_destroy (GtkObject* object, gpointer user_data) {
181 gtk_main_quit();
182 }