From c32c6f5ad024cf4ca396b867d82693501e341659 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Tue, 9 Mar 2010 19:14:19 +0100 Subject: Implemented zoom buttons. --- wallpapers.c | 15 +++++++++++++++ walls.ui | 2 ++ window_main.c | 28 +++++++++++++++++++++++++++- 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/wallpapers.c b/wallpapers.c index a4bfb60..0d37f5e 100644 --- a/wallpapers.c +++ b/wallpapers.c @@ -223,3 +223,18 @@ GdkPixbuf *resize_pixbuf(GdkPixbuf *orig, gint win_width, gint win_height, gint return pb; } + +GdkPixbuf *zoom_pixbuf(GdkPixbuf *orig, gdouble zoom) { + GdkPixbuf *pb; + gint img_width, img_height, width, height; + + img_width = gdk_pixbuf_get_width(orig); + img_height = gdk_pixbuf_get_height(orig); + + width = img_width * zoom; + height = img_height * zoom; + pb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height); + gdk_pixbuf_scale(orig, pb, 0, 0, width, height, 0, 0, + (gdouble)width / (gdouble)img_width, (gdouble)height / (gdouble)img_height, GDK_INTERP_BILINEAR); + return pb; +} diff --git a/walls.ui b/walls.ui index 7f3a410..cb6f3bd 100644 --- a/walls.ui +++ b/walls.ui @@ -133,6 +133,7 @@ Zoom _In True gtk-zoom-in + False @@ -145,6 +146,7 @@ Zoom _Out True gtk-zoom-out + False diff --git a/window_main.c b/window_main.c index ff5200f..bd1de4f 100644 --- a/window_main.c +++ b/window_main.c @@ -27,6 +27,7 @@ gboolean layout_dragging = FALSE; gdouble layout_dragx, layout_dragy; enum zoom_mode_t zoom_mode = ZOOM_BESTFIT; +gdouble zoom_factor = 1.0; GtkWindow *window; GtkImage *image = NULL; @@ -186,8 +187,21 @@ static void set_image_pixbuf() { set_image_pixbuf_resized(pb, win_width, win_height, width, height, ratio); g_object_unref(pb); - } else if(zoom_mode == ZOOM_NORMAL || zoom_mode == ZOOM_CUSTOM) { + } else if(zoom_mode == ZOOM_NORMAL) { set_image_pixbuf_normal(orig_pixbuf, win_width, win_height, gdk_pixbuf_get_width(orig_pixbuf), gdk_pixbuf_get_height(orig_pixbuf)); + } else if(zoom_mode == ZOOM_CUSTOM) { + pb = zoom_pixbuf(orig_pixbuf, zoom_factor); + if(!pb) + return; + + width = gdk_pixbuf_get_width(pb); + height = gdk_pixbuf_get_height(pb); + + set_image_pixbuf_normal(pb, win_width, win_height, width, height); + + set_resize_msg(zoom_factor); + + g_object_unref(pb); } } @@ -921,6 +935,18 @@ void on_zoom_mode_toggled(GtkToggleToolButton *toolbutton, gpointer user_data) { } } +void on_zoom_in_clicked(GtkToolButton *toolbutton, gpointer user_data) { + zoom_mode = ZOOM_CUSTOM; + zoom_factor *= 1.25; + set_image_pixbuf(); +} + +void on_zoom_out_clicked(GtkToolButton *toolbutton, gpointer user_data) { + zoom_mode = ZOOM_CUSTOM; + zoom_factor *= .80; + set_image_pixbuf(); +} + gboolean on_layout_button_press_event(GtkWindow *widget, GdkEventButton *event, gpointer user_data) { GtkAdjustment *hadj, *vadj; -- cgit v1.2.3