From de82d2f7ec1eef80c1c8dbaf1539429671024242 Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Thu, 14 Aug 2008 17:41:38 +0000 Subject: [PATCH] If the image is within the viewport and we are zooming out, make the focus 2008-08-14 Martin Nordholts * app/display/gimpdisplayshell-scale.c (gimp_display_shell_scale_get_zoom_focus): If the image is within the viewport and we are zooming out, make the focus point be the center of the image. svn path=/trunk/; revision=26560 --- ChangeLog | 7 +++ app/display/gimpdisplayshell-scale.c | 87 +++++++++++++++++----------- 2 files changed, 61 insertions(+), 33 deletions(-) diff --git a/ChangeLog b/ChangeLog index d40c43ea43..646d37d2f3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-08-14 Martin Nordholts + + * app/display/gimpdisplayshell-scale.c + (gimp_display_shell_scale_get_zoom_focus): If the image is within + the viewport and we are zooming out, make the focus point be the + center of the image. + 2008-08-14 Martin Nordholts * app/display/gimpdisplayshell-scale.c diff --git a/app/display/gimpdisplayshell-scale.c b/app/display/gimpdisplayshell-scale.c index c0791f915c..2bc69ad1ca 100644 --- a/app/display/gimpdisplayshell-scale.c +++ b/app/display/gimpdisplayshell-scale.c @@ -74,6 +74,7 @@ static void gimp_display_shell_scale_to (GimpDisplayShell *shell, gdouble x, gdouble y); static void gimp_display_shell_scale_get_zoom_focus (GimpDisplayShell *shell, + gdouble new_scale, gint *x, gint *y); @@ -363,7 +364,7 @@ gimp_display_shell_scale (GimpDisplayShell *shell, if (! SCALE_EQUALS (real_new_scale, current_scale)) { - gimp_display_shell_scale_get_zoom_focus (shell, &x, &y); + gimp_display_shell_scale_get_zoom_focus (shell, real_new_scale, &x, &y); gimp_display_shell_scale_to (shell, real_new_scale, x, y); } @@ -888,6 +889,7 @@ gimp_display_shell_scale_to (GimpDisplayShell *shell, /** * gimp_display_shell_scale_get_zoom_focus: * @shell: + * @new_scale: * @x: * @y: * @@ -895,47 +897,66 @@ gimp_display_shell_scale_to (GimpDisplayShell *shell, **/ static void gimp_display_shell_scale_get_zoom_focus (GimpDisplayShell *shell, + gdouble new_scale, gint *x, gint *y) { GdkEvent *event; + gdouble current_scale = gimp_zoom_model_get_factor (shell->zoom); - *x = shell->disp_width / 2; - *y = shell->disp_height / 2; - - /* Center on the mouse position instead of the display center if - * one of the following conditions are fulfilled and pointer is - * within the canvas: - * - * (1) there's no current event (the action was triggered by an - * input controller) - * (2) the event originates from the canvas (a scroll event) - * (3) the event originates from the shell (a key press event) - * - * Basically the only situation where we don't want to center on - * mouse position is if the action is being called from a menu. - */ - - event = gtk_get_current_event (); - - if (! event || - gtk_get_event_widget (event) == shell->canvas || - gtk_get_event_widget (event) == GTK_WIDGET (shell)) + if (new_scale < current_scale && + gimp_display_shell_scale_image_is_within_viewport (shell)) { - gint canvas_pointer_x; - gint canvas_pointer_y; + /* If the image is within the viewport and we are zooming out, put + * the zoom focus in the center of the image + */ + gint sw, sh; - gtk_widget_get_pointer (shell->canvas, - &canvas_pointer_x, - &canvas_pointer_y); + gimp_display_shell_draw_get_scaled_image_size (shell, + &sw, + &sh); + *x = -shell->offset_x + sw / 2; + *y = -shell->offset_y + sh / 2; + } + else + { + *x = shell->disp_width / 2; + *y = shell->disp_height / 2; - if (canvas_pointer_x >= 0 && - canvas_pointer_y >= 0 && - canvas_pointer_x < shell->disp_width && - canvas_pointer_y < shell->disp_height) + /* Center on the mouse position instead of the display center if + * one of the following conditions are fulfilled and pointer is + * within the canvas: + * + * (1) there's no current event (the action was triggered by an + * input controller) + * (2) the event originates from the canvas (a scroll event) + * (3) the event originates from the shell (a key press event) + * + * Basically the only situation where we don't want to center on + * mouse position is if the action is being called from a menu. + */ + + event = gtk_get_current_event (); + + if (! event || + gtk_get_event_widget (event) == shell->canvas || + gtk_get_event_widget (event) == GTK_WIDGET (shell)) { - *x = canvas_pointer_x; - *y = canvas_pointer_y; + gint canvas_pointer_x; + gint canvas_pointer_y; + + gtk_widget_get_pointer (shell->canvas, + &canvas_pointer_x, + &canvas_pointer_y); + + if (canvas_pointer_x >= 0 && + canvas_pointer_y >= 0 && + canvas_pointer_x < shell->disp_width && + canvas_pointer_y < shell->disp_height) + { + *x = canvas_pointer_x; + *y = canvas_pointer_y; + } } } }