# HG changeset patch # User meillo@marmaro.de # Date 1267727652 -3600 # Node ID 4453456abad1bd75a8d5357579a7d985ee38dd74 # Parent 88b8856fccf59f912c0175d2611675a4bfc192b0 gathered all code in one file diff -r 88b8856fccf5 -r 4453456abad1 Makefile --- a/Makefile Thu Mar 04 19:20:41 2010 +0100 +++ b/Makefile Thu Mar 04 19:34:12 2010 +0100 @@ -1,33 +1,16 @@ # makefile for cropper -NAME = cropper - -SRC = interface.c callbacks.c main.c -DEP = main.h -OBJ = ${SRC:.c=.o} - CC = gcc CFLAGS = `pkg-config --cflags gtk+-2.0` LDFLAGS = `pkg-config --libs --cflags gtk+-2.0` - -all: ${NAME} - -${NAME}: ${OBJ} ${DEP} - ${CC} -o ${NAME} ${OBJ} ${LDFLAGS} - -.c.o: - ${CC} ${CFLAGS} -c $< - - -interface.o: main.h -callbacks.o: main.h -main.o: main.h +cropper: main.o + ${CC} -o cropper main.o ${LDFLAGS} clean: rm -f *.o realclean: clean - rm -f ${NAME} + rm -f cropper diff -r 88b8856fccf5 -r 4453456abad1 callbacks.c --- a/callbacks.c Thu Mar 04 19:20:41 2010 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,347 +0,0 @@ -#include -#include -#include -#include "main.h" - -int image_width; -int image_height; -float inc = 0.3; -float zoom = 1.0; - - -/* -void -update_spin_button_ratio(GtkWidget* spinbutton) -{ - g_print("ratio change: %f\n", ratio); - on_ratio_w_spinbutton_value_changed(spinbutton, NULL); -} - - -void -on_ratio_none_activate(GtkMenuItem* menuitem, gpointer user_data) -{ - ratio = 1; - update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton")); -} - - -void -on_ratio_square_activate(GtkMenuItem* menuitem, gpointer user_data) -{ - ratio = 1; - update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton")); -} - - -void -on_ratio_4x3_activate(GtkMenuItem* menuitem, gpointer user_data) -{ - ratio = 4.0/3.0; - update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton")); -} - - -void -on_ratio_3x2_activate(GtkMenuItem* menuitem, gpointer user_data) -{ - ratio = 1.5; - update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton")); -} - - -void -on_ratio_custom_activate(GtkMenuItem* menuitem, gpointer user_data) -{ - 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")); - update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton")); -} -*/ - - - - - - - - - -/* -static void -ratio_optionmenu_changed_cb(GtkOptionMenu* optionmenu, gpointer unser_data) -{ - int idx = gtk_option_menu_get_history(optionmenu); - int w = 1, h = 1; - gboolean use_ratio = TRUE; - - switch (idx) { - case GTH_CROP_RATIO_NONE: - use_ratio = FALSE; - break; - case GTH_CROP_RATIO_SQUARE: - w = h = 1; - break; - case GTH_CROP_RATIO_IMAGE: - w = lookup_widget(cropper_window, "image_width"); - h = lookup_widget(cropper_window, "image_height"); - break; - case GTH_CROP_RATIO_DISPLAY: - w = lookup_widget(cropper_window, "display_width"); - h = lookup_widget(cropper_window, "display_height"); - break; - case GTH_CROP_RATIO_4_3: - w = 4; - h = 3; - break; - case GTH_CROP_RATIO_4_6: - w = 4; - h = 6; - break; - case GTH_CROP_RATIO_CUSTOM: - default: - w = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON( - lookup_widget(cropper_window, "ratio_w_spinbutton"))); - h = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON( - lookup_widget(cropper_window, "ratio_h_spinbutton"))); - break; - } - - gtk_widget_set_sensitive(lookup_widget(cropper_window, "custom_ratio_box"), - idx == GTH_CROP_RATIO_CUSTOM); - set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_w_spinbutton"), w); - set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_h_spinbutton"), h); - - gth_image_selector_set_ratio(GTH_IMAGE_SELECTOR(lookup_widget(cropper_window, "crop_image")), - use_ratio, (double) w / h); -} - - -static void -ratio_value_changed_cb(GtkSpinButton* spin, gpointer unser_data) -{ - int w, h; - - w = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_w_spinbutton")); - h = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_h_spinbutton")); - - gth_image_selector_set_ratio(GTH_IMAGE_SELECTOR( - lookup_widget(cropper_window, "crop_image")), TRUE, (double) w / h); -} - - -static void -ratio_swap_button_cb(GtkButton* button, gpointer unser_data) -{ - int w, h; - - w = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_w_spinbutton")); - h = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_h_spinbutton")); - - set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_w_spinbutton"), h); - set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_h_spinbutton"), w); - - gth_image_selector_set_ratio(GTH_IMAGE_SELECTOR(lookup_widget(cropper_window, - "crop_image")), TRUE, (double) h / w); -} - - - - - - - - -void -on_ratio_w_spinbutton_value_changed(GtkSpinButton* spinbutton, gpointer user_data) -{ - g_print("spinbutton W - ratio: %f\n", ratio); - gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_h_spinbutton"), - gtk_spin_button_get_value(spinbutton) / ratio); -} - - -void -on_ratio_w_spinbutton_change_value(GtkSpinButton* spinbutton, GtkScrollType scroll, gpointer user_data) -{ -} - - -void -on_ratio_h_spinbutton_change_value(GtkSpinButton* spinbutton, GtkScrollType scroll, gpointer user_data) -{ -} - - -void -on_ratio_h_spinbutton_value_changed(GtkSpinButton* spinbutton, gpointer user_data) -{ - g_print("spinbutton H - ratio: %f\n", ratio); - gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_w_spinbutton"), - gtk_spin_button_get_value(spinbutton) * ratio); - -} - - -void -on_ratio_swap_button_clicked(GtkButton* button, gpointer user_data) -{ - - ratio = 1.0 / ratio; - gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_w_spinbutton"), - gtk_spin_button_get_value(lookup_widget(cropper_window, - "ratio_h_spinbutton"))); - gtk_spin_button_update(lookup_widget(cropper_window, "ratio_w_spinbutton")); - -} -*/ - - -void -update_title(char* zoom) -{ - char title[128]; - snprintf(title, 128, "cropper (%s) %dx%d+%d+%d", zoom, w, h, x, y); - gtk_window_set_title(GTK_WINDOW(cropper_window), title); -} - - -/* zoom */ -void -set_zoom() -{ - static GdkPixbuf* pixbuf_new; - g_object_unref(pixbuf_new); - - pixbuf_new = gdk_pixbuf_scale_simple(image_buffer, image_width*zoom, image_height*zoom, - GDK_INTERP_BILINEAR); - gtk_image_set_from_pixbuf((GtkImage*) lookup_widget(cropper_window, "image_area"), pixbuf_new); -} - -void -on_zoom_in_button_clicked(GtkObject* object, gpointer user_data) -{ - zoom *= 1 + inc; - set_zoom(); -} - -void -on_zoom_out_button_clicked(GtkObject* object, gpointer user_data) -{ - zoom *= 1 - inc; - set_zoom(); -} - -void -on_zoom_100_button_clicked(GtkObject* object, gpointer user_data) -{ - zoom = 1.0; - set_zoom(); -} - -void -on_zoom_fit_button_clicked(GtkObject* object, gpointer user_data) -{ - int w, h; - float zw, zh; - GtkWidget* image_a; - - image_a = (GtkWidget*) lookup_widget(cropper_window, "image_area"); - gdk_drawable_get_size(image_a->window, &w, &h); - - zw = w*1.0 / image_width; - zh = h*1.0 / image_height; - - zoom = (zw < zh) ? zw : zh; - set_zoom(); -} - - - - - - - -void -crop(void) -{ - char crop_call[256]; - - sprintf(crop_call, "echo \"convert -crop %ix%i+%i+%i %s cropped_%s\"", - gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window, - "crop_width_spinbutton")), - gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window, - "crop_height_spinbutton")), - gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window, - "crop_x_spinbutton")), - gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window, - "crop_y_spinbutton")), - image_filename, - image_filename - ); - system(crop_call); - gtk_main_quit(); -} - - -void -on_cropper_window_create(GtkObject* object, gpointer user_data) -{ - image_width = gdk_pixbuf_get_width(image_buffer); - image_height = gdk_pixbuf_get_height(image_buffer); - - /* - image_buffer = gdk_pixbuf_new_from_file(image_filename, NULL); - image_area = gtk_image_new_from_pixbuf(image_buffer); - - int w, h; - GtkWidget* image_a; - - image_a = (GtkWidget*) lookup_widget(cropper_window, "image_area"); - gdk_drawable_get_size(image_a->window, &w, &h); - - image_width = w - 200; - image_height = h - 150; - set_zoom(); - */ -} - -void -on_cropper_window_destroy(GtkObject* object, gpointer user_data) -{ - gtk_main_quit(); -} - - - - -gboolean -on_key_press(GtkWidget* window, GdkEventKey* pKey, gpointer userdata) -{ - if (pKey->type != GDK_KEY_PRESS) { - return FALSE; - } - switch (pKey->keyval) { - case GDK_q: - gtk_main_quit(); - break; - case GDK_Return: - crop(); - break; - case GDK_plus: - on_zoom_in_button_clicked(NULL, userdata); - break; - case GDK_minus: - on_zoom_out_button_clicked(NULL, userdata); - break; - case GDK_0: - on_zoom_100_button_clicked(NULL, userdata); - break; - case GDK_f: - on_zoom_fit_button_clicked(NULL, userdata); - break; - } - return TRUE; -} - - diff -r 88b8856fccf5 -r 4453456abad1 interface.c --- a/interface.c Thu Mar 04 19:20:41 2010 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,173 +0,0 @@ -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "main.h" - -#define GLADE_HOOKUP_OBJECT(component,widget,name) \ - g_object_set_data_full(G_OBJECT(component), name, \ - gtk_widget_ref(widget),(GDestroyNotify) gtk_widget_unref) - -#define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \ - g_object_set_data(G_OBJECT(component), name, widget) - - -/* - * This function returns a widget in a component created by Glade. - * Call it with the toplevel widget in the component (i.e. a window/dialog), - * or alternatively any widget in the component, and the name of the widget - * you want returned. - */ -GtkWidget* -lookup_widget(GtkWidget* widget, const gchar* widget_name) -{ - GtkWidget* parent; - GtkWidget* found_widget; - - for (;;) { - if (GTK_IS_MENU(widget)) { - parent = gtk_menu_get_attach_widget(GTK_MENU(widget)); - } else { - parent = widget->parent; - } - if (!parent) { - parent = (GtkWidget*) g_object_get_data(G_OBJECT(widget), "GladeParentKey"); - } - if (parent == NULL) { - break; - } - widget = parent; - } - - found_widget = (GtkWidget*) g_object_get_data(G_OBJECT(widget), widget_name); - if (!found_widget) { - g_warning("Widget not found: %s", widget_name); - } - return found_widget; -} - - - -GtkWidget* -create_cropper_window(void) -{ - GtkWidget *cropper_window; - GtkWidget *dialog_vbox1; - GtkWidget *status; - GtkWidget *label1; - GtkWidget *label2; - - - cropper_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_widget_set_name(cropper_window, "cropper_window"); - gtk_container_set_border_width(GTK_CONTAINER(cropper_window), 6); - gtk_window_set_title(GTK_WINDOW(cropper_window), "cropper-0.2"); - - dialog_vbox1 = gtk_vbox_new(FALSE, 6); - gtk_widget_set_name(dialog_vbox1, "dialog_vbox1"); - gtk_widget_show(dialog_vbox1); - gtk_container_add(GTK_CONTAINER(cropper_window), dialog_vbox1); - - - status = gtk_hbox_new(FALSE, 0); - gtk_widget_set_name(status, "status"); - gtk_widget_show(status); - gtk_box_pack_end(GTK_BOX(dialog_vbox1), status, FALSE, FALSE, 0); - - label1 = gtk_label_new("zoom:"); - gtk_widget_set_name(label1, "label1"); - gtk_widget_show(label1); - gtk_box_pack_start(GTK_BOX(status), label1, FALSE, FALSE, 0); - - label2 = gtk_label_new("1.0"); - gtk_widget_set_name(label2, "label2"); - gtk_widget_show(label2); - gtk_box_pack_start(GTK_BOX(status), label2, FALSE, FALSE, 0); - -/* image_area */ - image_buffer = gdk_pixbuf_new_from_file(image_filename, NULL); - image_area = gtk_image_new_from_pixbuf(image_buffer); - - gtk_widget_set_name(image_area, "image_area"); - gtk_widget_show(image_area); - gtk_box_pack_start(GTK_BOX(dialog_vbox1), image_area, TRUE, TRUE, 0); - - - - - -g_signal_connect(G_OBJECT(cropper_window), "show", - G_CALLBACK(on_cropper_window_create), NULL); - -g_signal_connect(G_OBJECT(cropper_window), "destroy", - G_CALLBACK(on_cropper_window_destroy), NULL); - -g_signal_connect(cropper_window, "key-press-event", - G_CALLBACK(on_key_press), NULL); - - - /* Store pointers to all widgets, for use by lookup_widget(). */ - - GLADE_HOOKUP_OBJECT_NO_REF(cropper_window, cropper_window, "cropper_window"); - GLADE_HOOKUP_OBJECT(cropper_window, dialog_vbox1, "dialog_vbox1"); - - GLADE_HOOKUP_OBJECT(cropper_window, label1, "label1"); - GLADE_HOOKUP_OBJECT(cropper_window, label2, "label2"); - GLADE_HOOKUP_OBJECT(cropper_window, status, "status"); - GLADE_HOOKUP_OBJECT(cropper_window, image_area, "image_area"); - GLADE_HOOKUP_OBJECT(cropper_window,(GtkWidget*) image_buffer, "image_buffer"); - - - return cropper_window; -} - - - - - - - - - -/* - gtk_container_set_border_width(GTK_CONTAINER(hbox1), 5); - - label1 = gtk_label_new("Selection"); - gtk_label_set_use_markup(GTK_LABEL(label1), TRUE); - gtk_misc_set_alignment(GTK_MISC(label1), 0, 0.5); - - gtk_table_set_row_spacings(GTK_TABLE(table2), 6); - gtk_table_set_col_spacings(GTK_TABLE(table2), 6); - - gtk_table_attach(GTK_TABLE(table2), label3, 0, 1, 0, 1,(GtkAttachOptions)(GTK_FILL), - (GtkAttachOptions)(0), 0, 0); - gtk_misc_set_alignment(GTK_MISC(label3), 0, 0.5); - - frame1 = gtk_frame_new(NULL); - gtk_widget_set_name(frame1, "frame1"); - gtk_widget_show(frame1); - gtk_box_pack_start(GTK_BOX(vbox5), frame1, TRUE, TRUE, 0); - gtk_frame_set_shadow_type(GTK_FRAME(frame1), GTK_SHADOW_NONE); - - vbox7 = gtk_vbox_new(FALSE, 6); - gtk_widget_set_name(vbox7, "vbox7"); - gtk_widget_show(vbox7); - gtk_container_add(GTK_CONTAINER(frame1), vbox7); - -g_signal_connect(G_OBJECT(lookup_widget(cropper_window, "crop_x_spinbutton")), "value_changed", - G_CALLBACK(selection_x_value_changed_cb), data); -g_signal_connect(G_OBJECT(lookup_widget(cropper_window, "crop_image")), "selection_changed", - G_CALLBACK(selection_changed_cb), data); -g_signal_connect(G_OBJECT(lookup_widget(cropper_window, "ratio_swap_button")), "clicked", - G_CALLBACK(ratio_swap_button_cb), NULL); -g_signal_connect(G_OBJECT(lookup_widget(cropper_window, "ratio_optionmenu")), "changed", - G_CALLBACK(ratio_optionmenu_changed_cb), NULL); - g_signal_connect(G_OBJECT(ratio_none), "activate", - G_CALLBACK(on_ratio_none_activate), NULL); -*/ diff -r 88b8856fccf5 -r 4453456abad1 main.c --- a/main.c Thu Mar 04 19:20:41 2010 +0100 +++ b/main.c Thu Mar 04 19:34:12 2010 +0100 @@ -1,6 +1,332 @@ +#include +#include +#include +#include +#include + #include +#include +#include -#include "main.h" + + + +GtkWidget* cropper_window; +char* image_filename; + +/* from interface.h */ +GtkWidget* create_cropper_window(void); +GtkWidget* image_area; +GdkPixbuf* image_buffer; + +int w, h, x, y; + +int image_width; +int image_height; +float inc = 0.3; +float zoom = 1.0; + +/* from callbacks.h */ +double ratio; + +void crop(void); +gboolean on_key_press(GtkWidget* window, GdkEventKey* pKey, gpointer userdata); +void on_cropper_window_create(GtkObject* object, gpointer user_data); +void on_cropper_window_destroy(GtkObject* object, gpointer user_data); + + + + + +#define GLADE_HOOKUP_OBJECT(component,widget,name) \ + g_object_set_data_full(G_OBJECT(component), name, \ + gtk_widget_ref(widget),(GDestroyNotify) gtk_widget_unref) + +#define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \ + g_object_set_data(G_OBJECT(component), name, widget) + + +/* + * This function returns a widget in a component created by Glade. + * Call it with the toplevel widget in the component (i.e. a window/dialog), + * or alternatively any widget in the component, and the name of the widget + * you want returned. + */ +GtkWidget* +lookup_widget(GtkWidget* widget, const gchar* widget_name) +{ + GtkWidget* parent; + GtkWidget* found_widget; + + for (;;) { + if (GTK_IS_MENU(widget)) { + parent = gtk_menu_get_attach_widget(GTK_MENU(widget)); + } else { + parent = widget->parent; + } + if (!parent) { + parent = (GtkWidget*) g_object_get_data(G_OBJECT(widget), "GladeParentKey"); + } + if (parent == NULL) { + break; + } + widget = parent; + } + + found_widget = (GtkWidget*) g_object_get_data(G_OBJECT(widget), widget_name); + if (!found_widget) { + g_warning("Widget not found: %s", widget_name); + } + return found_widget; +} + + + +GtkWidget* +create_cropper_window(void) +{ + GtkWidget *cropper_window; + GtkWidget *dialog_vbox1; + GtkWidget *status; + GtkWidget *label1; + GtkWidget *label2; + + + cropper_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_widget_set_name(cropper_window, "cropper_window"); + gtk_container_set_border_width(GTK_CONTAINER(cropper_window), 6); + gtk_window_set_title(GTK_WINDOW(cropper_window), "cropper-0.2"); + + dialog_vbox1 = gtk_vbox_new(FALSE, 6); + gtk_widget_set_name(dialog_vbox1, "dialog_vbox1"); + gtk_widget_show(dialog_vbox1); + gtk_container_add(GTK_CONTAINER(cropper_window), dialog_vbox1); + + + status = gtk_hbox_new(FALSE, 0); + gtk_widget_set_name(status, "status"); + gtk_widget_show(status); + gtk_box_pack_end(GTK_BOX(dialog_vbox1), status, FALSE, FALSE, 0); + + label1 = gtk_label_new("zoom:"); + gtk_widget_set_name(label1, "label1"); + gtk_widget_show(label1); + gtk_box_pack_start(GTK_BOX(status), label1, FALSE, FALSE, 0); + + label2 = gtk_label_new("1.0"); + gtk_widget_set_name(label2, "label2"); + gtk_widget_show(label2); + gtk_box_pack_start(GTK_BOX(status), label2, FALSE, FALSE, 0); + +/* image_area */ + image_buffer = gdk_pixbuf_new_from_file(image_filename, NULL); + image_area = gtk_image_new_from_pixbuf(image_buffer); + + gtk_widget_set_name(image_area, "image_area"); + gtk_widget_show(image_area); + gtk_box_pack_start(GTK_BOX(dialog_vbox1), image_area, TRUE, TRUE, 0); + + + + + +g_signal_connect(G_OBJECT(cropper_window), "show", + G_CALLBACK(on_cropper_window_create), NULL); + +g_signal_connect(G_OBJECT(cropper_window), "destroy", + G_CALLBACK(on_cropper_window_destroy), NULL); + +g_signal_connect(cropper_window, "key-press-event", + G_CALLBACK(on_key_press), NULL); + + + /* Store pointers to all widgets, for use by lookup_widget(). */ + + GLADE_HOOKUP_OBJECT_NO_REF(cropper_window, cropper_window, "cropper_window"); + GLADE_HOOKUP_OBJECT(cropper_window, dialog_vbox1, "dialog_vbox1"); + + GLADE_HOOKUP_OBJECT(cropper_window, label1, "label1"); + GLADE_HOOKUP_OBJECT(cropper_window, label2, "label2"); + GLADE_HOOKUP_OBJECT(cropper_window, status, "status"); + GLADE_HOOKUP_OBJECT(cropper_window, image_area, "image_area"); + GLADE_HOOKUP_OBJECT(cropper_window,(GtkWidget*) image_buffer, "image_buffer"); + + + return cropper_window; +} + + + + + + + + + + + + + + + + + + + + + +void +update_title(char* zoom) +{ + char title[128]; + snprintf(title, 128, "cropper (%s) %dx%d+%d+%d", zoom, w, h, x, y); + gtk_window_set_title(GTK_WINDOW(cropper_window), title); +} + + +/* zoom */ +void +set_zoom() +{ + static GdkPixbuf* pixbuf_new; + g_object_unref(pixbuf_new); + + pixbuf_new = gdk_pixbuf_scale_simple(image_buffer, image_width*zoom, image_height*zoom, + GDK_INTERP_BILINEAR); + gtk_image_set_from_pixbuf((GtkImage*) lookup_widget(cropper_window, "image_area"), pixbuf_new); +} + +void +on_zoom_in_button_clicked(GtkObject* object, gpointer user_data) +{ + zoom *= 1 + inc; + set_zoom(); +} + +void +on_zoom_out_button_clicked(GtkObject* object, gpointer user_data) +{ + zoom *= 1 - inc; + set_zoom(); +} + +void +on_zoom_100_button_clicked(GtkObject* object, gpointer user_data) +{ + zoom = 1.0; + set_zoom(); +} + +void +on_zoom_fit_button_clicked(GtkObject* object, gpointer user_data) +{ + int w, h; + float zw, zh; + GtkWidget* image_a; + + image_a = (GtkWidget*) lookup_widget(cropper_window, "image_area"); + gdk_drawable_get_size(image_a->window, &w, &h); + + zw = w*1.0 / image_width; + zh = h*1.0 / image_height; + + zoom = (zw < zh) ? zw : zh; + set_zoom(); +} + + + + + + + +void +crop(void) +{ + char crop_call[256]; + + sprintf(crop_call, "echo \"convert -crop %ix%i+%i+%i %s cropped_%s\"", + gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window, + "crop_width_spinbutton")), + gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window, + "crop_height_spinbutton")), + gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window, + "crop_x_spinbutton")), + gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window, + "crop_y_spinbutton")), + image_filename, + image_filename + ); + system(crop_call); + gtk_main_quit(); +} + + +void +on_cropper_window_create(GtkObject* object, gpointer user_data) +{ + image_width = gdk_pixbuf_get_width(image_buffer); + image_height = gdk_pixbuf_get_height(image_buffer); + + /* + image_buffer = gdk_pixbuf_new_from_file(image_filename, NULL); + image_area = gtk_image_new_from_pixbuf(image_buffer); + + int w, h; + GtkWidget* image_a; + + image_a = (GtkWidget*) lookup_widget(cropper_window, "image_area"); + gdk_drawable_get_size(image_a->window, &w, &h); + + image_width = w - 200; + image_height = h - 150; + set_zoom(); + */ +} + +void +on_cropper_window_destroy(GtkObject* object, gpointer user_data) +{ + gtk_main_quit(); +} + + + + +gboolean +on_key_press(GtkWidget* window, GdkEventKey* pKey, gpointer userdata) +{ + if (pKey->type != GDK_KEY_PRESS) { + return FALSE; + } + switch (pKey->keyval) { + case GDK_q: + gtk_main_quit(); + break; + case GDK_Return: + crop(); + break; + case GDK_plus: + on_zoom_in_button_clicked(NULL, userdata); + break; + case GDK_minus: + on_zoom_out_button_clicked(NULL, userdata); + break; + case GDK_0: + on_zoom_100_button_clicked(NULL, userdata); + break; + case GDK_f: + on_zoom_fit_button_clicked(NULL, userdata); + break; + } + return TRUE; +} + + + + + + int diff -r 88b8856fccf5 -r 4453456abad1 main.h --- a/main.h Thu Mar 04 19:20:41 2010 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ -#include - -GtkWidget* cropper_window; -char* image_filename; - -/* from interface.h */ -GtkWidget* create_cropper_window(void); -GtkWidget* image_area; -GdkPixbuf* image_buffer; - -int w, h, x, y; - -/* from callbacks.h */ -double ratio; - -void crop(void); -gboolean on_key_press(GtkWidget* window, GdkEventKey* pKey, gpointer userdata); -void on_cropper_window_create(GtkObject* object, gpointer user_data); -void on_cropper_window_destroy(GtkObject* object, gpointer user_data);