[gimp/gimp-2-10] app: add "clip" parameter to gimp_display_shell_untransform_viewport()



commit 1f76013d1e377aac8cd96f0c1126c488b4c2200c
Author: Ell <ell_se yahoo com>
Date:   Wed Sep 4 16:02:58 2019 +0300

    app: add "clip" parameter to gimp_display_shell_untransform_viewport()
    
    ... which specifies whether to clip the viewport to the canvas
    (previously, it would always be clipped).  Use the appropriate
    value in all callers, depending on the shell's "show all" mode.  In
    particular, this commit avoids clipping the image projection's
    priority rect to the canvas in "show all" mode.

 app/actions/buffers-commands.c           |  2 +-
 app/actions/edit-commands.c              |  3 ++-
 app/display/gimpdisplayshell-dnd.c       | 10 +++++++---
 app/display/gimpdisplayshell-transform.c | 25 +++++++++++--------------
 app/display/gimpdisplayshell-transform.h |  1 +
 app/display/gimpdisplayshell.c           |  5 ++++-
 app/tools/gimpfiltertool.c               |  2 +-
 app/tools/gimpseamlessclonetool.c        |  3 ++-
 8 files changed, 29 insertions(+), 22 deletions(-)
---
diff --git a/app/actions/buffers-commands.c b/app/actions/buffers-commands.c
index 3fb37001d3..509c234622 100644
--- a/app/actions/buffers-commands.c
+++ b/app/actions/buffers-commands.c
@@ -74,7 +74,7 @@ buffers_paste_cmd_callback (GimpAction *action,
         {
           GimpDisplayShell *shell = gimp_display_get_shell (display);
 
-          gimp_display_shell_untransform_viewport (shell,
+          gimp_display_shell_untransform_viewport (shell, ! shell->show_all,
                                                    &x, &y, &width, &height);
 
           image = gimp_display_get_image (display);
diff --git a/app/actions/edit-commands.c b/app/actions/edit-commands.c
index 565b0ecbdf..9d37ca7e9e 100644
--- a/app/actions/edit-commands.c
+++ b/app/actions/edit-commands.c
@@ -609,7 +609,8 @@ edit_paste (GimpDisplay   *display,
           /* the actual paste-type conversion happens in gimp_edit_paste() */
         }
 
-      gimp_display_shell_untransform_viewport (shell, &x, &y, &width, &height);
+      gimp_display_shell_untransform_viewport (shell, ! shell->show_all,
+                                               &x, &y, &width, &height);
 
       if (gimp_edit_paste (image, drawable, paste,
                            paste_type, x, y, width, height))
diff --git a/app/display/gimpdisplayshell-dnd.c b/app/display/gimpdisplayshell-dnd.c
index 24ed1c238a..4c8511e553 100644
--- a/app/display/gimpdisplayshell-dnd.c
+++ b/app/display/gimpdisplayshell-dnd.c
@@ -179,7 +179,8 @@ gimp_display_shell_dnd_position_item (GimpDisplayShell *shell,
       gint x, y;
       gint width, height;
 
-      gimp_display_shell_untransform_viewport (shell, &x, &y, &width, &height);
+      gimp_display_shell_untransform_viewport (shell, ! shell->show_all,
+                                               &x, &y, &width, &height);
 
       off_x = x + (width  - item_width)  / 2;
       off_y = y + (height - item_height) / 2;
@@ -495,7 +496,8 @@ gimp_display_shell_drop_buffer (GtkWidget    *widget,
 
   buffer = GIMP_BUFFER (viewable);
 
-  gimp_display_shell_untransform_viewport (shell, &x, &y, &width, &height);
+  gimp_display_shell_untransform_viewport (shell, ! shell->show_all,
+                                           &x, &y, &width, &height);
 
   /* FIXME: popup a menu for selecting "Paste Into" */
 
@@ -567,7 +569,9 @@ gimp_display_shell_drop_uri_list (GtkWidget *widget,
               gint height = gimp_image_get_height (image);
 
               if (gimp_display_get_image (shell->display))
-                gimp_display_shell_untransform_viewport (shell, &x, &y,
+                gimp_display_shell_untransform_viewport (shell,
+                                                         ! shell->show_all,
+                                                         &x, &y,
                                                          &width, &height);
 
               gimp_image_add_layers (image, new_layers,
diff --git a/app/display/gimpdisplayshell-transform.c b/app/display/gimpdisplayshell-transform.c
index 9f810811c6..f9cd2e56da 100644
--- a/app/display/gimpdisplayshell-transform.c
+++ b/app/display/gimpdisplayshell-transform.c
@@ -956,6 +956,7 @@ gimp_display_shell_untransform_bounds_with_scale (GimpDisplayShell *shell,
 /**
  * gimp_display_shell_untransform_viewport:
  * @shell:  a #GimpDisplayShell
+ * @clip:   whether to clip the result to the image bounds
  * @x:      returns image x coordinate of display upper left corner
  * @y:      returns image y coordinate of display upper left corner
  * @width:  returns width of display measured in image coordinates
@@ -966,13 +967,13 @@ gimp_display_shell_untransform_bounds_with_scale (GimpDisplayShell *shell,
  **/
 void
 gimp_display_shell_untransform_viewport (GimpDisplayShell *shell,
+                                         gboolean          clip,
                                          gint             *x,
                                          gint             *y,
                                          gint             *width,
                                          gint             *height)
 {
-  GimpImage *image;
-  gdouble    x1, y1, x2, y2;
+  gdouble x1, y1, x2, y2;
 
   g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
 
@@ -987,19 +988,15 @@ gimp_display_shell_untransform_viewport (GimpDisplayShell *shell,
   x2 = ceil (x2);
   y2 = ceil (y2);
 
-  image = gimp_display_get_image (shell->display);
-
-  if (x1 < 0)
-    x1 = 0;
-
-  if (y1 < 0)
-    y1 = 0;
-
-  if (x2 > gimp_image_get_width (image))
-    x2 = gimp_image_get_width (image);
+  if (clip)
+    {
+      GimpImage *image = gimp_display_get_image (shell->display);
 
-  if (y2 > gimp_image_get_height (image))
-    y2 = gimp_image_get_height (image);
+      x1 = MAX (x1, 0);
+      y1 = MAX (y1, 0);
+      x2 = MIN (x2, gimp_image_get_width  (image));
+      y2 = MIN (y2, gimp_image_get_height (image));
+    }
 
   if (x)      *x      = x1;
   if (y)      *y      = y1;
diff --git a/app/display/gimpdisplayshell-transform.h b/app/display/gimpdisplayshell-transform.h
index 5a1ccba4ca..1877b13f03 100644
--- a/app/display/gimpdisplayshell-transform.h
+++ b/app/display/gimpdisplayshell-transform.h
@@ -190,6 +190,7 @@ void  gimp_display_shell_untransform_bounds_with_scale (GimpDisplayShell   *shel
                                                         gdouble            *ny2);
 
 void  gimp_display_shell_untransform_viewport          (GimpDisplayShell   *shell,
+                                                        gboolean            clip,
                                                         gint               *x,
                                                         gint               *y,
                                                         gint               *width,
diff --git a/app/display/gimpdisplayshell.c b/app/display/gimpdisplayshell.c
index b24d2da60d..611d1261c9 100644
--- a/app/display/gimpdisplayshell.c
+++ b/app/display/gimpdisplayshell.c
@@ -1050,7 +1050,8 @@ gimp_display_shell_set_priority_viewport (GimpDisplayShell *shell)
       gint            x, y;
       gint            width, height;
 
-      gimp_display_shell_untransform_viewport (shell, &x, &y, &width, &height);
+      gimp_display_shell_untransform_viewport (shell, ! shell->show_all,
+                                               &x, &y, &width, &height);
       gimp_projection_set_priority_rect (projection, x, y, width, height);
     }
 }
@@ -1847,6 +1848,8 @@ gimp_display_shell_set_show_all (GimpDisplayShell *shell,
 
       gimp_display_update_bounding_box (shell->display);
 
+      gimp_display_shell_set_priority_viewport (shell);
+
       gimp_display_shell_expose_full (shell);
 
       g_object_notify (G_OBJECT (shell), "show-all");
diff --git a/app/tools/gimpfiltertool.c b/app/tools/gimpfiltertool.c
index 3fb17f5317..cac86f733d 100644
--- a/app/tools/gimpfiltertool.c
+++ b/app/tools/gimpfiltertool.c
@@ -739,7 +739,7 @@ gimp_filter_tool_options_notify (GimpTool         *tool,
           GimpItem         *item  = GIMP_ITEM (tool->drawable);
           gint              x, y, width, height;
 
-          gimp_display_shell_untransform_viewport (shell,
+          gimp_display_shell_untransform_viewport (shell, TRUE,
                                                    &x, &y, &width, &height);
 
           if (gimp_rectangle_intersect (gimp_item_get_offset_x (item),
diff --git a/app/tools/gimpseamlessclonetool.c b/app/tools/gimpseamlessclonetool.c
index 4848c702a5..79a97806d3 100644
--- a/app/tools/gimpseamlessclonetool.c
+++ b/app/tools/gimpseamlessclonetool.c
@@ -792,7 +792,8 @@ gimp_seamless_clone_tool_filter_update (GimpSeamlessCloneTool *sc)
 
   /* Find out at which x,y is the top left corner of the currently
    * displayed part */
-  gimp_display_shell_untransform_viewport (shell, &x, &y, &w, &h);
+  gimp_display_shell_untransform_viewport (shell, ! shell->show_all,
+                                           &x, &y, &w, &h);
 
   /* Find out where is our drawable positioned */
   gimp_item_get_offset (item, &off_x, &off_y);


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