From 47b34e973de078c34d2c182ea669f9506df27990 Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Wed, 13 Aug 2008 17:36:29 +0000 Subject: [PATCH] New function. 2008-08-13 Martin Nordholts * app/display/gimpdisplayshell-scale.c (gimp_display_shell_scale_image_is_within_viewport): New function. * app/display/gimpdisplayshell.c (gimp_display_shell_new): When the zoom button is toggled, implicitly do a View -> Fit Image in Window if the (scaled) image is within the viewport. svn path=/trunk/; revision=26529 --- ChangeLog | 9 ++++ app/display/gimpdisplayshell-scale.c | 25 +++++++++++ app/display/gimpdisplayshell-scale.h | 63 ++++++++++++++-------------- app/display/gimpdisplayshell.c | 21 ++++++++-- 4 files changed, 84 insertions(+), 34 deletions(-) diff --git a/ChangeLog b/ChangeLog index 86cc15ca79..62527dd65b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-08-13 Martin Nordholts + + * app/display/gimpdisplayshell-scale.c + (gimp_display_shell_scale_image_is_within_viewport): New function. + + * app/display/gimpdisplayshell.c (gimp_display_shell_new): When + the zoom button is toggled, implicitly do a View -> Fit Image in + Window if the (scaled) image is within the viewport. + 2008-08-13 Martin Nordholts * app/paint/gimppaintcore.c: Include gimpprojection.h for diff --git a/app/display/gimpdisplayshell-scale.c b/app/display/gimpdisplayshell-scale.c index 3feae2d4eb..cd4f0390f2 100644 --- a/app/display/gimpdisplayshell-scale.c +++ b/app/display/gimpdisplayshell-scale.c @@ -38,6 +38,7 @@ #include "gimpdisplay.h" #include "gimpdisplayshell.h" +#include "gimpdisplayshell-draw.h" #include "gimpdisplayshell-scale.h" #include "gimpdisplayshell-scroll.h" #include "gimpdisplayshell-title.h" @@ -445,6 +446,30 @@ gimp_display_shell_scale_fit_in (GimpDisplayShell *shell) gimp_display_shell_scroll_center_image (shell, TRUE, TRUE); } +/** + * gimp_display_shell_scale_image_is_within_viewport: + * @shell: + * + * Returns: %TRUE if the (scaled) image is smaller than and within the + * viewport. + **/ +gboolean +gimp_display_shell_scale_image_is_within_viewport (GimpDisplayShell *shell) +{ + gint sw, sh; + + g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE); + + gimp_display_shell_draw_get_scaled_image_size (shell, &sw, &sh); + + return sw < shell->disp_width && + sh < shell->disp_height && + shell->offset_x < 0 && + shell->offset_y < 0 && + shell->offset_x > sw - shell->disp_width && + shell->offset_y > sh - shell->disp_height; +} + /** * gimp_display_shell_scale_fill: * @shell: the #GimpDisplayShell diff --git a/app/display/gimpdisplayshell-scale.h b/app/display/gimpdisplayshell-scale.h index db6b604fea..111f2441f3 100644 --- a/app/display/gimpdisplayshell-scale.h +++ b/app/display/gimpdisplayshell-scale.h @@ -20,42 +20,43 @@ #define __GIMP_DISPLAY_SHELL_SCALE_H__ -void gimp_display_shell_update_scrollbars_and_rulers (GimpDisplayShell *shell); +void gimp_display_shell_update_scrollbars_and_rulers (GimpDisplayShell *shell); -gboolean gimp_display_shell_scale_revert (GimpDisplayShell *shell); -gboolean gimp_display_shell_scale_can_revert (GimpDisplayShell *shell); +gboolean gimp_display_shell_scale_revert (GimpDisplayShell *shell); +gboolean gimp_display_shell_scale_can_revert (GimpDisplayShell *shell); -void gimp_display_shell_scale_set_dot_for_dot (GimpDisplayShell *shell, - gboolean dot_for_dot); +void gimp_display_shell_scale_set_dot_for_dot (GimpDisplayShell *shell, + gboolean dot_for_dot); -void gimp_display_shell_scale (GimpDisplayShell *shell, - GimpZoomType zoom_type, - gdouble scale); -void gimp_display_shell_scale_to (GimpDisplayShell *shell, - GimpZoomType zoom_type, - gdouble scale, - gdouble x, - gdouble y); -void gimp_display_shell_scale_fit_in (GimpDisplayShell *shell); -void gimp_display_shell_scale_fill (GimpDisplayShell *shell); -void gimp_display_shell_scale_handle_zoom_revert (GimpDisplayShell *shell); -void gimp_display_shell_scale_by_values (GimpDisplayShell *shell, - gdouble scale, - gint offset_x, - gint offset_y, - gboolean resize_window); -void gimp_display_shell_scale_shrink_wrap (GimpDisplayShell *shell, - gboolean grow_only); +void gimp_display_shell_scale (GimpDisplayShell *shell, + GimpZoomType zoom_type, + gdouble scale); +void gimp_display_shell_scale_to (GimpDisplayShell *shell, + GimpZoomType zoom_type, + gdouble scale, + gdouble x, + gdouble y); +void gimp_display_shell_scale_fit_in (GimpDisplayShell *shell); +gboolean gimp_display_shell_scale_image_is_within_viewport (GimpDisplayShell *shell); +void gimp_display_shell_scale_fill (GimpDisplayShell *shell); +void gimp_display_shell_scale_handle_zoom_revert (GimpDisplayShell *shell); +void gimp_display_shell_scale_by_values (GimpDisplayShell *shell, + gdouble scale, + gint offset_x, + gint offset_y, + gboolean resize_window); +void gimp_display_shell_scale_shrink_wrap (GimpDisplayShell *shell, + gboolean grow_only); -void gimp_display_shell_scale_resize (GimpDisplayShell *shell, - gboolean resize_window, - gboolean grow_only); -void gimp_display_shell_set_initial_scale (GimpDisplayShell *shell, - gdouble scale, - gint *display_width, - gint *display_height); +void gimp_display_shell_scale_resize (GimpDisplayShell *shell, + gboolean resize_window, + gboolean grow_only); +void gimp_display_shell_set_initial_scale (GimpDisplayShell *shell, + gdouble scale, + gint *display_width, + gint *display_height); -void gimp_display_shell_scale_dialog (GimpDisplayShell *shell); +void gimp_display_shell_scale_dialog (GimpDisplayShell *shell); #endif /* __GIMP_DISPLAY_SHELL_SCALE_H__ */ diff --git a/app/display/gimpdisplayshell.c b/app/display/gimpdisplayshell.c index e43e631bf7..7c17b06be7 100644 --- a/app/display/gimpdisplayshell.c +++ b/app/display/gimpdisplayshell.c @@ -718,6 +718,21 @@ gimp_display_shell_get_icc_profile (GimpColorManaged *managed, return NULL; } +static void +gimp_display_shell_zoom_button_callback (GimpDisplayShell *shell, + GtkWidget *zoom_button) +{ + shell->zoom_on_resize = + gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (zoom_button)); + + if (shell->zoom_on_resize && + gimp_display_shell_scale_image_is_within_viewport (shell)) + { + /* Implicitly make a View -> Fit Image in Window */ + gimp_display_shell_scale_fit_in (shell); + } +} + /* public functions */ @@ -1079,9 +1094,9 @@ gimp_display_shell_new (GimpDisplay *display, _("Zoom image when window size changes"), GIMP_HELP_IMAGE_WINDOW_ZOOM_FOLLOW_BUTTON); - g_signal_connect (shell->zoom_button, "toggled", - G_CALLBACK (gimp_toggle_button_update), - &shell->zoom_on_resize); + g_signal_connect_swapped (shell->zoom_button, "toggled", + G_CALLBACK (gimp_display_shell_zoom_button_callback), + shell); /* create the contents of the lower_hbox *********************************/