cropper

annotate callbacks.c @ 9:7e1cf00de1df

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