[gimp] app: make scrollbar limits and scroll-offset clamping rotation aware



commit bfba49d203b4644bfee63554e3e2776ba322ee87
Author: Ell <ell_se yahoo com>
Date:   Sat Jul 16 19:21:56 2016 +0000

    app: make scrollbar limits and scroll-offset clamping rotation aware
    
    Limit the scrollbars by the (screen space) bounding box of the canvas.
    Scroll offsets are clamped to 1.5 that.

 app/display/gimpdisplayshell-rotate.c     |    2 +
 app/display/gimpdisplayshell-scale.c      |    3 +
 app/display/gimpdisplayshell-scroll.c     |   70 ++++++++++++++++++---------
 app/display/gimpdisplayshell-scrollbars.c |   75 ++++++++++++++++++++--------
 4 files changed, 105 insertions(+), 45 deletions(-)
---
diff --git a/app/display/gimpdisplayshell-rotate.c b/app/display/gimpdisplayshell-rotate.c
index e928843..efc7f6f 100644
--- a/app/display/gimpdisplayshell-rotate.c
+++ b/app/display/gimpdisplayshell-rotate.c
@@ -74,6 +74,8 @@ gimp_display_shell_rotate_to (GimpDisplayShell *shell,
 
   shell->rotate_angle = value;
 
+  gimp_display_shell_scroll_clamp_and_update (shell);
+
   gimp_display_shell_rotated (shell);
   gimp_display_shell_expose_full (shell);
 }
diff --git a/app/display/gimpdisplayshell-scale.c b/app/display/gimpdisplayshell-scale.c
index 499447e..8568ba1 100644
--- a/app/display/gimpdisplayshell-scale.c
+++ b/app/display/gimpdisplayshell-scale.c
@@ -34,6 +34,7 @@
 #include "gimpdisplay.h"
 #include "gimpdisplayshell.h"
 #include "gimpdisplayshell-expose.h"
+#include "gimpdisplayshell-rotate.h"
 #include "gimpdisplayshell-scale.h"
 #include "gimpdisplayshell-scroll.h"
 #include "gimpdisplayshell-transform.h"
