[gimp/gimp-2-10] Issue #288: Point snapping to guides does not work outside the canvas.



commit 22db7695c822d27a17ea88da8766e95911516b0a
Author: Jehan <jehan girinstud io>
Date:   Sat Feb 13 01:30:51 2021 +0100

    Issue #288: Point snapping to guides does not work outside the canvas.
    
    This commit also makes snap to grid and snap to vectors work off-canvas.
    Since we now have off-canvas viewing, it just makes sense that snapping
    would work there too.
    
    Note that I disable snap to grid when "Show All" is OFF. I am actually
    unsure this is right (as "Show All" is a view action, and we usually
    don't change behavior based on view actions; for instance snap to guides
    are not disabled if guides are hidden). Yet I noticed we do this in
    various other features when off-canvas. We kind of use this view flag as
    a switch for features working off-canvas (for instance, color picking
    works off-canvas only when "Show All" is ON). So let's keep the same
    logics for now at least.
    
    Snap to guide or snap to vectors will always work though, because guides
    and vectors are always visible off-canvas (even when "Show All" is OFF).
    They always have been (visible, not snappable off-canvas; now they are
    both).
    
    (cherry picked from commit 82438728fb220d840db2eccfcba9859d326e6beb)

 app/core/gimpimage-snap.c      | 14 ++++++++++----
 app/core/gimpimage-snap.h      |  3 ++-
 app/display/gimpdisplayshell.c |  3 ++-
 3 files changed, 14 insertions(+), 6 deletions(-)
---
diff --git a/app/core/gimpimage-snap.c b/app/core/gimpimage-snap.c
index b4b1af6822..e35b646560 100644
--- a/app/core/gimpimage-snap.c
+++ b/app/core/gimpimage-snap.c
@@ -221,7 +221,8 @@ gimp_image_snap_point (GimpImage *image,
                        gboolean   snap_to_guides,
                        gboolean   snap_to_grid,
                        gboolean   snap_to_canvas,
-                       gboolean   snap_to_vectors)
+                       gboolean   snap_to_vectors,
+                       gboolean   show_all)
 {
   gdouble  mindist_x = G_MAXDOUBLE;
   gdouble  mindist_y = G_MAXDOUBLE;
@@ -241,10 +242,15 @@ gimp_image_snap_point (GimpImage *image,
   if (! (snap_to_guides || snap_to_grid || snap_to_canvas || snap_to_vectors))
     return FALSE;
 
-  if (x < -epsilon_x || x >= (gimp_image_get_width  (image) + epsilon_x) ||
-      y < -epsilon_y || y >= (gimp_image_get_height (image) + epsilon_y))
+  if (! show_all &&
+      (x < -epsilon_x || x >= (gimp_image_get_width  (image) + epsilon_x) ||
+       y < -epsilon_y || y >= (gimp_image_get_height (image) + epsilon_y)))
     {
-      return FALSE;
+      /* Off-canvas grid is invisible unless "show all" option is
+       * enabled. So let's not snap to the invisible grid.
+       */
+      snap_to_grid   = FALSE;
+      snap_to_canvas = FALSE;
     }
 
   if (snap_to_guides)
diff --git a/app/core/gimpimage-snap.h b/app/core/gimpimage-snap.h
index 70cca42d81..b0d5e4b3dd 100644
--- a/app/core/gimpimage-snap.h
+++ b/app/core/gimpimage-snap.h
@@ -43,7 +43,8 @@ gboolean    gimp_image_snap_point     (GimpImage *image,
                                        gboolean   snap_to_guides,
                                        gboolean   snap_to_grid,
                                        gboolean   snap_to_canvas,
-                                       gboolean   snap_to_vectors);
+                                       gboolean   snap_to_vectors,
+                                       gboolean   show_all);
 gboolean    gimp_image_snap_rectangle (GimpImage *image,
                                        gdouble    x1,
                                        gdouble    y1,
diff --git a/app/display/gimpdisplayshell.c b/app/display/gimpdisplayshell.c
index 6db94e471f..9603e4fae4 100644
--- a/app/display/gimpdisplayshell.c
+++ b/app/display/gimpdisplayshell.c
@@ -1717,7 +1717,8 @@ gimp_display_shell_snap_coords (GimpDisplayShell *shell,
                                            snap_to_guides,
                                            snap_to_grid,
                                            snap_to_canvas,
-                                           snap_to_vectors);
+                                           snap_to_vectors,
+                                           shell->show_all);
         }
 
       if (snapped)


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