[gimp] app: constrain line angles in display space, not image space



commit 984ed6cefda5df921777c8530d4ea8f51a52977c
Author: Ell <ell_se yahoo com>
Date:   Fri Dec 22 05:56:11 2017 -0500

    app: constrain line angles in display space, not image space
    
    Add an offset_angle parameter to gimp_constrain_line(), which
    offsets the radial lines by a given angle.
    
    Add gimpdisplayshell-utils.[ch], with two new functions:
    
      - gimp_display_shell_get_constrained_line_offset_angle():
        Returns the offset angle to be passed to
        gimp_constrain_line(), in order to constrain line angles in
        display space, according to the shell's rotation angle and
        flip mode.
    
      - gimp_display_shell_constrain_line():  A convenience function
        which calls gimp_constrain_line() with the said offset angle.
    
    Use the new functions in all instances where we constrain line
    angles, so that angles are constrained in display space, rather
    than image space.
    
    The only exception is GimpEditSelectionTool, which keeps
    constraining angles in image space, since it's not entirely obvious
    that we want to constrain angles of dragged layers/selections in
    display space.

 app/core/gimp-utils.c             |    7 +++++--
 app/core/gimp-utils.h             |    3 ++-
 app/display/Makefile.am           |    2 ++
 app/display/gimptoolcompass.c     |   17 +++++++++++------
 app/display/gimptoolline.c        |   21 +++++++++++++++------
 app/display/gimptoolpolygon.c     |   23 ++++++++++++++---------
 app/paint/gimppaintcore.c         |    6 ++++--
 app/paint/gimppaintcore.h         |    3 ++-
 app/tools/gimpeditselectiontool.c |    2 +-
 app/tools/gimppainttool.c         |   12 +++++++++---
 10 files changed, 65 insertions(+), 31 deletions(-)
