[gimp] app: fix gimp_display_shell_scale_to_rectangle() to also do only scrolling



commit 5bc9ad947a9b8314885b1215925036dd120f079c
Author: Michael Natterer <mitch gimp org>
Date:   Sun Oct 18 15:18:23 2015 +0200

    app: fix gimp_display_shell_scale_to_rectangle() to also do only scrolling
    
    which means: also scroll to the rectangle if the scale doesn't change.

 app/display/gimpdisplayshell-scale.c |  137 +++++++++++++++++-----------------
 1 files changed, 70 insertions(+), 67 deletions(-)
---
diff --git a/app/display/gimpdisplayshell-scale.c b/app/display/gimpdisplayshell-scale.c
index 506bfe8..06e8f8d 100644
--- a/app/display/gimpdisplayshell-scale.c
+++ b/app/display/gimpdisplayshell-scale.c
@@ -517,14 +517,23 @@ gimp_display_shell_scale_to_rectangle (GimpDisplayShell *shell,
                                        gdouble           height,
                                        gboolean          resize_window)
 {
-  gdouble current_scale;
-  gdouble new_scale;
-  gdouble display_width;
-  gdouble display_height;
-  gdouble factor = 1.0;
+  GimpImage *image;
+  gdouble    current_scale;
+  gdouble    new_scale;
+  gdouble    display_width;
+  gdouble    display_height;
+  gdouble    factor   = 1.0;
+  gint       offset_x = 0;
+  gint       offset_y = 0;
+  gdouble    xres;
+  gdouble    yres;
+  gdouble    screen_xres;
+  gdouble    screen_yres;
 
   g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
 
+  image = gimp_display_get_image (shell->display);
+
   width  = MAX (1.0, width);
   height = MAX (1.0, height);
 
@@ -552,70 +561,64 @@ gimp_display_shell_scale_to_rectangle (GimpDisplayShell *shell,
 
   new_scale = current_scale * factor;
 
-  if (new_scale != current_scale)
+  gimp_image_get_resolution (image, &xres, &yres);
+  gimp_display_shell_get_screen_resolution (shell,
+                                            &screen_xres, &screen_yres);
+
+  switch (zoom_type)
     {
-      GimpImage *image    = gimp_display_get_image (shell->display);
-      gint       offset_x = 0;
-      gint       offset_y = 0;
-      gdouble    xres;
-      gdouble    yres;
-      gdouble    screen_xres;
-      gdouble    screen_yres;
-
-      gimp_image_get_resolution (image, &xres, &yres);
-      gimp_display_shell_get_screen_resolution (shell,
-                                                &screen_xres, &screen_yres);
-
-      switch (zoom_type)
-        {
-        case GIMP_ZOOM_IN:
-          /*  move the center of the rectangle to the center of the
-           *  viewport:
-           *
-           *  new_offset = center of rectangle in new scale screen coords
-           *               including offset
-           *               -
-           *               center of viewport in screen coords without
-           *               offset
-           */
-          offset_x = RINT (new_scale * (x + width / 2.0) *
-                           screen_xres / xres -
-                           (shell->disp_width / 2.0));
-
-          offset_y = RINT (new_scale * (y + height / 2.0) *
-                           screen_yres / yres -
-                           (shell->disp_height / 2.0));
-          break;
-
-        case GIMP_ZOOM_OUT:
-          /*  move the center of the viewport to the center of the
-           *  rectangle:
-           *
-           *  new_offset = center of viewport in new scale screen coords
-           *               including offset
-           *               -
-           *               center of rectangle in screen coords without
-           *               offset
-           */
-          offset_x = RINT (new_scale * UNSCALEX (shell,
-                                                 shell->offset_x +
-                                                 shell->disp_width / 2.0) *
-                           screen_xres / xres -
-                           (SCALEX (shell, x + width / 2.0) -
-                            shell->offset_x));
-
-          offset_y = RINT (new_scale * UNSCALEY (shell,
-                                                 shell->offset_y +
-                                                 shell->disp_height / 2.0) *
-                           screen_yres / yres -
-                           (SCALEY (shell, y + height / 2.0) -
-                            shell->offset_y));
-          break;
-
-        default:
-          break;
-        }
+    case GIMP_ZOOM_IN:
+      /*  move the center of the rectangle to the center of the
+       *  viewport:
+       *
+       *  new_offset = center of rectangle in new scale screen coords
+       *               including offset
+       *               -
+       *               center of viewport in screen coords without
+       *               offset
+       */
+      offset_x = RINT (new_scale * (x + width / 2.0) *
+                       screen_xres / xres -
+                       (shell->disp_width / 2.0));
+
+      offset_y = RINT (new_scale * (y + height / 2.0) *
+                       screen_yres / yres -
+                       (shell->disp_height / 2.0));
+      break;
+
+    case GIMP_ZOOM_OUT:
+      /*  move the center of the viewport to the center of the
+       *  rectangle:
+       *
+       *  new_offset = center of viewport in new scale screen coords
+       *               including offset
+       *               -
+       *               center of rectangle in screen coords without
+       *               offset
+       */
+      offset_x = RINT (new_scale * UNSCALEX (shell,
+                                             shell->offset_x +
+                                             shell->disp_width / 2.0) *
+                       screen_xres / xres -
+                       (SCALEX (shell, x + width / 2.0) -
+                        shell->offset_x));
+
+      offset_y = RINT (new_scale * UNSCALEY (shell,
+                                             shell->offset_y +
+                                             shell->disp_height / 2.0) *
+                       screen_yres / yres -
+                       (SCALEY (shell, y + height / 2.0) -
+                        shell->offset_y));
+      break;
 
+    default:
+      break;
+    }
+
+  if (new_scale != current_scale   ||
+      offset_x  != shell->offset_x ||
+      offset_y  != shell->offset_y)
+    {
       gimp_display_shell_scale_by_values (shell,
                                           new_scale,
                                           offset_x, offset_y,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]