cropper
changeset 4:2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
author | meillo@marmaro.de |
---|---|
date | Fri, 07 Dec 2007 17:40:08 +0100 |
parents | 6aaba3a61563 |
children | 61e5a1727231 |
files | Makefile callbacks.c callbacks.h interface.c main.c main.h |
diffstat | 6 files changed, 271 insertions(+), 35 deletions(-) [+] |
line diff
1.1 --- a/Makefile Wed Dec 05 00:08:39 2007 +0100 1.2 +++ b/Makefile Fri Dec 07 17:40:08 2007 +0100 1.3 @@ -19,8 +19,8 @@ 1.4 1.5 1.6 clean: 1.7 - rm *.o 1.8 - rm ${PACKAGE} 1.9 + rm -f *.o 1.10 + rm -f ${PACKAGE} 1.11 1.12 1.13 # end of file
2.1 --- a/callbacks.c Wed Dec 05 00:08:39 2007 +0100 2.2 +++ b/callbacks.c Fri Dec 07 17:40:08 2007 +0100 2.3 @@ -5,49 +5,131 @@ 2.4 #include "interface.h" 2.5 #include "support.h" 2.6 2.7 - 2.8 +/* 2.9 void update_spin_button_ratio(GtkWidget* spinbutton) { 2.10 g_print("ratio change: %f\n", ratio); 2.11 - /*gtk_spin_button_set_value((spinbutton), gtk_spin_button_get_value(spinbutton));*/ 2.12 - /*gtk_spin_button_update(spinbutton);*/ 2.13 on_ratio_w_spinbutton_value_changed(spinbutton, NULL); 2.14 } 2.15 2.16 + 2.17 + 2.18 + 2.19 + 2.20 void on_ratio_none_activate (GtkMenuItem* menuitem, gpointer user_data) { 2.21 - ratio = (double) 1; 2.22 + ratio = 1; 2.23 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton")); 2.24 } 2.25 2.26 2.27 void on_ratio_square_activate (GtkMenuItem* menuitem, gpointer user_data) { 2.28 - ratio = (double) 1; 2.29 + ratio = 1; 2.30 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton")); 2.31 } 2.32 2.33 2.34 void on_ratio_4x3_activate (GtkMenuItem* menuitem, gpointer user_data) { 2.35 - ratio = (double) 4/3; 2.36 + ratio = 4.0/3.0; 2.37 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton")); 2.38 } 2.39 2.40 2.41 void on_ratio_3x2_activate (GtkMenuItem* menuitem, gpointer user_data) { 2.42 - ratio = (double) 3/2; 2.43 + ratio = 1.5; 2.44 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton")); 2.45 } 2.46 2.47 2.48 void on_ratio_custom_activate (GtkMenuItem* menuitem, gpointer user_data) { 2.49 - ratio = (double) gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_w_spinbutton")) / gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_h_spinbutton")); 2.50 + 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")); 2.51 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton")); 2.52 } 2.53 +*/ 2.54 2.55 2.56 2.57 2.58 2.59 + 2.60 + 2.61 + 2.62 + 2.63 +/* 2.64 +static void ratio_optionmenu_changed_cb (GtkOptionMenu* optionmenu, gpointer unser_data) { 2.65 + int idx = gtk_option_menu_get_history (optionmenu); 2.66 + int w = 1, h = 1; 2.67 + gboolean use_ratio = TRUE; 2.68 + 2.69 + switch (idx) { 2.70 + case GTH_CROP_RATIO_NONE: 2.71 + use_ratio = FALSE; 2.72 + break; 2.73 + case GTH_CROP_RATIO_SQUARE: 2.74 + w = h = 1; 2.75 + break; 2.76 + case GTH_CROP_RATIO_IMAGE: 2.77 + w = lookup_widget(cropper_window, "image_width"); 2.78 + h = lookup_widget(cropper_window, "image_height"); 2.79 + break; 2.80 + case GTH_CROP_RATIO_DISPLAY: 2.81 + w = lookup_widget(cropper_window, "display_width"); 2.82 + h = lookup_widget(cropper_window, "display_height"); 2.83 + break; 2.84 + case GTH_CROP_RATIO_4_3: 2.85 + w = 4; 2.86 + h = 3; 2.87 + break; 2.88 + case GTH_CROP_RATIO_4_6: 2.89 + w = 4; 2.90 + h = 6; 2.91 + break; 2.92 + case GTH_CROP_RATIO_CUSTOM: 2.93 + default: 2.94 + w = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (lookup_widget(cropper_window, "ratio_w_spinbutton"))); 2.95 + h = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (lookup_widget(cropper_window, "ratio_h_spinbutton"))); 2.96 + break; 2.97 + } 2.98 + 2.99 + gtk_widget_set_sensitive (lookup_widget(cropper_window, "custom_ratio_box"), idx == GTH_CROP_RATIO_CUSTOM); 2.100 + set_spin_value (cropper_window, lookup_widget(cropper_window, "ratio_w_spinbutton"), w); 2.101 + set_spin_value (cropper_window, lookup_widget(cropper_window, "ratio_h_spinbutton"), h); 2.102 + 2.103 + gth_image_selector_set_ratio (GTH_IMAGE_SELECTOR (lookup_widget(cropper_window, "crop_image")), use_ratio, (double) w / h); 2.104 +} 2.105 + 2.106 + 2.107 +static void ratio_value_changed_cb (GtkSpinButton* spin, gpointer unser_data) { 2.108 + int w, h; 2.109 + 2.110 + w = gtk_spin_button_get_value_as_int (lookup_widget(cropper_window, "ratio_w_spinbutton")); 2.111 + h = gtk_spin_button_get_value_as_int (lookup_widget(cropper_window, "ratio_h_spinbutton")); 2.112 + 2.113 + gth_image_selector_set_ratio (GTH_IMAGE_SELECTOR (lookup_widget(cropper_window, "crop_image")), TRUE, (double) w / h); 2.114 +} 2.115 + 2.116 + 2.117 +static void ratio_swap_button_cb (GtkButton* button, gpointer unser_data) { 2.118 + int w, h; 2.119 + 2.120 + w = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_w_spinbutton")); 2.121 + h = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_h_spinbutton")); 2.122 + 2.123 + set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_w_spinbutton"), h); 2.124 + set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_h_spinbutton"), w); 2.125 + 2.126 + gth_image_selector_set_ratio(GTH_IMAGE_SELECTOR (lookup_widget(cropper_window, "crop_image")), TRUE, (double) h / w); 2.127 +} 2.128 + 2.129 +*/ 2.130 + 2.131 + 2.132 + 2.133 + 2.134 + 2.135 + 2.136 + 2.137 + 2.138 +/* 2.139 void on_ratio_w_spinbutton_value_changed (GtkSpinButton* spinbutton, gpointer user_data) { 2.140 - /*gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_h_spinbutton"), gtk_spin_button_get_value(spinbutton) / ratio);*/ 2.141 g_print("spinbutton W - ratio: %f\n", ratio); 2.142 gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_h_spinbutton"), gtk_spin_button_get_value(spinbutton) / ratio); 2.143 } 2.144 @@ -62,7 +144,6 @@ 2.145 2.146 2.147 void on_ratio_h_spinbutton_value_changed (GtkSpinButton* spinbutton, gpointer user_data) { 2.148 - /*gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_w_spinbutton"), gtk_spin_button_get_value(spinbutton) * ratio);*/ 2.149 g_print("spinbutton H - ratio: %f\n", ratio); 2.150 gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_w_spinbutton"), gtk_spin_button_get_value(spinbutton) * ratio); 2.151 2.152 @@ -76,15 +157,25 @@ 2.153 gtk_spin_button_update(lookup_widget(cropper_window, "ratio_w_spinbutton")); 2.154 2.155 } 2.156 +*/ 2.157 2.158 2.159 2.160 +void on_crop_clicked(GtkButton* button, gpointer user_data) { 2.161 + char crop_call[256]; 2.162 2.163 + sprintf(crop_call, "echo \"convert -crop %ix%i+%i+%i %s cropped_%s\"", 2.164 + gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "crop_width_spinbutton")), 2.165 + gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "crop_height_spinbutton")), 2.166 + gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "crop_x_spinbutton")), 2.167 + gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "crop_y_spinbutton")), 2.168 + image_filename, 2.169 + image_filename 2.170 + ); 2.171 + system(crop_call); 2.172 + gtk_main_quit(); 2.173 +} 2.174 2.175 -gboolean on_cropper_window_delete_event (GtkWidget* widget, GdkEvent *event, gpointer user_data) { 2.176 - /* g_print("thanks for using the program - visit http://prog.marmaro.de\n"); */ 2.177 - return FALSE; 2.178 -} 2.179 2.180 void on_cropper_window_destroy (GtkObject* object, gpointer user_data) { 2.181 gtk_main_quit();
3.1 --- a/callbacks.h Wed Dec 05 00:08:39 2007 +0100 3.2 +++ b/callbacks.h Fri Dec 07 17:40:08 2007 +0100 3.3 @@ -1,19 +1,32 @@ 3.4 +#ifndef _CALLBACKS_H_ 3.5 +#define _CALLBACKS_H_ 3.6 + 3.7 #include <gtk/gtk.h> 3.8 3.9 double ratio; 3.10 3.11 +/* 3.12 void on_ratio_none_activate(GtkMenuItem* menuitem, gpointer user_data); 3.13 void on_ratio_square_activate(GtkMenuItem* menuitem, gpointer user_data); 3.14 void on_ratio_4x3_activate(GtkMenuItem* menuitem, gpointer user_data); 3.15 void on_ratio_3x2_activate(GtkMenuItem* menuitem, gpointer user_data); 3.16 void on_ratio_custom_activate(GtkMenuItem* menuitem, gpointer user_data); 3.17 3.18 +static void ratio_optionmenu_changed_cb (GtkOptionMenu* optionmenu, gpointer unser_data); 3.19 +static void ratio_value_changed_cb (GtkSpinButton* spin, gpointer unser_data); 3.20 +static void ratio_swap_button_cb (GtkButton* button, gpointer unser_data); 3.21 + 3.22 void on_ratio_w_spinbutton_value_changed(GtkSpinButton* spinbutton, gpointer user_data); 3.23 void on_ratio_w_spinbutton_change_value(GtkSpinButton* spinbutton, GtkScrollType scroll, gpointer user_data); 3.24 void on_ratio_h_spinbutton_change_value(GtkSpinButton* spinbutton, GtkScrollType scroll, gpointer user_data); 3.25 void on_ratio_h_spinbutton_value_changed(GtkSpinButton* spinbutton, gpointer user_data); 3.26 void on_ratio_swap_button_clicked(GtkButton* button, gpointer user_data); 3.27 +*/ 3.28 + 3.29 +void on_crop_clicked(GtkButton* button, gpointer user_data); 3.30 3.31 void on_cropper_window_destroy(GtkObject* object, gpointer user_data); 3.32 -gboolean on_cropper_window_delete_event(GtkWidget* widget, GdkEvent *event, gpointer user_data); 3.33 +/*gboolean on_cropper_window_delete_event(GtkWidget* widget, GdkEvent *event, gpointer user_data);*/ 3.34 3.35 + 3.36 +#endif
4.1 --- a/interface.c Wed Dec 05 00:08:39 2007 +0100 4.2 +++ b/interface.c Fri Dec 07 17:40:08 2007 +0100 4.3 @@ -81,6 +81,13 @@ 4.4 GtkWidget *image3; 4.5 GtkWidget *crop_zoom_fit_button; 4.6 GtkWidget *image1; 4.7 + GtkWidget *dialog_action_area1; 4.8 + GtkWidget *crop_okbutton; 4.9 + GtkWidget *alignment1; 4.10 + GtkWidget *hbox11; 4.11 + GtkWidget *crop_image; 4.12 + GtkWidget *label12; 4.13 + 4.14 4.15 cropper_window = gtk_window_new (GTK_WINDOW_TOPLEVEL); 4.16 gtk_widget_set_name (cropper_window, "cropper_window"); 4.17 @@ -400,48 +407,148 @@ 4.18 4.19 4.20 4.21 +/* 4.22 + okay_box = gtk_hbox_new (FALSE, 0); 4.23 + gtk_widget_set_name (okay_box, "okay_box"); 4.24 + gtk_widget_show (okay_box); 4.25 + gtk_box_pack_end (GTK_BOX (hbox16), okay_box, FALSE, TRUE, 0); 4.26 +*/ 4.27 4.28 + crop_okbutton = gtk_button_new (); 4.29 + gtk_widget_set_name (crop_okbutton, "crop_okbutton"); 4.30 + gtk_widget_show (crop_okbutton); 4.31 + gtk_box_pack_end (GTK_BOX (dialog_vbox1), crop_okbutton, FALSE, FALSE, 0); 4.32 + GTK_WIDGET_SET_FLAGS (crop_okbutton, GTK_CAN_DEFAULT); 4.33 4.34 + alignment1 = gtk_alignment_new (0.5, 0.5, 0, 0); 4.35 + gtk_widget_set_name (alignment1, "alignment1"); 4.36 + gtk_widget_show (alignment1); 4.37 + gtk_container_add (GTK_CONTAINER (crop_okbutton), alignment1); 4.38 4.39 - g_signal_connect ((gpointer) cropper_window, "delete_event", 4.40 - G_CALLBACK (on_cropper_window_delete_event), 4.41 - NULL); 4.42 - g_signal_connect ((gpointer) cropper_window, "destroy", 4.43 + hbox11 = gtk_hbox_new (FALSE, 2); 4.44 + gtk_widget_set_name (hbox11, "hbox11"); 4.45 + gtk_widget_show (hbox11); 4.46 + gtk_container_add (GTK_CONTAINER (alignment1), hbox11); 4.47 + 4.48 + crop_image = gtk_image_new_from_stock ("gtk-ok", GTK_ICON_SIZE_BUTTON); 4.49 + gtk_widget_set_name (crop_image, "crop_image"); 4.50 + gtk_widget_show (crop_image); 4.51 + gtk_box_pack_start (GTK_BOX (hbox11), crop_image, FALSE, FALSE, 0); 4.52 + 4.53 + label12 = gtk_label_new_with_mnemonic ("_Crop"); 4.54 + gtk_widget_set_name (label12, "label12"); 4.55 + gtk_widget_show (label12); 4.56 + gtk_box_pack_start (GTK_BOX (hbox11), label12, FALSE, FALSE, 0); 4.57 + 4.58 + 4.59 + 4.60 + 4.61 + 4.62 +/* destroy */ 4.63 + g_signal_connect (G_OBJECT (cropper_window), "destroy", 4.64 G_CALLBACK (on_cropper_window_destroy), 4.65 NULL); 4.66 4.67 - g_signal_connect ((gpointer) ratio_w_spinbutton, "value_changed", 4.68 + 4.69 +/* crop */ 4.70 + g_signal_connect (G_OBJECT (crop_okbutton), "clicked", 4.71 + G_CALLBACK (on_crop_clicked), 4.72 + NULL); 4.73 + 4.74 + 4.75 + 4.76 +/* aspect ratio */ 4.77 +/* 4.78 + g_signal_connect (G_OBJECT (ratio_w_spinbutton), "value_changed", 4.79 G_CALLBACK (on_ratio_w_spinbutton_value_changed), 4.80 NULL); 4.81 - g_signal_connect ((gpointer) ratio_w_spinbutton, "change_value", 4.82 - G_CALLBACK (on_ratio_w_spinbutton_change_value), 4.83 - NULL); 4.84 - g_signal_connect ((gpointer) ratio_swap_button, "clicked", 4.85 + g_signal_connect (G_OBJECT (ratio_swap_button), "clicked", 4.86 G_CALLBACK (on_ratio_swap_button_clicked), 4.87 NULL); 4.88 - g_signal_connect ((gpointer) ratio_h_spinbutton, "change_value", 4.89 - G_CALLBACK (on_ratio_h_spinbutton_change_value), 4.90 - NULL); 4.91 - g_signal_connect ((gpointer) ratio_h_spinbutton, "value_changed", 4.92 + g_signal_connect (G_OBJECT (ratio_h_spinbutton), "value_changed", 4.93 G_CALLBACK (on_ratio_h_spinbutton_value_changed), 4.94 NULL); 4.95 4.96 - g_signal_connect ((gpointer) ratio_none, "activate", 4.97 + g_signal_connect (G_OBJECT (ratio_none), "activate", 4.98 G_CALLBACK (on_ratio_none_activate), 4.99 NULL); 4.100 - g_signal_connect ((gpointer) ratio_square, "activate", 4.101 + g_signal_connect (G_OBJECT (ratio_square), "activate", 4.102 G_CALLBACK (on_ratio_square_activate), 4.103 NULL); 4.104 - g_signal_connect ((gpointer) ratio_4x3, "activate", 4.105 + g_signal_connect (G_OBJECT (ratio_4x3), "activate", 4.106 G_CALLBACK (on_ratio_4x3_activate), 4.107 NULL); 4.108 - g_signal_connect ((gpointer) ratio_3x2, "activate", 4.109 + g_signal_connect (G_OBJECT (ratio_3x2), "activate", 4.110 G_CALLBACK (on_ratio_3x2_activate), 4.111 NULL); 4.112 - g_signal_connect ((gpointer) ratio_custom, "activate", 4.113 + g_signal_connect (G_OBJECT (ratio_custom), "activate", 4.114 G_CALLBACK (on_ratio_custom_activate), 4.115 NULL); 4.116 4.117 +g_signal_connect (G_OBJECT (lookup_widget(cropper_window, "ratio_optionmenu")), "changed", 4.118 + G_CALLBACK (ratio_optionmenu_changed_cb), 4.119 + NULL); 4.120 +g_signal_connect (G_OBJECT (lookup_widget(cropper_window, "ratio_w_spinbutton")), "value_changed", 4.121 + G_CALLBACK (ratio_value_changed_cb), 4.122 + NULL); 4.123 +g_signal_connect (G_OBJECT (lookup_widget(cropper_window, "ratio_h_spinbutton")), "value_changed", 4.124 + G_CALLBACK (ratio_value_changed_cb), 4.125 + NULL); 4.126 +g_signal_connect (G_OBJECT (lookup_widget(cropper_window, "ratio_swap_button")), "clicked", 4.127 + G_CALLBACK (ratio_swap_button_cb), 4.128 + NULL); 4.129 +*/ 4.130 + 4.131 + 4.132 +/* selection */ 4.133 +/* 4.134 +g_signal_connect (G_OBJECT (lookup_widget(cropper_window, "crop_x_spinbutton")), "value_changed", 4.135 + G_CALLBACK (selection_x_value_changed_cb), 4.136 + data); 4.137 +g_signal_connect (G_OBJECT (lookup_widget(cropper_window, "crop_y_spinbutton")), "value_changed", 4.138 + G_CALLBACK (selection_y_value_changed_cb), 4.139 + data); 4.140 +g_signal_connect (G_OBJECT (lookup_widget(cropper_window, "crop_width_spinbutton")), "value_changed", 4.141 + G_CALLBACK (selection_width_value_changed_cb), 4.142 + data); 4.143 +g_signal_connect (G_OBJECT (lookup_widget(cropper_window, "crop_height_spinbutton")), "value_changed", 4.144 + G_CALLBACK (selection_height_value_changed_cb), 4.145 + data); 4.146 +g_signal_connect (G_OBJECT (lookup_widget(cropper_window, "crop_image")), "selection_changed", 4.147 + G_CALLBACK (selection_changed_cb), 4.148 + data); 4.149 +*/ 4.150 + 4.151 + 4.152 +/* zoom */ 4.153 +/* 4.154 +g_signal_connect (G_OBJECT (zoom_in_button), "clicked", 4.155 + G_CALLBACK (zoom_in_button_clicked_cb), 4.156 + data); 4.157 +g_signal_connect (G_OBJECT (zoom_out_button), "clicked", 4.158 + G_CALLBACK (zoom_out_button_clicked_cb), 4.159 + data); 4.160 +g_signal_connect (G_OBJECT (zoom_100_button), "clicked", 4.161 + G_CALLBACK (zoom_100_button_clicked_cb), 4.162 + data); 4.163 +g_signal_connect (G_OBJECT (zoom_fit_button), "clicked", 4.164 + G_CALLBACK (zoom_fit_button_clicked_cb), 4.165 + data); 4.166 +*/ 4.167 + 4.168 + 4.169 + 4.170 + 4.171 + 4.172 + 4.173 + 4.174 + 4.175 + 4.176 + 4.177 + 4.178 + 4.179 + 4.180 + 4.181 4.182 /* Store pointers to all widgets, for use by lookup_widget(). */ 4.183 GLADE_HOOKUP_OBJECT_NO_REF (cropper_window, cropper_window, "cropper_window"); 4.184 @@ -498,6 +605,13 @@ 4.185 GLADE_HOOKUP_OBJECT (cropper_window, image3, "image3"); 4.186 GLADE_HOOKUP_OBJECT (cropper_window, crop_zoom_fit_button, "crop_zoom_fit_button"); 4.187 GLADE_HOOKUP_OBJECT (cropper_window, image1, "image1"); 4.188 + /*GLADE_HOOKUP_OBJECT_NO_REF (cropper_window, dialog_action_area1, "dialog_action_area1"); */ 4.189 + GLADE_HOOKUP_OBJECT (cropper_window, crop_okbutton, "crop_okbutton"); 4.190 + GLADE_HOOKUP_OBJECT (cropper_window, alignment1, "alignment1"); 4.191 + GLADE_HOOKUP_OBJECT (cropper_window, hbox11, "hbox11"); 4.192 + GLADE_HOOKUP_OBJECT (cropper_window, crop_image, "crop_image"); 4.193 + GLADE_HOOKUP_OBJECT (cropper_window, label12, "label12"); 4.194 + 4.195 4.196 return cropper_window; 4.197 }
5.1 --- a/main.c Wed Dec 05 00:08:39 2007 +0100 5.2 +++ b/main.c Fri Dec 07 17:40:08 2007 +0100 5.3 @@ -7,6 +7,23 @@ 5.4 5.5 int main (int argc, char *argv[]) { 5.6 5.7 + /* printf("argc: %i\nargv[0]: %s\nargv[1]: %s\nargv[2]: %s\n", argc, argv[0], argv[1], argv[2]); */ 5.8 + 5.9 + /* commandline option handling */ 5.10 + if (argc == 2) { 5.11 + if (strcmp(argv[1], "--version") == 0) { 5.12 + g_print("cropper - a crop frontend for convert\nversion 0.1\nhttp://prog.marmaro.de\n"); 5.13 + return(0); 5.14 + } else { 5.15 + image_filename = argv[1]; 5.16 + } 5.17 + } else { 5.18 + g_print("usage: %s <image>\n", argv[0]); 5.19 + return(1); 5.20 + } 5.21 + 5.22 + 5.23 + 5.24 gtk_set_locale (); 5.25 gtk_init (&argc, &argv); 5.26