cropper

annotate 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
rev   line source
meillo@0 1 #include <gtk/gtk.h>
meillo@7 2 #include <gdk-pixbuf/gdk-pixbuf.h>
meillo@0 3
meillo@2 4 #include "main.h"
meillo@0 5 #include "callbacks.h"
meillo@0 6 #include "interface.h"
meillo@0 7 #include "support.h"
meillo@0 8
meillo@7 9 int image_width;
meillo@7 10 int image_height;
meillo@7 11 float inc = 0.1;
meillo@4 12 /*
meillo@3 13 void update_spin_button_ratio(GtkWidget* spinbutton) {
meillo@3 14 g_print("ratio change: %f\n", ratio);
meillo@3 15 on_ratio_w_spinbutton_value_changed(spinbutton, NULL);
meillo@3 16 }
meillo@2 17
meillo@4 18
meillo@4 19
meillo@4 20
meillo@4 21
meillo@2 22 void on_ratio_none_activate (GtkMenuItem* menuitem, gpointer user_data) {
meillo@4 23 ratio = 1;
meillo@3 24 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
meillo@2 25 }
meillo@2 26
meillo@2 27
meillo@2 28 void on_ratio_square_activate (GtkMenuItem* menuitem, gpointer user_data) {
meillo@4 29 ratio = 1;
meillo@3 30 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
meillo@2 31 }
meillo@2 32
meillo@2 33
meillo@2 34 void on_ratio_4x3_activate (GtkMenuItem* menuitem, gpointer user_data) {
meillo@4 35 ratio = 4.0/3.0;
meillo@3 36 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
meillo@2 37 }
meillo@2 38
meillo@2 39
meillo@2 40 void on_ratio_3x2_activate (GtkMenuItem* menuitem, gpointer user_data) {
meillo@4 41 ratio = 1.5;
meillo@3 42 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
meillo@2 43 }
meillo@2 44
meillo@2 45
meillo@2 46 void on_ratio_custom_activate (GtkMenuItem* menuitem, gpointer user_data) {
meillo@4 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"));
meillo@3 48 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton"));
meillo@3 49 }
meillo@4 50 */
meillo@3 51
meillo@3 52
meillo@3 53
meillo@3 54
meillo@3 55
meillo@4 56
meillo@4 57
meillo@4 58
meillo@4 59
meillo@4 60 /*
meillo@4 61 static void ratio_optionmenu_changed_cb (GtkOptionMenu* optionmenu, gpointer unser_data) {
meillo@4 62 int idx = gtk_option_menu_get_history (optionmenu);
meillo@4 63 int w = 1, h = 1;
meillo@4 64 gboolean use_ratio = TRUE;
meillo@4 65
meillo@4 66 switch (idx) {
meillo@4 67 case GTH_CROP_RATIO_NONE:
meillo@4 68 use_ratio = FALSE;
meillo@4 69 break;
meillo@4 70 case GTH_CROP_RATIO_SQUARE:
meillo@4 71 w = h = 1;
meillo@4 72 break;
meillo@4 73 case GTH_CROP_RATIO_IMAGE:
meillo@4 74 w = lookup_widget(cropper_window, "image_width");
meillo@4 75 h = lookup_widget(cropper_window, "image_height");
meillo@4 76 break;
meillo@4 77 case GTH_CROP_RATIO_DISPLAY:
meillo@4 78 w = lookup_widget(cropper_window, "display_width");
meillo@4 79 h = lookup_widget(cropper_window, "display_height");
meillo@4 80 break;
meillo@4 81 case GTH_CROP_RATIO_4_3:
meillo@4 82 w = 4;
meillo@4 83 h = 3;
meillo@4 84 break;
meillo@4 85 case GTH_CROP_RATIO_4_6:
meillo@4 86 w = 4;
meillo@4 87 h = 6;
meillo@4 88 break;
meillo@4 89 case GTH_CROP_RATIO_CUSTOM:
meillo@4 90 default:
meillo@4 91 w = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (lookup_widget(cropper_window, "ratio_w_spinbutton")));
meillo@4 92 h = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (lookup_widget(cropper_window, "ratio_h_spinbutton")));
meillo@4 93 break;
meillo@4 94 }
meillo@4 95
meillo@4 96 gtk_widget_set_sensitive (lookup_widget(cropper_window, "custom_ratio_box"), idx == GTH_CROP_RATIO_CUSTOM);
meillo@4 97 set_spin_value (cropper_window, lookup_widget(cropper_window, "ratio_w_spinbutton"), w);
meillo@4 98 set_spin_value (cropper_window, lookup_widget(cropper_window, "ratio_h_spinbutton"), h);
meillo@4 99
meillo@4 100 gth_image_selector_set_ratio (GTH_IMAGE_SELECTOR (lookup_widget(cropper_window, "crop_image")), use_ratio, (double) w / h);
meillo@4 101 }
meillo@4 102
meillo@4 103
meillo@4 104 static void ratio_value_changed_cb (GtkSpinButton* spin, gpointer unser_data) {
meillo@4 105 int w, h;
meillo@4 106
meillo@4 107 w = gtk_spin_button_get_value_as_int (lookup_widget(cropper_window, "ratio_w_spinbutton"));
meillo@4 108 h = gtk_spin_button_get_value_as_int (lookup_widget(cropper_window, "ratio_h_spinbutton"));
meillo@4 109
meillo@4 110 gth_image_selector_set_ratio (GTH_IMAGE_SELECTOR (lookup_widget(cropper_window, "crop_image")), TRUE, (double) w / h);
meillo@4 111 }
meillo@4 112
meillo@4 113
meillo@4 114 static void ratio_swap_button_cb (GtkButton* button, gpointer unser_data) {
meillo@4 115 int w, h;
meillo@4 116
meillo@4 117 w = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_w_spinbutton"));
meillo@4 118 h = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_h_spinbutton"));
meillo@4 119
meillo@4 120 set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_w_spinbutton"), h);
meillo@4 121 set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_h_spinbutton"), w);
meillo@4 122
meillo@4 123 gth_image_selector_set_ratio(GTH_IMAGE_SELECTOR (lookup_widget(cropper_window, "crop_image")), TRUE, (double) h / w);
meillo@4 124 }
meillo@4 125
meillo@4 126 */
meillo@4 127
meillo@4 128
meillo@4 129
meillo@4 130
meillo@4 131
meillo@4 132
meillo@4 133
meillo@4 134
meillo@4 135 /*
meillo@3 136 void on_ratio_w_spinbutton_value_changed (GtkSpinButton* spinbutton, gpointer user_data) {
meillo@3 137 g_print("spinbutton W - ratio: %f\n", ratio);
meillo@3 138 gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_h_spinbutton"), gtk_spin_button_get_value(spinbutton) / ratio);
meillo@3 139 }
meillo@3 140
meillo@3 141
meillo@3 142 void on_ratio_w_spinbutton_change_value (GtkSpinButton* spinbutton, GtkScrollType scroll, gpointer user_data) {
meillo@3 143 }
meillo@3 144
meillo@3 145
meillo@3 146 void on_ratio_h_spinbutton_change_value (GtkSpinButton* spinbutton, GtkScrollType scroll, gpointer user_data) {
meillo@3 147 }
meillo@3 148
meillo@3 149
meillo@3 150 void on_ratio_h_spinbutton_value_changed (GtkSpinButton* spinbutton, gpointer user_data) {
meillo@3 151 g_print("spinbutton H - ratio: %f\n", ratio);
meillo@3 152 gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_w_spinbutton"), gtk_spin_button_get_value(spinbutton) * ratio);
meillo@0 153
meillo@0 154 }
meillo@0 155
meillo@0 156
meillo@3 157 void on_ratio_swap_button_clicked (GtkButton* button, gpointer user_data) {
meillo@3 158
meillo@3 159 ratio = 1.0 / ratio;
meillo@3 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")));
meillo@3 161 gtk_spin_button_update(lookup_widget(cropper_window, "ratio_w_spinbutton"));
meillo@0 162
meillo@2 163 }
meillo@4 164 */
meillo@2 165
meillo@2 166
meillo@2 167
meillo@7 168 /* zoom */
meillo@7 169 void on_zoom_in_button_clicked(GtkObject* object, gpointer user_data) {
meillo@7 170 printf("zoom in clicked\n");
meillo@7 171 image_width *= 1 + inc;
meillo@7 172 image_height *= 1 + inc;
meillo@7 173 gtk_image_set_from_pixbuf(lookup_widget(cropper_window, "image_area"),
meillo@7 174 gdk_pixbuf_scale_simple(image_buffer, image_width, image_height, GDK_INTERP_BILINEAR));
meillo@7 175 }
meillo@7 176
meillo@7 177 void on_zoom_out_button_clicked(GtkObject* object, gpointer user_data) {
meillo@7 178 printf("zoom out clicked\n");
meillo@7 179 image_width *= 1 - inc;
meillo@7 180 image_height *= 1 - inc;
meillo@7 181 gtk_image_set_from_pixbuf(lookup_widget(cropper_window, "image_area"),
meillo@7 182 gdk_pixbuf_scale_simple(image_buffer, image_width, image_height, GDK_INTERP_BILINEAR));
meillo@7 183 }
meillo@7 184
meillo@7 185 void on_zoom_100_button_clicked(GtkObject* object, gpointer user_data) {
meillo@7 186 printf("zoom 100 clicked\n");
meillo@7 187 image_width = gdk_pixbuf_get_width(image_buffer);
meillo@7 188 image_height = gdk_pixbuf_get_height(image_buffer);
meillo@7 189 gtk_image_set_from_pixbuf(lookup_widget(cropper_window, "image_area"),
meillo@7 190 gdk_pixbuf_scale_simple(image_buffer, image_width, image_height, GDK_INTERP_BILINEAR));
meillo@7 191 }
meillo@7 192
meillo@7 193 void on_zoom_fit_button_clicked(GtkObject* object, gpointer user_data) {
meillo@7 194 printf("zoom fit clicked\n");
meillo@7 195 image_width = gdk_pixbuf_get_width(image_buffer) + 200; /* FIXME */
meillo@7 196 image_height = gdk_pixbuf_get_height(image_buffer) + 200; /* FIXME */
meillo@7 197 gtk_image_set_from_pixbuf(lookup_widget(cropper_window, "image_area"),
meillo@7 198 gdk_pixbuf_scale_simple(image_buffer, image_width, image_height, GDK_INTERP_BILINEAR));
meillo@7 199 }
meillo@7 200
meillo@7 201
meillo@7 202
meillo@7 203
meillo@7 204
meillo@7 205
meillo@7 206
meillo@4 207 void on_crop_clicked(GtkButton* button, gpointer user_data) {
meillo@4 208 char crop_call[256];
meillo@2 209
meillo@4 210 sprintf(crop_call, "echo \"convert -crop %ix%i+%i+%i %s cropped_%s\"",
meillo@4 211 gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "crop_width_spinbutton")),
meillo@4 212 gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "crop_height_spinbutton")),
meillo@4 213 gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "crop_x_spinbutton")),
meillo@4 214 gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "crop_y_spinbutton")),
meillo@4 215 image_filename,
meillo@4 216 image_filename
meillo@4 217 );
meillo@4 218 system(crop_call);
meillo@4 219 gtk_main_quit();
meillo@4 220 }
meillo@2 221
meillo@7 222 void on_cropper_window_create (GtkObject* object, gpointer user_data) {
meillo@7 223 image_width = gdk_pixbuf_get_width(image_buffer);
meillo@7 224 image_height = gdk_pixbuf_get_height(image_buffer);
meillo@7 225 }
meillo@0 226
meillo@1 227 void on_cropper_window_destroy (GtkObject* object, gpointer user_data) {
meillo@0 228 gtk_main_quit();
meillo@0 229 }
meillo@0 230