[gimp] app: improve elimination of trivial blend-tool edit actions



commit 6036217d20b8a292e2c678286a8b29a26b2514d4
Author: Ell <ell_se yahoo com>
Date:   Thu Nov 16 11:08:15 2017 -0500

    app: improve elimination of trivial blend-tool edit actions
    
    ... from the undo stack
    
    When a blend-tool edit action modifies the gradient, do a deep
    comparison of the original gradient against the current gradient,
    to test if anything changed, instead of just assuming that
    something did change.

 app/core/gimpgradient.c          |    2 +-
 app/tools/gimpblendtool-editor.c |   42 ++++++++++++++++++++++++++++++++-----
 2 files changed, 37 insertions(+), 7 deletions(-)
---
diff --git a/app/core/gimpgradient.c b/app/core/gimpgradient.c
index 8ea80f6..a84e6f0 100644
--- a/app/core/gimpgradient.c
+++ b/app/core/gimpgradient.c
@@ -694,7 +694,7 @@ gimp_gradient_segment_new (void)
 {
   GimpGradientSegment *seg;
 
-  seg = g_slice_new (GimpGradientSegment);
+  seg = g_slice_new0 (GimpGradientSegment);
 
   seg->left   = 0.0;
   seg->middle = 0.5;
diff --git a/app/tools/gimpblendtool-editor.c b/app/tools/gimpblendtool-editor.c
index 4a2fb8f..0c323c4 100644
--- a/app/tools/gimpblendtool-editor.c
+++ b/app/tools/gimpblendtool-editor.c
@@ -198,6 +198,8 @@ static void                  gimp_blend_tool_editor_blend_info_free
 static void                  gimp_blend_tool_editor_blend_info_apply              (GimpBlendTool         
*blend_tool,
                                                                                    const BlendInfo       
*info,
                                                                                    gboolean               
set_selection);
+static gboolean              gimp_blend_tool_editor_blend_info_is_trivial         (GimpBlendTool         
*blend_tool,
+                                                                                   const BlendInfo       
*info);
 
 
 /*  private functions  */
@@ -2033,6 +2035,38 @@ gimp_blend_tool_editor_blend_info_apply (GimpBlendTool   *blend_tool,
   gimp_blend_tool_editor_unblock_handlers (blend_tool);
 }
 
+static gboolean
+gimp_blend_tool_editor_blend_info_is_trivial (GimpBlendTool   *blend_tool,
+                                              const BlendInfo *info)
+{
+  const GimpGradientSegment *seg1;
+  const GimpGradientSegment *seg2;
+
+  if (info->start_x != blend_tool->start_x ||
+      info->start_y != blend_tool->start_y ||
+      info->end_x   != blend_tool->end_x   ||
+      info->end_y   != blend_tool->end_y)
+    {
+      return FALSE;
+    }
+
+  if (info->gradient)
+    {
+      for (seg1 = info->gradient->segments, seg2 = blend_tool->gradient->segments;
+           seg1 && seg2;
+           seg1 = seg1->next, seg2 = seg2->next)
+        {
+          if (memcmp (seg1, seg2, G_STRUCT_OFFSET (GimpGradientSegment, prev)))
+            return FALSE;
+        }
+
+      if (seg1 || seg2)
+        return FALSE;
+    }
+
+  return TRUE;
+}
+
 
 /*  public functions  */
 
@@ -2409,12 +2443,8 @@ gimp_blend_tool_editor_end_edit (GimpBlendTool *blend_tool,
       info->selected_handle =
         gimp_tool_line_get_selection (GIMP_TOOL_LINE (blend_tool->widget));
 
-      if (cancel                                ||
-          (info->start_x == blend_tool->start_x &&
-           info->start_y == blend_tool->start_y &&
-           info->end_x   == blend_tool->end_x   &&
-           info->end_y   == blend_tool->end_y   &&
-           ! info->gradient))
+      if (cancel ||
+          gimp_blend_tool_editor_blend_info_is_trivial (blend_tool, info))
         {
           /* if the edit is canceled, or if nothing changed, undo the last
            * step


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