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 diff
1.1 --- a/callbacks.c Thu Mar 04 14:23:30 2010 +0100 1.2 +++ b/callbacks.c Thu Mar 04 17:05:38 2010 +0100 1.3 @@ -1,5 +1,6 @@ 1.4 #include <gtk/gtk.h> 1.5 #include <gdk-pixbuf/gdk-pixbuf.h> 1.6 +#include <gdk/gdkkeysyms.h> 1.7 #include "main.h" 1.8 #include "callbacks.h" 1.9 #include "support.h" 1.10 @@ -7,6 +8,7 @@ 1.11 int image_width; 1.12 int image_height; 1.13 float inc = 0.3; 1.14 +float zoom = 1.0; 1.15 1.16 1.17 /* 1.18 @@ -200,6 +202,14 @@ 1.19 */ 1.20 1.21 1.22 +void 1.23 +update_title(char* zoom) 1.24 +{ 1.25 + char title[128]; 1.26 + snprintf(title, 128, "cropper (%s) %dx%d+%d+%d", zoom, w, h, x, y); 1.27 + gtk_window_set_title(GTK_WINDOW(cropper_window), title); 1.28 +} 1.29 + 1.30 1.31 /* zoom */ 1.32 void 1.33 @@ -208,31 +218,29 @@ 1.34 static GdkPixbuf* pixbuf_new; 1.35 g_object_unref(pixbuf_new); 1.36 1.37 - pixbuf_new = gdk_pixbuf_scale_simple(image_buffer, image_width, image_height, GDK_INTERP_BILINEAR); 1.38 + pixbuf_new = gdk_pixbuf_scale_simple(image_buffer, image_width*zoom, image_height*zoom, 1.39 + GDK_INTERP_BILINEAR); 1.40 gtk_image_set_from_pixbuf((GtkImage*) lookup_widget(cropper_window, "image_area"), pixbuf_new); 1.41 } 1.42 1.43 void 1.44 on_zoom_in_button_clicked(GtkObject* object, gpointer user_data) 1.45 { 1.46 - image_width *= 1 + inc; 1.47 - image_height *= 1 + inc; 1.48 + zoom *= 1 + inc; 1.49 set_zoom(); 1.50 } 1.51 1.52 void 1.53 on_zoom_out_button_clicked(GtkObject* object, gpointer user_data) 1.54 { 1.55 - image_width *= 1 - inc; 1.56 - image_height *= 1 - inc; 1.57 + zoom *= 1 - inc; 1.58 set_zoom(); 1.59 } 1.60 1.61 void 1.62 on_zoom_100_button_clicked(GtkObject* object, gpointer user_data) 1.63 { 1.64 - image_width = gdk_pixbuf_get_width(image_buffer); 1.65 - image_height = gdk_pixbuf_get_height(image_buffer); 1.66 + zoom = 1.0; 1.67 set_zoom(); 1.68 } 1.69 1.70 @@ -240,13 +248,16 @@ 1.71 on_zoom_fit_button_clicked(GtkObject* object, gpointer user_data) 1.72 { 1.73 int w, h; 1.74 + float zw, zh; 1.75 GtkWidget* image_a; 1.76 1.77 image_a = (GtkWidget*) lookup_widget(cropper_window, "image_area"); 1.78 gdk_drawable_get_size(image_a->window, &w, &h); 1.79 1.80 - image_width = w - 200; 1.81 - image_height = h - 150; 1.82 + zw = w*1.0 / image_width; 1.83 + zh = h*1.0 / image_height; 1.84 + 1.85 + zoom = (zw < zh) ? zw : zh; 1.86 set_zoom(); 1.87 } 1.88 1.89 @@ -306,3 +317,30 @@ 1.90 gtk_main_quit(); 1.91 } 1.92 1.93 + 1.94 + 1.95 + 1.96 +gboolean 1.97 +on_key_press(GtkWidget* window, GdkEventKey* pKey, gpointer userdata) 1.98 +{ 1.99 + if (pKey->type != GDK_KEY_PRESS) { 1.100 + return FALSE; 1.101 + } 1.102 + switch (pKey->keyval) { 1.103 + case GDK_plus: 1.104 + on_zoom_in_button_clicked(NULL, userdata); 1.105 + break; 1.106 + case GDK_minus: 1.107 + on_zoom_out_button_clicked(NULL, userdata); 1.108 + break; 1.109 + case GDK_0: 1.110 + on_zoom_100_button_clicked(NULL, userdata); 1.111 + break; 1.112 + case GDK_f: 1.113 + on_zoom_fit_button_clicked(NULL, userdata); 1.114 + break; 1.115 + } 1.116 + return TRUE; 1.117 +} 1.118 + 1.119 +
2.1 --- a/callbacks.h Thu Mar 04 14:23:30 2010 +0100 2.2 +++ b/callbacks.h Thu Mar 04 17:05:38 2010 +0100 2.3 @@ -34,4 +34,6 @@ 2.4 void on_zoom_100_button_clicked(GtkObject* object, gpointer user_data); 2.5 void on_zoom_fit_button_clicked(GtkObject* object, gpointer user_data); 2.6 2.7 +gboolean on_key_press(GtkWidget* window, GdkEventKey* pKey, gpointer userdata); 2.8 + 2.9 #endif