[gimp] app: in warp tool, avoid nop strokes with the MOVE behavior



commit 3814ac9056fff2504c909e9eb1effdeb8668bdb8
Author: Ell <ell_se yahoo com>
Date:   Wed May 17 12:18:12 2017 -0400

    app: in warp tool, avoid nop strokes with the MOVE behavior
    
    When using the MOVE behavior, don't append the current cursor
    position to the stroke path in the timeout proc if the cursor
    hasn't moved since last time.  It has no effect, except for
    requiring an unnecessary update.

 app/tools/gimpwarptool.c |   27 ++++++++++++++++++++-------
 app/tools/gimpwarptool.h |    1 +
 2 files changed, 21 insertions(+), 7 deletions(-)
---
diff --git a/app/tools/gimpwarptool.c b/app/tools/gimpwarptool.c
index 1216fe8..674a2b9 100644
--- a/app/tools/gimpwarptool.c
+++ b/app/tools/gimpwarptool.c
@@ -265,6 +265,8 @@ gimp_warp_tool_button_press (GimpTool            *tool,
   gegl_path_append (wt->current_stroke,
                     'M', coords->x - off_x, coords->y - off_y);
 
+  wt->cursor_moved = FALSE;
+
   wt->stroke_timer = g_timeout_add (STROKE_PERIOD,
                                     (GSourceFunc) gimp_warp_tool_stroke_timer,
                                     wt);
@@ -339,8 +341,9 @@ gimp_warp_tool_motion (GimpTool         *tool,
 
   gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
 
-  wt->cursor_x = coords->x;
-  wt->cursor_y = coords->y;
+  wt->cursor_x     = coords->x;
+  wt->cursor_y     = coords->y;
+  wt->cursor_moved = TRUE;
 
   gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
 }
@@ -702,13 +705,23 @@ gimp_warp_tool_commit (GimpWarpTool *wt)
 static gboolean
 gimp_warp_tool_stroke_timer (GimpWarpTool *wt)
 {
-  GimpTool *tool = GIMP_TOOL (wt);
-  gint      off_x, off_y;
+  GimpTool        *tool = GIMP_TOOL (wt);
+  GimpWarpOptions *options = GIMP_WARP_TOOL_GET_OPTIONS (wt);
+  gint             off_x, off_y;
 
-  gimp_item_get_offset (GIMP_ITEM (tool->drawable), &off_x, &off_y);
+  /* don't append the current point to the path if we're using the MOVE
+   * behavior, and the cursor didn't move since last time; it's a nop, and
+   * results in an unnecessary update.
+   */
+  if (options->behavior != GIMP_WARP_BEHAVIOR_MOVE || wt->cursor_moved)
+    {
+      gimp_item_get_offset (GIMP_ITEM (tool->drawable), &off_x, &off_y);
 
-  gegl_path_append (wt->current_stroke,
-                    'L', wt->cursor_x - off_x, wt->cursor_y - off_y);
+      gegl_path_append (wt->current_stroke,
+                        'L', wt->cursor_x - off_x, wt->cursor_y - off_y);
+
+      wt->cursor_moved = FALSE;
+    }
 
   return TRUE;
 }
diff --git a/app/tools/gimpwarptool.h b/app/tools/gimpwarptool.h
index 932f43a..627e022 100644
--- a/app/tools/gimpwarptool.h
+++ b/app/tools/gimpwarptool.h
@@ -43,6 +43,7 @@ struct _GimpWarpTool
 
   gdouble             cursor_x;      /* Hold the cursor x position */
   gdouble             cursor_y;      /* Hold the cursor y position */
+  gboolean            cursor_moved;  /* Did the cursor move since the last stroke? */
 
   GeglBuffer         *coords_buffer; /* Buffer where coordinates are stored */
 


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