cropper

changeset 18:9d6e8105b145

rename
author meillo@marmaro.de
date Thu, 04 Mar 2010 19:34:39 +0100
parents 4453456abad1
children 762de8cee1e4
files cropper.c main.c
diffstat 2 files changed, 351 insertions(+), 351 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/cropper.c	Thu Mar 04 19:34:39 2010 +0100
     1.3 @@ -0,0 +1,351 @@
     1.4 +#include <sys/types.h>
     1.5 +#include <sys/stat.h>
     1.6 +#include <unistd.h>
     1.7 +#include <string.h>
     1.8 +#include <stdio.h>
     1.9 +
    1.10 +#include <gtk/gtk.h>
    1.11 +#include <gdk/gdkkeysyms.h>
    1.12 +#include <gdk-pixbuf/gdk-pixbuf.h>
    1.13 +
    1.14 +
    1.15 +
    1.16 +
    1.17 +GtkWidget* cropper_window;
    1.18 +char* image_filename;
    1.19 +
    1.20 +/* from interface.h */
    1.21 +GtkWidget* create_cropper_window(void);
    1.22 +GtkWidget* image_area;
    1.23 +GdkPixbuf* image_buffer;
    1.24 +
    1.25 +int w, h, x, y;
    1.26 +
    1.27 +int image_width;
    1.28 +int image_height;
    1.29 +float inc = 0.3;
    1.30 +float zoom = 1.0;
    1.31 +
    1.32 +/* from callbacks.h */
    1.33 +double ratio;
    1.34 +
    1.35 +void crop(void);
    1.36 +gboolean on_key_press(GtkWidget* window, GdkEventKey* pKey, gpointer userdata);
    1.37 +void on_cropper_window_create(GtkObject* object, gpointer user_data);
    1.38 +void on_cropper_window_destroy(GtkObject* object, gpointer user_data);
    1.39 +
    1.40 +
    1.41 +
    1.42 +
    1.43 +
    1.44 +#define GLADE_HOOKUP_OBJECT(component,widget,name) \
    1.45 +  g_object_set_data_full(G_OBJECT(component), name, \
    1.46 +    gtk_widget_ref(widget),(GDestroyNotify) gtk_widget_unref)
    1.47 +
    1.48 +#define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \
    1.49 +  g_object_set_data(G_OBJECT(component), name, widget)
    1.50 +
    1.51 +
    1.52 +/*
    1.53 + * This function returns a widget in a component created by Glade.
    1.54 + * Call it with the toplevel widget in the component (i.e. a window/dialog),
    1.55 + * or alternatively any widget in the component, and the name of the widget
    1.56 + * you want returned.
    1.57 + */
    1.58 +GtkWidget*
    1.59 +lookup_widget(GtkWidget* widget, const gchar* widget_name)
    1.60 +{
    1.61 +	GtkWidget* parent;
    1.62 +	GtkWidget* found_widget;
    1.63 +
    1.64 +	for (;;) {
    1.65 +		if (GTK_IS_MENU(widget)) {
    1.66 +			parent = gtk_menu_get_attach_widget(GTK_MENU(widget));
    1.67 +		} else {
    1.68 +			parent = widget->parent;
    1.69 +		}
    1.70 +		if (!parent) {
    1.71 +			parent = (GtkWidget*) g_object_get_data(G_OBJECT(widget), "GladeParentKey");
    1.72 +		}
    1.73 +		if (parent == NULL) {
    1.74 +			break;
    1.75 +		}
    1.76 +		widget = parent;
    1.77 +	}
    1.78 +
    1.79 +	found_widget = (GtkWidget*) g_object_get_data(G_OBJECT(widget), widget_name);
    1.80 +	if (!found_widget) {
    1.81 +		g_warning("Widget not found: %s", widget_name);
    1.82 +	}
    1.83 +	return found_widget;
    1.84 +}
    1.85 +
    1.86 +
    1.87 +
    1.88 +GtkWidget*
    1.89 +create_cropper_window(void)
    1.90 +{
    1.91 +  GtkWidget *cropper_window;
    1.92 +  GtkWidget *dialog_vbox1;
    1.93 +  GtkWidget *status;
    1.94 +  GtkWidget *label1;
    1.95 +  GtkWidget *label2;
    1.96 +
    1.97 +
    1.98 +  cropper_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    1.99 +  gtk_widget_set_name(cropper_window, "cropper_window");
   1.100 +  gtk_container_set_border_width(GTK_CONTAINER(cropper_window), 6);
   1.101 +  gtk_window_set_title(GTK_WINDOW(cropper_window), "cropper-0.2");
   1.102 +
   1.103 +  dialog_vbox1 = gtk_vbox_new(FALSE, 6);
   1.104 +  gtk_widget_set_name(dialog_vbox1, "dialog_vbox1");
   1.105 +  gtk_widget_show(dialog_vbox1);
   1.106 +  gtk_container_add(GTK_CONTAINER(cropper_window), dialog_vbox1);
   1.107 +
   1.108 +
   1.109 +  status = gtk_hbox_new(FALSE, 0);
   1.110 +  gtk_widget_set_name(status, "status");
   1.111 +  gtk_widget_show(status);
   1.112 +  gtk_box_pack_end(GTK_BOX(dialog_vbox1), status, FALSE, FALSE, 0);
   1.113 +
   1.114 +  label1 = gtk_label_new("zoom:");
   1.115 +  gtk_widget_set_name(label1, "label1");
   1.116 +  gtk_widget_show(label1);
   1.117 +  gtk_box_pack_start(GTK_BOX(status), label1, FALSE, FALSE, 0);
   1.118 +
   1.119 +  label2 = gtk_label_new("1.0");
   1.120 +  gtk_widget_set_name(label2, "label2");
   1.121 +  gtk_widget_show(label2);
   1.122 +  gtk_box_pack_start(GTK_BOX(status), label2, FALSE, FALSE, 0);
   1.123 +
   1.124 +/* image_area */
   1.125 +  image_buffer = gdk_pixbuf_new_from_file(image_filename, NULL);
   1.126 +  image_area = gtk_image_new_from_pixbuf(image_buffer);
   1.127 +
   1.128 +  gtk_widget_set_name(image_area, "image_area");
   1.129 +  gtk_widget_show(image_area);
   1.130 +  gtk_box_pack_start(GTK_BOX(dialog_vbox1), image_area, TRUE, TRUE, 0);
   1.131 +
   1.132 +
   1.133 +
   1.134 +
   1.135 +
   1.136 +g_signal_connect(G_OBJECT(cropper_window), "show",
   1.137 +                 G_CALLBACK(on_cropper_window_create), NULL);
   1.138 +
   1.139 +g_signal_connect(G_OBJECT(cropper_window), "destroy",
   1.140 +                 G_CALLBACK(on_cropper_window_destroy), NULL);
   1.141 +
   1.142 +g_signal_connect(cropper_window, "key-press-event",
   1.143 +                 G_CALLBACK(on_key_press), NULL);
   1.144 +
   1.145 +
   1.146 +  /* Store pointers to all widgets, for use by lookup_widget(). */
   1.147 +
   1.148 +  GLADE_HOOKUP_OBJECT_NO_REF(cropper_window, cropper_window, "cropper_window");
   1.149 +  GLADE_HOOKUP_OBJECT(cropper_window, dialog_vbox1, "dialog_vbox1");
   1.150 +
   1.151 +  GLADE_HOOKUP_OBJECT(cropper_window, label1, "label1");
   1.152 +  GLADE_HOOKUP_OBJECT(cropper_window, label2, "label2");
   1.153 +  GLADE_HOOKUP_OBJECT(cropper_window, status, "status");
   1.154 +  GLADE_HOOKUP_OBJECT(cropper_window, image_area, "image_area");
   1.155 +  GLADE_HOOKUP_OBJECT(cropper_window,(GtkWidget*) image_buffer, "image_buffer");
   1.156 +
   1.157 +
   1.158 +  return cropper_window;
   1.159 +}
   1.160 +
   1.161 +
   1.162 +
   1.163 +
   1.164 +
   1.165 +
   1.166 +
   1.167 +
   1.168 +
   1.169 +
   1.170 +
   1.171 +
   1.172 +
   1.173 +
   1.174 +
   1.175 +
   1.176 +
   1.177 +
   1.178 +
   1.179 +
   1.180 +
   1.181 +void
   1.182 +update_title(char* zoom)
   1.183 +{
   1.184 +	char title[128];
   1.185 +	snprintf(title, 128, "cropper (%s) %dx%d+%d+%d", zoom, w, h, x, y);
   1.186 +	gtk_window_set_title(GTK_WINDOW(cropper_window), title);
   1.187 +}
   1.188 +
   1.189 +
   1.190 +/* zoom */
   1.191 +void
   1.192 +set_zoom()
   1.193 +{
   1.194 +	static GdkPixbuf* pixbuf_new;
   1.195 +	g_object_unref(pixbuf_new);
   1.196 +
   1.197 +	pixbuf_new = gdk_pixbuf_scale_simple(image_buffer, image_width*zoom, image_height*zoom,
   1.198 +	                                     GDK_INTERP_BILINEAR);
   1.199 +	gtk_image_set_from_pixbuf((GtkImage*) lookup_widget(cropper_window, "image_area"), pixbuf_new);
   1.200 +}
   1.201 +
   1.202 +void
   1.203 +on_zoom_in_button_clicked(GtkObject* object, gpointer user_data)
   1.204 +{
   1.205 +	zoom *= 1 + inc;
   1.206 +	set_zoom();
   1.207 +}
   1.208 +
   1.209 +void
   1.210 +on_zoom_out_button_clicked(GtkObject* object, gpointer user_data)
   1.211 +{
   1.212 +	zoom *= 1 - inc;
   1.213 +	set_zoom();
   1.214 +}
   1.215 +
   1.216 +void
   1.217 +on_zoom_100_button_clicked(GtkObject* object, gpointer user_data)
   1.218 +{
   1.219 +	zoom = 1.0;
   1.220 +	set_zoom();
   1.221 +}
   1.222 +
   1.223 +void
   1.224 +on_zoom_fit_button_clicked(GtkObject* object, gpointer user_data)
   1.225 +{
   1.226 +	int w, h;
   1.227 +	float zw, zh;
   1.228 +	GtkWidget* image_a;
   1.229 +
   1.230 +	image_a = (GtkWidget*) lookup_widget(cropper_window, "image_area");
   1.231 +	gdk_drawable_get_size(image_a->window, &w, &h);
   1.232 +
   1.233 +	zw = w*1.0 / image_width;
   1.234 +	zh = h*1.0 / image_height;
   1.235 +
   1.236 +	zoom = (zw < zh) ? zw : zh;
   1.237 +	set_zoom();
   1.238 +}
   1.239 +
   1.240 +
   1.241 +
   1.242 +
   1.243 +
   1.244 +
   1.245 +
   1.246 +void
   1.247 +crop(void)
   1.248 +{
   1.249 +	char crop_call[256];
   1.250 +
   1.251 +	sprintf(crop_call, "echo \"convert -crop %ix%i+%i+%i %s cropped_%s\"",
   1.252 +		gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window,
   1.253 +		                                 "crop_width_spinbutton")),
   1.254 +		gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window,
   1.255 +		                                 "crop_height_spinbutton")),
   1.256 +		gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window,
   1.257 +		                                 "crop_x_spinbutton")),
   1.258 +		gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window,
   1.259 +		                                 "crop_y_spinbutton")),
   1.260 +		image_filename,
   1.261 +		image_filename
   1.262 +	);
   1.263 +	system(crop_call);
   1.264 +	gtk_main_quit();
   1.265 +}
   1.266 +
   1.267 +
   1.268 +void
   1.269 +on_cropper_window_create(GtkObject* object, gpointer user_data)
   1.270 +{
   1.271 +	image_width = gdk_pixbuf_get_width(image_buffer);
   1.272 +	image_height = gdk_pixbuf_get_height(image_buffer);
   1.273 +
   1.274 +	/*
   1.275 +	image_buffer = gdk_pixbuf_new_from_file(image_filename, NULL);
   1.276 +	image_area = gtk_image_new_from_pixbuf(image_buffer);
   1.277 +
   1.278 +	int w, h;
   1.279 +	GtkWidget* image_a;
   1.280 +
   1.281 +	image_a = (GtkWidget*) lookup_widget(cropper_window, "image_area");
   1.282 +	gdk_drawable_get_size(image_a->window, &w, &h);
   1.283 +
   1.284 +	image_width = w - 200;
   1.285 +	image_height = h - 150;
   1.286 +	set_zoom();
   1.287 +	*/
   1.288 +}
   1.289 +
   1.290 +void
   1.291 +on_cropper_window_destroy(GtkObject* object, gpointer user_data)
   1.292 +{
   1.293 +	gtk_main_quit();
   1.294 +}
   1.295 +
   1.296 +
   1.297 +
   1.298 +
   1.299 +gboolean
   1.300 +on_key_press(GtkWidget* window, GdkEventKey* pKey, gpointer userdata)
   1.301 +{
   1.302 +	if (pKey->type != GDK_KEY_PRESS) {
   1.303 +		return FALSE;
   1.304 +	}
   1.305 +	switch (pKey->keyval) {
   1.306 +	case GDK_q:
   1.307 +		gtk_main_quit();
   1.308 +		break;
   1.309 +	case GDK_Return:
   1.310 +		crop();
   1.311 +		break;
   1.312 +	case GDK_plus:
   1.313 +		on_zoom_in_button_clicked(NULL, userdata);
   1.314 +		break;
   1.315 +	case GDK_minus:
   1.316 +		on_zoom_out_button_clicked(NULL, userdata);
   1.317 +		break;
   1.318 +	case GDK_0:
   1.319 +		on_zoom_100_button_clicked(NULL, userdata);
   1.320 +		break;
   1.321 +	case GDK_f:
   1.322 +		on_zoom_fit_button_clicked(NULL, userdata);
   1.323 +		break;
   1.324 +	}
   1.325 +	return TRUE;
   1.326 +}
   1.327 +
   1.328 +
   1.329 +
   1.330 +
   1.331 +
   1.332 +
   1.333 +
   1.334 +
   1.335 +int
   1.336 +main(int argc, char* argv[])
   1.337 +{
   1.338 +	/* commandline option handling */
   1.339 +	if (argc != 2) {
   1.340 +		g_print("cropper -- a crop frontend to convert\n");
   1.341 +		g_print("usage: cropper IMAGE\n");
   1.342 +		return 1;
   1.343 +	}
   1.344 +
   1.345 +	image_filename = argv[1];
   1.346 +	gtk_init(&argc, &argv);
   1.347 +
   1.348 +	cropper_window = create_cropper_window();
   1.349 +	gtk_widget_show(cropper_window);
   1.350 +	gtk_main();
   1.351 +
   1.352 +	return 0;
   1.353 +}
   1.354 +
     2.1 --- a/main.c	Thu Mar 04 19:34:12 2010 +0100
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,351 +0,0 @@
     2.4 -#include <sys/types.h>
     2.5 -#include <sys/stat.h>
     2.6 -#include <unistd.h>
     2.7 -#include <string.h>
     2.8 -#include <stdio.h>
     2.9 -
    2.10 -#include <gtk/gtk.h>
    2.11 -#include <gdk/gdkkeysyms.h>
    2.12 -#include <gdk-pixbuf/gdk-pixbuf.h>
    2.13 -
    2.14 -
    2.15 -
    2.16 -
    2.17 -GtkWidget* cropper_window;
    2.18 -char* image_filename;
    2.19 -
    2.20 -/* from interface.h */
    2.21 -GtkWidget* create_cropper_window(void);
    2.22 -GtkWidget* image_area;
    2.23 -GdkPixbuf* image_buffer;
    2.24 -
    2.25 -int w, h, x, y;
    2.26 -
    2.27 -int image_width;
    2.28 -int image_height;
    2.29 -float inc = 0.3;
    2.30 -float zoom = 1.0;
    2.31 -
    2.32 -/* from callbacks.h */
    2.33 -double ratio;
    2.34 -
    2.35 -void crop(void);
    2.36 -gboolean on_key_press(GtkWidget* window, GdkEventKey* pKey, gpointer userdata);
    2.37 -void on_cropper_window_create(GtkObject* object, gpointer user_data);
    2.38 -void on_cropper_window_destroy(GtkObject* object, gpointer user_data);
    2.39 -
    2.40 -
    2.41 -
    2.42 -
    2.43 -
    2.44 -#define GLADE_HOOKUP_OBJECT(component,widget,name) \
    2.45 -  g_object_set_data_full(G_OBJECT(component), name, \
    2.46 -    gtk_widget_ref(widget),(GDestroyNotify) gtk_widget_unref)
    2.47 -
    2.48 -#define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \
    2.49 -  g_object_set_data(G_OBJECT(component), name, widget)
    2.50 -
    2.51 -
    2.52 -/*
    2.53 - * This function returns a widget in a component created by Glade.
    2.54 - * Call it with the toplevel widget in the component (i.e. a window/dialog),
    2.55 - * or alternatively any widget in the component, and the name of the widget
    2.56 - * you want returned.
    2.57 - */
    2.58 -GtkWidget*
    2.59 -lookup_widget(GtkWidget* widget, const gchar* widget_name)
    2.60 -{
    2.61 -	GtkWidget* parent;
    2.62 -	GtkWidget* found_widget;
    2.63 -
    2.64 -	for (;;) {
    2.65 -		if (GTK_IS_MENU(widget)) {
    2.66 -			parent = gtk_menu_get_attach_widget(GTK_MENU(widget));
    2.67 -		} else {
    2.68 -			parent = widget->parent;
    2.69 -		}
    2.70 -		if (!parent) {
    2.71 -			parent = (GtkWidget*) g_object_get_data(G_OBJECT(widget), "GladeParentKey");
    2.72 -		}
    2.73 -		if (parent == NULL) {
    2.74 -			break;
    2.75 -		}
    2.76 -		widget = parent;
    2.77 -	}
    2.78 -
    2.79 -	found_widget = (GtkWidget*) g_object_get_data(G_OBJECT(widget), widget_name);
    2.80 -	if (!found_widget) {
    2.81 -		g_warning("Widget not found: %s", widget_name);
    2.82 -	}
    2.83 -	return found_widget;
    2.84 -}
    2.85 -
    2.86 -
    2.87 -
    2.88 -GtkWidget*
    2.89 -create_cropper_window(void)
    2.90 -{
    2.91 -  GtkWidget *cropper_window;
    2.92 -  GtkWidget *dialog_vbox1;
    2.93 -  GtkWidget *status;
    2.94 -  GtkWidget *label1;
    2.95 -  GtkWidget *label2;
    2.96 -
    2.97 -
    2.98 -  cropper_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    2.99 -  gtk_widget_set_name(cropper_window, "cropper_window");
   2.100 -  gtk_container_set_border_width(GTK_CONTAINER(cropper_window), 6);
   2.101 -  gtk_window_set_title(GTK_WINDOW(cropper_window), "cropper-0.2");
   2.102 -
   2.103 -  dialog_vbox1 = gtk_vbox_new(FALSE, 6);
   2.104 -  gtk_widget_set_name(dialog_vbox1, "dialog_vbox1");
   2.105 -  gtk_widget_show(dialog_vbox1);
   2.106 -  gtk_container_add(GTK_CONTAINER(cropper_window), dialog_vbox1);
   2.107 -
   2.108 -
   2.109 -  status = gtk_hbox_new(FALSE, 0);
   2.110 -  gtk_widget_set_name(status, "status");
   2.111 -  gtk_widget_show(status);
   2.112 -  gtk_box_pack_end(GTK_BOX(dialog_vbox1), status, FALSE, FALSE, 0);
   2.113 -
   2.114 -  label1 = gtk_label_new("zoom:");
   2.115 -  gtk_widget_set_name(label1, "label1");
   2.116 -  gtk_widget_show(label1);
   2.117 -  gtk_box_pack_start(GTK_BOX(status), label1, FALSE, FALSE, 0);
   2.118 -
   2.119 -  label2 = gtk_label_new("1.0");
   2.120 -  gtk_widget_set_name(label2, "label2");
   2.121 -  gtk_widget_show(label2);
   2.122 -  gtk_box_pack_start(GTK_BOX(status), label2, FALSE, FALSE, 0);
   2.123 -
   2.124 -/* image_area */
   2.125 -  image_buffer = gdk_pixbuf_new_from_file(image_filename, NULL);
   2.126 -  image_area = gtk_image_new_from_pixbuf(image_buffer);
   2.127 -
   2.128 -  gtk_widget_set_name(image_area, "image_area");
   2.129 -  gtk_widget_show(image_area);
   2.130 -  gtk_box_pack_start(GTK_BOX(dialog_vbox1), image_area, TRUE, TRUE, 0);
   2.131 -
   2.132 -
   2.133 -
   2.134 -
   2.135 -
   2.136 -g_signal_connect(G_OBJECT(cropper_window), "show",
   2.137 -                 G_CALLBACK(on_cropper_window_create), NULL);
   2.138 -
   2.139 -g_signal_connect(G_OBJECT(cropper_window), "destroy",
   2.140 -                 G_CALLBACK(on_cropper_window_destroy), NULL);
   2.141 -
   2.142 -g_signal_connect(cropper_window, "key-press-event",
   2.143 -                 G_CALLBACK(on_key_press), NULL);
   2.144 -
   2.145 -
   2.146 -  /* Store pointers to all widgets, for use by lookup_widget(). */
   2.147 -
   2.148 -  GLADE_HOOKUP_OBJECT_NO_REF(cropper_window, cropper_window, "cropper_window");
   2.149 -  GLADE_HOOKUP_OBJECT(cropper_window, dialog_vbox1, "dialog_vbox1");
   2.150 -
   2.151 -  GLADE_HOOKUP_OBJECT(cropper_window, label1, "label1");
   2.152 -  GLADE_HOOKUP_OBJECT(cropper_window, label2, "label2");
   2.153 -  GLADE_HOOKUP_OBJECT(cropper_window, status, "status");
   2.154 -  GLADE_HOOKUP_OBJECT(cropper_window, image_area, "image_area");
   2.155 -  GLADE_HOOKUP_OBJECT(cropper_window,(GtkWidget*) image_buffer, "image_buffer");
   2.156 -
   2.157 -
   2.158 -  return cropper_window;
   2.159 -}
   2.160 -
   2.161 -
   2.162 -
   2.163 -
   2.164 -
   2.165 -
   2.166 -
   2.167 -
   2.168 -
   2.169 -
   2.170 -
   2.171 -
   2.172 -
   2.173 -
   2.174 -
   2.175 -
   2.176 -
   2.177 -
   2.178 -
   2.179 -
   2.180 -
   2.181 -void
   2.182 -update_title(char* zoom)
   2.183 -{
   2.184 -	char title[128];
   2.185 -	snprintf(title, 128, "cropper (%s) %dx%d+%d+%d", zoom, w, h, x, y);
   2.186 -	gtk_window_set_title(GTK_WINDOW(cropper_window), title);
   2.187 -}
   2.188 -
   2.189 -
   2.190 -/* zoom */
   2.191 -void
   2.192 -set_zoom()
   2.193 -{
   2.194 -	static GdkPixbuf* pixbuf_new;
   2.195 -	g_object_unref(pixbuf_new);
   2.196 -
   2.197 -	pixbuf_new = gdk_pixbuf_scale_simple(image_buffer, image_width*zoom, image_height*zoom,
   2.198 -	                                     GDK_INTERP_BILINEAR);
   2.199 -	gtk_image_set_from_pixbuf((GtkImage*) lookup_widget(cropper_window, "image_area"), pixbuf_new);
   2.200 -}
   2.201 -
   2.202 -void
   2.203 -on_zoom_in_button_clicked(GtkObject* object, gpointer user_data)
   2.204 -{
   2.205 -	zoom *= 1 + inc;
   2.206 -	set_zoom();
   2.207 -}
   2.208 -
   2.209 -void
   2.210 -on_zoom_out_button_clicked(GtkObject* object, gpointer user_data)
   2.211 -{
   2.212 -	zoom *= 1 - inc;
   2.213 -	set_zoom();
   2.214 -}
   2.215 -
   2.216 -void
   2.217 -on_zoom_100_button_clicked(GtkObject* object, gpointer user_data)
   2.218 -{
   2.219 -	zoom = 1.0;
   2.220 -	set_zoom();
   2.221 -}
   2.222 -
   2.223 -void
   2.224 -on_zoom_fit_button_clicked(GtkObject* object, gpointer user_data)
   2.225 -{
   2.226 -	int w, h;
   2.227 -	float zw, zh;
   2.228 -	GtkWidget* image_a;
   2.229 -
   2.230 -	image_a = (GtkWidget*) lookup_widget(cropper_window, "image_area");
   2.231 -	gdk_drawable_get_size(image_a->window, &w, &h);
   2.232 -
   2.233 -	zw = w*1.0 / image_width;
   2.234 -	zh = h*1.0 / image_height;
   2.235 -
   2.236 -	zoom = (zw < zh) ? zw : zh;
   2.237 -	set_zoom();
   2.238 -}
   2.239 -
   2.240 -
   2.241 -
   2.242 -
   2.243 -
   2.244 -
   2.245 -
   2.246 -void
   2.247 -crop(void)
   2.248 -{
   2.249 -	char crop_call[256];
   2.250 -
   2.251 -	sprintf(crop_call, "echo \"convert -crop %ix%i+%i+%i %s cropped_%s\"",
   2.252 -		gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window,
   2.253 -		                                 "crop_width_spinbutton")),
   2.254 -		gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window,
   2.255 -		                                 "crop_height_spinbutton")),
   2.256 -		gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window,
   2.257 -		                                 "crop_x_spinbutton")),
   2.258 -		gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window,
   2.259 -		                                 "crop_y_spinbutton")),
   2.260 -		image_filename,
   2.261 -		image_filename
   2.262 -	);
   2.263 -	system(crop_call);
   2.264 -	gtk_main_quit();
   2.265 -}
   2.266 -
   2.267 -
   2.268 -void
   2.269 -on_cropper_window_create(GtkObject* object, gpointer user_data)
   2.270 -{
   2.271 -	image_width = gdk_pixbuf_get_width(image_buffer);
   2.272 -	image_height = gdk_pixbuf_get_height(image_buffer);
   2.273 -
   2.274 -	/*
   2.275 -	image_buffer = gdk_pixbuf_new_from_file(image_filename, NULL);
   2.276 -	image_area = gtk_image_new_from_pixbuf(image_buffer);
   2.277 -
   2.278 -	int w, h;
   2.279 -	GtkWidget* image_a;
   2.280 -
   2.281 -	image_a = (GtkWidget*) lookup_widget(cropper_window, "image_area");
   2.282 -	gdk_drawable_get_size(image_a->window, &w, &h);
   2.283 -
   2.284 -	image_width = w - 200;
   2.285 -	image_height = h - 150;
   2.286 -	set_zoom();
   2.287 -	*/
   2.288 -}
   2.289 -
   2.290 -void
   2.291 -on_cropper_window_destroy(GtkObject* object, gpointer user_data)
   2.292 -{
   2.293 -	gtk_main_quit();
   2.294 -}
   2.295 -
   2.296 -
   2.297 -
   2.298 -
   2.299 -gboolean
   2.300 -on_key_press(GtkWidget* window, GdkEventKey* pKey, gpointer userdata)
   2.301 -{
   2.302 -	if (pKey->type != GDK_KEY_PRESS) {
   2.303 -		return FALSE;
   2.304 -	}
   2.305 -	switch (pKey->keyval) {
   2.306 -	case GDK_q:
   2.307 -		gtk_main_quit();
   2.308 -		break;
   2.309 -	case GDK_Return:
   2.310 -		crop();
   2.311 -		break;
   2.312 -	case GDK_plus:
   2.313 -		on_zoom_in_button_clicked(NULL, userdata);
   2.314 -		break;
   2.315 -	case GDK_minus:
   2.316 -		on_zoom_out_button_clicked(NULL, userdata);
   2.317 -		break;
   2.318 -	case GDK_0:
   2.319 -		on_zoom_100_button_clicked(NULL, userdata);
   2.320 -		break;
   2.321 -	case GDK_f:
   2.322 -		on_zoom_fit_button_clicked(NULL, userdata);
   2.323 -		break;
   2.324 -	}
   2.325 -	return TRUE;
   2.326 -}
   2.327 -
   2.328 -
   2.329 -
   2.330 -
   2.331 -
   2.332 -
   2.333 -
   2.334 -
   2.335 -int
   2.336 -main(int argc, char* argv[])
   2.337 -{
   2.338 -	/* commandline option handling */
   2.339 -	if (argc != 2) {
   2.340 -		g_print("cropper -- a crop frontend to convert\n");
   2.341 -		g_print("usage: cropper IMAGE\n");
   2.342 -		return 1;
   2.343 -	}
   2.344 -
   2.345 -	image_filename = argv[1];
   2.346 -	gtk_init(&argc, &argv);
   2.347 -
   2.348 -	cropper_window = create_cropper_window();
   2.349 -	gtk_widget_show(cropper_window);
   2.350 -	gtk_main();
   2.351 -
   2.352 -	return 0;
   2.353 -}
   2.354 -