---
diff --git a/app/core/gimp-utils.c b/app/core/gimp-utils.c
index ba2f9c0..0414cb9 100644
--- a/app/core/gimp-utils.c
+++ b/app/core/gimp-utils.c
@@ -610,6 +610,7 @@ gimp_utils_point_to_line_distance (const GimpVector2 *point,
  * @end_x:
  * @end_y:
  * @n_snap_lines: Number evenly disributed lines to snap to.
+ * @offset_angle: The angle by which to offset the lines, in degrees.
  *
  * Projects a line onto the specified subset of evenly radially
  * distributed lines. @n_lines of 2 makes the line snap horizontally
@@ -621,7 +622,8 @@ gimp_constrain_line (gdouble  start_x,
                      gdouble  start_y,
                      gdouble *end_x,
                      gdouble *end_y,
-                     gint     n_snap_lines)
+                     gint     n_snap_lines,
+                     gdouble  offset_angle)
 {
   GimpVector2 line_point          = {  start_x,  start_y };
   GimpVector2 point               = { *end_x,   *end_y   };
@@ -634,7 +636,8 @@ gimp_constrain_line (gdouble  start_x,
 
   for (i = 0; i < n_snap_lines; i++)
     {
-      angle = i * G_PI / n_snap_lines;
+      angle  = i * G_PI / n_snap_lines;
+      angle += offset_angle * G_PI / 180.0;
 
       gimp_vector2_set (&line_dir,
                         cos (angle),
diff --git a/app/core/gimp-utils.h b/app/core/gimp-utils.h
index 5e3c1ee..4c87949 100644
--- a/app/core/gimp-utils.h
+++ b/app/core/gimp-utils.h
@@ -71,7 +71,8 @@ void         gimp_constrain_line                   (gdouble          start_x,
                                                     gdouble          start_y,
                                                     gdouble         *end_x,
                                                     gdouble         *end_y,
-                                                    gint             n_snap_lines);
+                                                    gint             n_snap_lines,
+                                                    gdouble          offset_angle);
 
 gint         gimp_file_compare                     (GFile           *file1,
                                                     GFile           *file2);
diff --git a/app/display/Makefile.am b/app/display/Makefile.am
index 2851dcb..5df014e 100644
--- a/app/display/Makefile.am
+++ b/app/display/Makefile.am
@@ -144,6 +144,8 @@ libappdisplay_a_sources = \
        gimpdisplayshell-tool-events.h          \
        gimpdisplayshell-transform.c            \
        gimpdisplayshell-transform.h            \
+       gimpdisplayshell-utils.c                \
+       gimpdisplayshell-utils.h                \
        gimpdisplayxfer.c                       \
        gimpdisplayxfer.h                       \
        gimpimagewindow.c                       \
diff --git a/app/display/gimptoolcompass.c b/app/display/gimptoolcompass.c
index 3bdf5a3..1abb50f 100644
--- a/app/display/gimptoolcompass.c
+++ b/app/display/gimptoolcompass.c
@@ -42,6 +42,7 @@
 #include "gimpdisplay.h"
 #include "gimpdisplayshell.h"
 #include "gimpdisplayshell-appearance.h"
+#include "gimpdisplayshell-utils.h"
 #include "gimptoolcompass.h"
 
 #include "gimp-intl.h"
@@ -736,9 +737,10 @@ gimp_tool_compass_motion (GimpToolWidget   *widget,
           gdouble  x = new_x[private->point];
           gdouble  y = new_y[private->point];
 
-          gimp_constrain_line (new_x[0], new_y[0],
-                               &x, &y,
-                               GIMP_CONSTRAIN_LINE_15_DEGREES);
+          gimp_display_shell_constrain_line (gimp_tool_widget_get_shell (widget),
+                                             new_x[0], new_y[0],
+                                             &x, &y,
+                                             GIMP_CONSTRAIN_LINE_15_DEGREES);
 
           new_x[private->point] = ROUND (x);
           new_y[private->point] = ROUND (y);
@@ -909,9 +911,12 @@ gimp_tool_compass_motion_modifier (GimpToolWidget  *widget,
       new_y[2] = private->y[2];
 
       if (press)
-        gimp_constrain_line (private->x[0], private->y[0],
-                             &x, &y,
-                             GIMP_CONSTRAIN_LINE_15_DEGREES);
+        {
+          gimp_display_shell_constrain_line (gimp_tool_widget_get_shell (widget),
+                                             private->x[0], private->y[0],
+                                             &x, &y,
+                                             GIMP_CONSTRAIN_LINE_15_DEGREES);
+        }
 
       new_x[private->point] = ROUND (x);
       new_y[private->point] = ROUND (y);
diff --git a/app/display/gimptoolline.c b/app/display/gimptoolline.c
index 5fc70b5..21f1096 100644
--- a/app/display/gimptoolline.c
+++ b/app/display/gimptoolline.c
@@ -42,6 +42,7 @@
 #include "gimpcanvasline.h"
 #include "gimpdisplayshell.h"
 #include "gimpdisplayshell-cursor.h"
+#include "gimpdisplayshell-utils.h"
 #include "gimptoolline.h"
 
 #include "gimp-intl.h"
@@ -1201,9 +1202,13 @@ gimp_tool_line_selection_motion (GimpToolLine *line,
 
     case GIMP_TOOL_LINE_HANDLE_START:
       if (constrain)
-        gimp_constrain_line (private->x2, private->y2,
-                             &x, &y,
-                             GIMP_CONSTRAIN_LINE_15_DEGREES);
+        {
+          gimp_display_shell_constrain_line (
+            gimp_tool_widget_get_shell (GIMP_TOOL_WIDGET (line)),
+            private->x2, private->y2,
+            &x, &y,
+            GIMP_CONSTRAIN_LINE_15_DEGREES);
+        }
 
       g_object_set (line,
                     "x1", x,
@@ -1213,9 +1218,13 @@ gimp_tool_line_selection_motion (GimpToolLine *line,
 
     case GIMP_TOOL_LINE_HANDLE_END:
       if (constrain)
-        gimp_constrain_line (private->x1, private->y1,
-                             &x, &y,
-                             GIMP_CONSTRAIN_LINE_15_DEGREES);
+        {
+          gimp_display_shell_constrain_line (
+            gimp_tool_widget_get_shell (GIMP_TOOL_WIDGET (line)),
+            private->x1, private->y1,
+            &x, &y,
+            GIMP_CONSTRAIN_LINE_15_DEGREES);
+        }
 
       g_object_set (line,
                     "x2", x,
diff --git a/app/display/gimptoolpolygon.c b/app/display/gimptoolpolygon.c
index c836fa4..655bcae 100644
--- a/app/display/gimptoolpolygon.c
+++ b/app/display/gimptoolpolygon.c
@@ -44,6 +44,7 @@
 #include "gimpcanvasline.h"
 #include "gimpcanvaspolygon.h"
 #include "gimpdisplayshell.h"
+#include "gimpdisplayshell-utils.h"
 #include "gimptoolpolygon.h"
 
 #include "gimp-intl.h"
@@ -812,11 +813,13 @@ gimp_tool_polygon_update_motion (GimpToolPolygon *polygon,
                                                &start_point_y,
                                                segment_index);
 
-          gimp_constrain_line (start_point_x,
-                               start_point_y,
-                               &new_x,
-                               &new_y,
-                               GIMP_CONSTRAIN_LINE_15_DEGREES);
+          gimp_display_shell_constrain_line (
+            gimp_tool_widget_get_shell (GIMP_TOOL_WIDGET (polygon)),
+            start_point_x,
+            start_point_y,
+            &new_x,
+            &new_y,
+            GIMP_CONSTRAIN_LINE_15_DEGREES);
         }
 
       gimp_tool_polygon_move_segment_vertex_to (polygon,
@@ -1262,10 +1265,12 @@ gimp_tool_polygon_hover (GimpToolWidget   *widget,
                                                    &start_point_y,
                                                    priv->n_segment_indices - 1);
 
-              gimp_constrain_line (start_point_x, start_point_y,
-                                   &priv->pending_point.x,
-                                   &priv->pending_point.y,
-                                   GIMP_CONSTRAIN_LINE_15_DEGREES);
+              gimp_display_shell_constrain_line (
+                gimp_tool_widget_get_shell (widget),
+                start_point_x, start_point_y,
+                &priv->pending_point.x,
+                &priv->pending_point.y,
+                GIMP_CONSTRAIN_LINE_15_DEGREES);
             }
         }
     }
diff --git a/app/paint/gimppaintcore.c b/app/paint/gimppaintcore.c
index b70efc0..5b740b1 100644
--- a/app/paint/gimppaintcore.c
+++ b/app/paint/gimppaintcore.c
@@ -687,7 +687,8 @@ gimp_paint_core_get_last_coords (GimpPaintCore *core,
 void
 gimp_paint_core_round_line (GimpPaintCore    *core,
                             GimpPaintOptions *paint_options,
-                            gboolean          constrain_15_degrees)
+                            gboolean          constrain_15_degrees,
+                            gdouble           constrain_offset_angle)
 {
   g_return_if_fail (GIMP_IS_PAINT_CORE (core));
   g_return_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options));
@@ -703,7 +704,8 @@ gimp_paint_core_round_line (GimpPaintCore    *core,
   if (constrain_15_degrees)
     gimp_constrain_line (core->last_coords.x, core->last_coords.y,
                          &core->cur_coords.x, &core->cur_coords.y,
-                         GIMP_CONSTRAIN_LINE_15_DEGREES);
+                         GIMP_CONSTRAIN_LINE_15_DEGREES,
+                         constrain_offset_angle);
 }
 
 
diff --git a/app/paint/gimppaintcore.h b/app/paint/gimppaintcore.h
index 26a8550..4fe024a 100644
--- a/app/paint/gimppaintcore.h
+++ b/app/paint/gimppaintcore.h
@@ -159,7 +159,8 @@ void      gimp_paint_core_get_last_coords           (GimpPaintCore    *core,
 
 void      gimp_paint_core_round_line                (GimpPaintCore    *core,
                                                      GimpPaintOptions *options,
-                                                     gboolean          constrain_15_degrees);
+                                                     gboolean          constrain_15_degrees,
+                                                     gdouble           constrain_offset_angle);
 
 
 /*  protected functions  */
diff --git a/app/tools/gimpeditselectiontool.c b/app/tools/gimpeditselectiontool.c
index a3d2ea1..245e730 100644
--- a/app/tools/gimpeditselectiontool.c
+++ b/app/tools/gimpeditselectiontool.c
@@ -521,7 +521,7 @@ gimp_edit_selection_tool_update_motion (GimpEditSelectionTool *edit_select,
     {
       gimp_constrain_line (edit_select->start_x, edit_select->start_y,
                            &new_x, &new_y,
-                           GIMP_CONSTRAIN_LINE_45_DEGREES);
+                           GIMP_CONSTRAIN_LINE_45_DEGREES, 0.0);
     }
 
   gimp_edit_selection_tool_calc_coords (edit_select, image,
diff --git a/app/tools/gimppainttool.c b/app/tools/gimppainttool.c
index b4154be..a694d8d 100644
--- a/app/tools/gimppainttool.c
+++ b/app/tools/gimppainttool.c
@@ -45,6 +45,7 @@
 #include "display/gimpdisplay.h"
 #include "display/gimpdisplayshell.h"
 #include "display/gimpdisplayshell-selection.h"
+#include "display/gimpdisplayshell-utils.h"
 
 #include "gimpcoloroptions.h"
 #include "gimppainttool.h"
@@ -337,7 +338,10 @@ gimp_paint_tool_button_press (GimpTool            *tool,
       /*  If shift is down and this is not the first paint
        *  stroke, then draw a line from the last coords to the pointer
        */
-      gimp_paint_core_round_line (core, paint_options, constrain);
+      gimp_paint_core_round_line (
+        core, paint_options,
+        constrain,
+        gimp_display_shell_get_constrained_line_offset_angle (shell));
     }
 
   tool->display  = display;
@@ -646,8 +650,10 @@ gimp_paint_tool_oper_update (GimpTool         *tool,
           gdouble  yres;
           gdouble  angle;
 
-          gimp_paint_core_round_line (core, paint_options,
-                                      (state & constrain_mask) != 0);
+          gimp_paint_core_round_line (
+            core, paint_options,
+            (state & constrain_mask) != 0,
+            gimp_display_shell_get_constrained_line_offset_angle (shell));
 
           dx = core->cur_coords.x - core->last_coords.x;
           dy = core->cur_coords.y - core->last_coords.y;


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