Mercurial > cropper
changeset 13:13bc21684b8a
added zooming with buttons
author | meillo@marmaro.de |
---|---|
date | Thu, 04 Mar 2010 17:05:38 +0100 |
parents | 75a30c850ea0 |
children | da18f2d4f92f |
files | callbacks.c callbacks.h interface.c main.h |
diffstat | 4 files changed, 53 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/callbacks.c Thu Mar 04 14:23:30 2010 +0100 +++ b/callbacks.c Thu Mar 04 17:05:38 2010 +0100 @@ -1,5 +1,6 @@ #include <gtk/gtk.h> #include <gdk-pixbuf/gdk-pixbuf.h> +#include <gdk/gdkkeysyms.h> #include "main.h" #include "callbacks.h" #include "support.h" @@ -7,6 +8,7 @@ int image_width; int image_height; float inc = 0.3; +float zoom = 1.0; /* @@ -200,6 +202,14 @@ */ +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 @@ -208,31 +218,29 @@ static GdkPixbuf* pixbuf_new; g_object_unref(pixbuf_new); - pixbuf_new = gdk_pixbuf_scale_simple(image_buffer, image_width, image_height, GDK_INTERP_BILINEAR); + 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) { - image_width *= 1 + inc; - image_height *= 1 + inc; + zoom *= 1 + inc; set_zoom(); } void on_zoom_out_button_clicked(GtkObject* object, gpointer user_data) { - image_width *= 1 - inc; - image_height *= 1 - inc; + zoom *= 1 - inc; set_zoom(); } void on_zoom_100_button_clicked(GtkObject* object, gpointer user_data) { - image_width = gdk_pixbuf_get_width(image_buffer); - image_height = gdk_pixbuf_get_height(image_buffer); + zoom = 1.0; set_zoom(); } @@ -240,13 +248,16 @@ 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); - image_width = w - 200; - image_height = h - 150; + zw = w*1.0 / image_width; + zh = h*1.0 / image_height; + + zoom = (zw < zh) ? zw : zh; set_zoom(); } @@ -306,3 +317,30 @@ 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_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; +} + +
--- a/callbacks.h Thu Mar 04 14:23:30 2010 +0100 +++ b/callbacks.h Thu Mar 04 17:05:38 2010 +0100 @@ -34,4 +34,6 @@ void on_zoom_100_button_clicked(GtkObject* object, gpointer user_data); void on_zoom_fit_button_clicked(GtkObject* object, gpointer user_data); +gboolean on_key_press(GtkWidget* window, GdkEventKey* pKey, gpointer userdata); + #endif