cropper

annotate callbacks.c @ 12:75a30c850ea0

more cosmetic changes
author meillo@marmaro.de
date Thu, 04 Mar 2010 14:23:30 +0100
parents 5e282003f0c1
children 13bc21684b8a
rev   line source
meillo@0 1 #include <gtk/gtk.h>
meillo@7 2 #include <gdk-pixbuf/gdk-pixbuf.h>
meillo@2 3 #include "main.h"
meillo@0 4 #include "callbacks.h"
meillo@0 5 #include "support.h"
meillo@0 6
meillo@7 7 int image_width;
meillo@7 8 int image_height;
meillo@10 9 float inc = 0.3;
meillo@11 10
meillo@11 11
meillo@4 12 /*
meillo@11 13 void
meillo@11 14 update_spin_button_ratio(GtkWidget* spinbutton)
meillo@11 15 {
meillo@3 16 g_print("ratio change: %f\n", ratio);
meillo@3 17 on_ratio_w_spinbutton_value_changed(spinbutton, NULL);
meillo@3 18 }
meillo@2 19
meillo@4 20
meillo@11 21 void
meillo@11 22 on_ratio_none_activate(GtkMenuItem* menuitem, gpointer user_data)
meillo@11 23 {
meillo@4 24 ratio = 1;
meillo@3 25 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
meillo@2 26 }
meillo@2 27
meillo@2 28
meillo@11 29 void
meillo@11 30 on_ratio_square_activate(GtkMenuItem* menuitem, gpointer user_data)
meillo@11 31 {
meillo@4 32 ratio = 1;
meillo@3 33 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
meillo@2 34 }
meillo@2 35
meillo@2 36
meillo@11 37 void
meillo@11 38 on_ratio_4x3_activate(GtkMenuItem* menuitem, gpointer user_data)
meillo@11 39 {
meillo@4 40 ratio = 4.0/3.0;
meillo@3 41 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
meillo@2 42 }
meillo@2 43
meillo@2 44
meillo@11 45 void
meillo@11 46 on_ratio_3x2_activate(GtkMenuItem* menuitem, gpointer user_data)
meillo@11 47 {
meillo@4 48 ratio = 1.5;
meillo@3 49 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
meillo@2 50 }
meillo@2 51
meillo@2 52
meillo@11 53 void
meillo@11 54 on_ratio_custom_activate(GtkMenuItem* menuitem, gpointer user_data)
meillo@11 55 {
meillo@11 56 ratio = gtk_spin_button_get_value(lookup_widget(cropper_window, "ratio_w_spinbutton"))
meillo@11 57 / gtk_spin_button_get_value(lookup_widget(cropper_window, "ratio_h_spinbutton"));
meillo@3 58 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
meillo@3 59 }
meillo@4 60 */
meillo@3 61
meillo@3 62
meillo@3 63
meillo@3 64
meillo@3 65
meillo@4 66
meillo@4 67
meillo@4 68
meillo@4 69
meillo@4 70 /*
meillo@11 71 static void
meillo@11 72 ratio_optionmenu_changed_cb(GtkOptionMenu* optionmenu, gpointer unser_data)
meillo@11 73 {
meillo@11 74 int idx = gtk_option_menu_get_history(optionmenu);
meillo@4 75 int w = 1, h = 1;
meillo@4 76 gboolean use_ratio = TRUE;
meillo@4 77
meillo@4 78 switch (idx) {
meillo@4 79 case GTH_CROP_RATIO_NONE:
meillo@4 80 use_ratio = FALSE;
meillo@4 81 break;
meillo@4 82 case GTH_CROP_RATIO_SQUARE:
meillo@4 83 w = h = 1;
meillo@4 84 break;
meillo@4 85 case GTH_CROP_RATIO_IMAGE:
meillo@4 86 w = lookup_widget(cropper_window, "image_width");
meillo@4 87 h = lookup_widget(cropper_window, "image_height");
meillo@4 88 break;
meillo@4 89 case GTH_CROP_RATIO_DISPLAY:
meillo@4 90 w = lookup_widget(cropper_window, "display_width");
meillo@4 91 h = lookup_widget(cropper_window, "display_height");
meillo@4 92 break;
meillo@4 93 case GTH_CROP_RATIO_4_3:
meillo@4 94 w = 4;
meillo@4 95 h = 3;
meillo@4 96 break;
meillo@4 97 case GTH_CROP_RATIO_4_6:
meillo@4 98 w = 4;
meillo@4 99 h = 6;
meillo@4 100 break;
meillo@4 101 case GTH_CROP_RATIO_CUSTOM:
meillo@4 102 default:
meillo@11 103 w = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(
meillo@11 104 lookup_widget(cropper_window, "ratio_w_spinbutton")));
meillo@11 105 h = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(
meillo@11 106 lookup_widget(cropper_window, "ratio_h_spinbutton")));
meillo@4 107 break;
meillo@4 108 }
meillo@4 109
meillo@11 110 gtk_widget_set_sensitive(lookup_widget(cropper_window, "custom_ratio_box"),
meillo@11 111 idx == GTH_CROP_RATIO_CUSTOM);
meillo@11 112 set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_w_spinbutton"), w);
meillo@11 113 set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_h_spinbutton"), h);
meillo@4 114
meillo@11 115 gth_image_selector_set_ratio(GTH_IMAGE_SELECTOR(lookup_widget(cropper_window, "crop_image")),
meillo@11 116 use_ratio, (double) w / h);
meillo@4 117 }
meillo@4 118
meillo@4 119
meillo@11 120 static void
meillo@11 121 ratio_value_changed_cb(GtkSpinButton* spin, gpointer unser_data)
meillo@11 122 {
meillo@4 123 int w, h;
meillo@4 124
meillo@11 125 w = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_w_spinbutton"));
meillo@11 126 h = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_h_spinbutton"));
meillo@4 127
meillo@11 128 gth_image_selector_set_ratio(GTH_IMAGE_SELECTOR(
meillo@11 129 lookup_widget(cropper_window, "crop_image")), TRUE, (double) w / h);
meillo@4 130 }
meillo@4 131
meillo@4 132
meillo@11 133 static void
meillo@11 134 ratio_swap_button_cb(GtkButton* button, gpointer unser_data)
meillo@11 135 {
meillo@4 136 int w, h;
meillo@4 137
meillo@4 138 w = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_w_spinbutton"));
meillo@4 139 h = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_h_spinbutton"));
meillo@4 140
meillo@4 141 set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_w_spinbutton"), h);
meillo@4 142 set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_h_spinbutton"), w);
meillo@4 143
meillo@11 144 gth_image_selector_set_ratio(GTH_IMAGE_SELECTOR(lookup_widget(cropper_window,
meillo@11 145 "crop_image")), TRUE, (double) h / w);
meillo@4 146 }
meillo@4 147
meillo@4 148 */
meillo@4 149
meillo@4 150
meillo@4 151
meillo@4 152
meillo@4 153
meillo@4 154
meillo@4 155
meillo@4 156
meillo@4 157 /*
meillo@11 158 void
meillo@11 159 on_ratio_w_spinbutton_value_changed(GtkSpinButton* spinbutton, gpointer user_data)
meillo@11 160 {
meillo@3 161 g_print("spinbutton W - ratio: %f\n", ratio);
meillo@11 162 gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_h_spinbutton"),
meillo@11 163 gtk_spin_button_get_value(spinbutton) / ratio);
meillo@3 164 }
meillo@3 165
meillo@3 166
meillo@11 167 void
meillo@11 168 on_ratio_w_spinbutton_change_value(GtkSpinButton* spinbutton, GtkScrollType scroll, gpointer user_data)
meillo@11 169 {
meillo@3 170 }
meillo@3 171
meillo@3 172
meillo@11 173 void
meillo@11 174 on_ratio_h_spinbutton_change_value(GtkSpinButton* spinbutton, GtkScrollType scroll, gpointer user_data)
meillo@11 175 {
meillo@3 176 }
meillo@3 177
meillo@3 178
meillo@11 179 void
meillo@11 180 on_ratio_h_spinbutton_value_changed(GtkSpinButton* spinbutton, gpointer user_data)
meillo@11 181 {
meillo@3 182 g_print("spinbutton H - ratio: %f\n", ratio);
meillo@11 183 gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_w_spinbutton"),
meillo@11 184 gtk_spin_button_get_value(spinbutton) * ratio);
meillo@0 185
meillo@0 186 }
meillo@0 187
meillo@0 188
meillo@11 189 void
meillo@11 190 on_ratio_swap_button_clicked(GtkButton* button, gpointer user_data)
meillo@11 191 {
meillo@3 192
meillo@3 193 ratio = 1.0 / ratio;
meillo@11 194 gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_w_spinbutton"),
meillo@11 195 gtk_spin_button_get_value(lookup_widget(cropper_window,
meillo@11 196 "ratio_h_spinbutton")));
meillo@3 197 gtk_spin_button_update(lookup_widget(cropper_window, "ratio_w_spinbutton"));
meillo@0 198
meillo@2 199 }
meillo@4 200 */
meillo@2 201
meillo@2 202
meillo@2 203
meillo@7 204 /* zoom */
meillo@11 205 void
meillo@11 206 set_zoom()
meillo@11 207 {
meillo@8 208 static GdkPixbuf* pixbuf_new;
meillo@8 209 g_object_unref(pixbuf_new);
meillo@8 210
meillo@10 211 pixbuf_new = gdk_pixbuf_scale_simple(image_buffer, image_width, image_height, GDK_INTERP_BILINEAR);
meillo@8 212 gtk_image_set_from_pixbuf((GtkImage*) lookup_widget(cropper_window, "image_area"), pixbuf_new);
meillo@8 213 }
meillo@8 214
meillo@11 215 void
meillo@11 216 on_zoom_in_button_clicked(GtkObject* object, gpointer user_data)
meillo@11 217 {
meillo@7 218 image_width *= 1 + inc;
meillo@7 219 image_height *= 1 + inc;
meillo@8 220 set_zoom();
meillo@7 221 }
meillo@7 222
meillo@11 223 void
meillo@11 224 on_zoom_out_button_clicked(GtkObject* object, gpointer user_data)
meillo@11 225 {
meillo@7 226 image_width *= 1 - inc;
meillo@7 227 image_height *= 1 - inc;
meillo@8 228 set_zoom();
meillo@7 229 }
meillo@7 230
meillo@11 231 void
meillo@11 232 on_zoom_100_button_clicked(GtkObject* object, gpointer user_data)
meillo@11 233 {
meillo@7 234 image_width = gdk_pixbuf_get_width(image_buffer);
meillo@7 235 image_height = gdk_pixbuf_get_height(image_buffer);
meillo@8 236 set_zoom();
meillo@7 237 }
meillo@7 238
meillo@11 239 void
meillo@11 240 on_zoom_fit_button_clicked(GtkObject* object, gpointer user_data)
meillo@11 241 {
meillo@8 242 int w, h;
meillo@8 243 GtkWidget* image_a;
meillo@8 244
meillo@8 245 image_a = (GtkWidget*) lookup_widget(cropper_window, "image_area");
meillo@11 246 gdk_drawable_get_size(image_a->window, &w, &h);
meillo@8 247
meillo@8 248 image_width = w - 200;
meillo@8 249 image_height = h - 150;
meillo@8 250 set_zoom();
meillo@7 251 }
meillo@7 252
meillo@7 253
meillo@7 254
meillo@7 255
meillo@7 256
meillo@7 257
meillo@7 258
meillo@11 259 void
meillo@11 260 on_crop_clicked(GtkButton* button, gpointer user_data)
meillo@11 261 {
meillo@4 262 char crop_call[256];
meillo@2 263
meillo@4 264 sprintf(crop_call, "echo \"convert -crop %ix%i+%i+%i %s cropped_%s\"",
meillo@11 265 gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window,
meillo@11 266 "crop_width_spinbutton")),
meillo@11 267 gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window,
meillo@11 268 "crop_height_spinbutton")),
meillo@11 269 gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window,
meillo@11 270 "crop_x_spinbutton")),
meillo@11 271 gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window,
meillo@11 272 "crop_y_spinbutton")),
meillo@4 273 image_filename,
meillo@4 274 image_filename
meillo@4 275 );
meillo@4 276 system(crop_call);
meillo@4 277 gtk_main_quit();
meillo@4 278 }
meillo@2 279
meillo@11 280
meillo@11 281 void
meillo@11 282 on_cropper_window_create(GtkObject* object, gpointer user_data)
meillo@11 283 {
meillo@7 284 image_width = gdk_pixbuf_get_width(image_buffer);
meillo@7 285 image_height = gdk_pixbuf_get_height(image_buffer);
meillo@10 286
meillo@10 287 /*
meillo@11 288 image_buffer = gdk_pixbuf_new_from_file(image_filename, NULL);
meillo@11 289 image_area = gtk_image_new_from_pixbuf(image_buffer);
meillo@10 290
meillo@10 291 int w, h;
meillo@10 292 GtkWidget* image_a;
meillo@10 293
meillo@10 294 image_a = (GtkWidget*) lookup_widget(cropper_window, "image_area");
meillo@11 295 gdk_drawable_get_size(image_a->window, &w, &h);
meillo@10 296
meillo@10 297 image_width = w - 200;
meillo@10 298 image_height = h - 150;
meillo@10 299 set_zoom();
meillo@10 300 */
meillo@7 301 }
meillo@0 302
meillo@11 303 void
meillo@11 304 on_cropper_window_destroy(GtkObject* object, gpointer user_data)
meillo@11 305 {
meillo@0 306 gtk_main_quit();
meillo@0 307 }
meillo@0 308