@@ -642,6 +643,8 @@ gimp_display_shell_scale_by_values (GimpDisplayShell *shell,
   shell->offset_x = offset_x;
   shell->offset_y = offset_y;
 
+  gimp_display_shell_rotate_update_transform (shell);
+
   gimp_display_shell_scale_resize (shell, resize_window, FALSE);
 
   /* re-enable the active tool */
diff --git a/app/display/gimpdisplayshell-scroll.c b/app/display/gimpdisplayshell-scroll.c
index 5345251..089d738 100644
--- a/app/display/gimpdisplayshell-scroll.c
+++ b/app/display/gimpdisplayshell-scroll.c
@@ -35,6 +35,7 @@
 #include "gimpdisplay-foreach.h"
 #include "gimpdisplayshell.h"
 #include "gimpdisplayshell-expose.h"
+#include "gimpdisplayshell-rotate.h"
 #include "gimpdisplayshell-rulers.h"
 #include "gimpdisplayshell-scale.h"
 #include "gimpdisplayshell-scroll.h"
@@ -158,49 +159,72 @@ gimp_display_shell_scroll_clamp_and_update (GimpDisplayShell *shell)
 
   if (image)
     {
-      gint sw, sh;
-      gint min_offset_x;
-      gint max_offset_x;
-      gint min_offset_y;
-      gint max_offset_y;
-
-      sw = SCALEX (shell, gimp_image_get_width  (image));
-      sh = SCALEY (shell, gimp_image_get_height (image));
-
-      if (shell->disp_width < sw)
+      gdouble dx, dy;
+      gdouble dw, dh;
+      gint    min_offset_x;
+      gint    max_offset_x;
+      gint    min_offset_y;
+      gint    max_offset_y;
+      gint    offset_x;
+      gint    offset_y;
+
+      gimp_display_shell_rotate_update_transform (shell);
+
+      gimp_display_shell_transform_bounds (shell,
+                                           0, 0,
+                                           gimp_image_get_width (image),
+                                           gimp_image_get_height (image),
+                                           &dx, &dy,
+                                           &dw, &dh);
+
+      /* Convert scrolled (x1, y1, x2, y2) to unscrolled (x, y, width, height). */
+      dw -= dx;
+      dh -= dy;
+      dx += shell->offset_x;
+      dy += shell->offset_y;
+
+      if (shell->disp_width < dw)
         {
-          min_offset_x = 0  - shell->disp_width * OVERPAN_FACTOR;
-          max_offset_x = sw - shell->disp_width * (1.0 - OVERPAN_FACTOR);
+          min_offset_x = dx      - shell->disp_width * OVERPAN_FACTOR;
+          max_offset_x = dx + dw - shell->disp_width * (1.0 - OVERPAN_FACTOR);
         }
       else
         {
           gint overpan_amount;
 
-          overpan_amount = shell->disp_width - sw * (1.0 - OVERPAN_FACTOR);
+          overpan_amount = shell->disp_width - dw * (1.0 - OVERPAN_FACTOR);
 
-          min_offset_x = 0  - overpan_amount;
-          max_offset_x = sw + overpan_amount - shell->disp_width;
+          min_offset_x = dx      - overpan_amount;
+          max_offset_x = dx + dw + overpan_amount - shell->disp_width;
         }
 
-      if (shell->disp_height < sh)
+      if (shell->disp_height < dh)
         {
-          min_offset_y = 0  - shell->disp_height * OVERPAN_FACTOR;
-          max_offset_y = sh - shell->disp_height * (1.0 - OVERPAN_FACTOR);
+          min_offset_y = dy      - shell->disp_height * OVERPAN_FACTOR;
+          max_offset_y = dy + dh - shell->disp_height * (1.0 - OVERPAN_FACTOR);
         }
       else
         {
           gint overpan_amount;
 
-          overpan_amount = shell->disp_height - sh * (1.0 - OVERPAN_FACTOR);
+          overpan_amount = shell->disp_height - dh * (1.0 - OVERPAN_FACTOR);
 
-          min_offset_y = 0  - overpan_amount;
-          max_offset_y = sh + overpan_amount - shell->disp_height;
+          min_offset_y = dy      - overpan_amount;
+          max_offset_y = dy + dh + overpan_amount - shell->disp_height;
         }
 
       /* Clamp */
 
-      shell->offset_x = CLAMP (shell->offset_x, min_offset_x, max_offset_x);
-      shell->offset_y = CLAMP (shell->offset_y, min_offset_y, max_offset_y);
+      offset_x = CLAMP (shell->offset_x, min_offset_x, max_offset_x);
+      offset_y = CLAMP (shell->offset_y, min_offset_y, max_offset_y);
+
+      if (offset_x != shell->offset_x || offset_y != shell->offset_y)
+        {
+          shell->offset_x = offset_x;
+          shell->offset_y = offset_y;
+
+          gimp_display_shell_rotate_update_transform (shell);
+        }
 
       /* Set scrollbar stepper sensitiity */
 
diff --git a/app/display/gimpdisplayshell-scrollbars.c b/app/display/gimpdisplayshell-scrollbars.c
index ee998c6..fd61d81 100644
--- a/app/display/gimpdisplayshell-scrollbars.c
+++ b/app/display/gimpdisplayshell-scrollbars.c
@@ -22,9 +22,12 @@
 
 #include "display-types.h"
 
+#include "core/gimpimage.h"
+
 #include "gimpdisplay.h"
 #include "gimpdisplayshell.h"
 #include "gimpdisplayshell-scale.h"
+#include "gimpdisplayshell-transform.h"
 #include "gimpdisplayshell-scrollbars.h"
 
 
@@ -87,28 +90,42 @@ void
 gimp_display_shell_scrollbars_setup_horizontal (GimpDisplayShell *shell,
                                                 gdouble           value)
 {
-  gint    sw;
-  gdouble lower;
-  gdouble upper;
+  GimpImage *image;
+  gdouble    dx, dy;
+  gdouble    dw, dh;
+  gdouble    lower;
+  gdouble    upper;
 
   g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
 
-  if (! shell->display ||
-      ! gimp_display_get_image (shell->display))
+  if (! shell->display)
     return;
 
-  gimp_display_shell_scale_get_image_size (shell, &sw, NULL);
+  image = gimp_display_get_image (shell->display);
+  if (! image)
+    return;
+
+  gimp_display_shell_transform_bounds (shell,
+                                       0, 0,
+                                       gimp_image_get_width (image),
+                                       gimp_image_get_height (image),
+                                       &dx, &dy,
+                                       &dw, &dh);
+
+  /* Convert scrolled (x1, x2) to unscrolled (x, width). */
+  dw -= dx;
+  dx += shell->offset_x;
 
-  if (shell->disp_width < sw)
+  if (shell->disp_width < dw)
     {
-      lower = MIN (value, 0);
-      upper = MAX (value + shell->disp_width, sw);
+      lower = MIN (value, dx);
+      upper = MAX (value + shell->disp_width, dx + dw);
     }
   else
     {
-      lower = MIN (value, -(shell->disp_width - sw) / 2);
+      lower = MIN (value, dx - (shell->disp_width - dw) / 2);
       upper = MAX (value + shell->disp_width,
-                   sw + (shell->disp_width - sw) / 2);
+                   dx + dw + (shell->disp_width - dw) / 2);
     }
 
   g_object_set (shell->hsbdata,
@@ -130,28 +147,42 @@ void
 gimp_display_shell_scrollbars_setup_vertical (GimpDisplayShell *shell,
                                               gdouble           value)
 {
-  gint    sh;
-  gdouble lower;
-  gdouble upper;
+  GimpImage *image;
+  gdouble    dx, dy;
+  gdouble    dw, dh;
+  gdouble    lower;
+  gdouble    upper;
 
   g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
 
-  if (! shell->display ||
-      ! gimp_display_get_image (shell->display))
+  if (! shell->display)
+    return;
+
+  image = gimp_display_get_image (shell->display);
+  if (! image)
     return;
 
-  gimp_display_shell_scale_get_image_size (shell, NULL, &sh);
+  gimp_display_shell_transform_bounds (shell,
+                                       0, 0,
+                                       gimp_image_get_width (image),
+                                       gimp_image_get_height (image),
+                                       &dx, &dy,
+                                       &dw, &dh);
+
+  /* Convert scrolled (y1, y2) to unscrolled (y, height). */
+  dh -= dy;
+  dy += shell->offset_y;
 
-  if (shell->disp_height < sh)
+  if (shell->disp_height < dh)
     {
-      lower = MIN (value, 0);
-      upper = MAX (value + shell->disp_height, sh);
+      lower = MIN (value, dy);
+      upper = MAX (value + shell->disp_height, dy + dh);
     }
   else
     {
-      lower = MIN (value, -(shell->disp_height - sh) / 2);
+      lower = MIN (value, dy - (shell->disp_height - dh) / 2);
       upper = MAX (value + shell->disp_height,
-                   sh + (shell->disp_height - sh) / 2);
+                   dy + dh + (shell->disp_height - dh) / 2);
     }
 
   g_object_set (shell->vsbdata,


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