[gimp/gimp-2-10] app: fix use of Clone tool with "sample merged" across images



commit b8177906a2a0224a912ca1f9f93ff88284ada919
Author: Ell <ell_se yahoo com>
Date:   Wed Oct 2 17:08:45 2019 +0300

    app: fix use of Clone tool with "sample merged" across images
    
    In GimpSourceCore, when "sample merged" is enabled, derive the
    source pickable from the source drawable's image according to the
    paint-core's show-all flag manually, instead of using
    gimp_paint_core_get_image_pickable(), which uses the destination
    image, and would therefore only work when the source and
    destination images are the same.
    
    In GimpSourceTool, override GimpPaintTool::paint_prepare() to set
    the paint-core's show-all flag according to the source display,
    rather than the destination display.
    
    (cherry picked from commit aa02f1f35c685325ad3c85d1a74521d2d35df601)

 app/paint/gimpsourcecore.c | 13 ++++++++++--
 app/tools/gimpsourcetool.c | 52 ++++++++++++++++++++++++++++++++++------------
 2 files changed, 50 insertions(+), 15 deletions(-)
---
diff --git a/app/paint/gimpsourcecore.c b/app/paint/gimpsourcecore.c
index f0ca584215..94238ad32f 100644
--- a/app/paint/gimpsourcecore.c
+++ b/app/paint/gimpsourcecore.c
@@ -408,9 +408,18 @@ gimp_source_core_motion (GimpSourceCore   *source_core,
 
       if (options->sample_merged)
         {
-          gint off_x, off_y;
+          GimpImage *src_image = gimp_pickable_get_image (src_pickable);
+          gint       off_x, off_y;
 
-          src_pickable = gimp_paint_core_get_image_pickable (paint_core);
+          if (! gimp_paint_core_get_show_all (paint_core))
+            {
+              src_pickable = GIMP_PICKABLE (src_image);
+            }
+          else
+            {
+              src_pickable = GIMP_PICKABLE (
+                gimp_image_get_projection (src_image));
+            }
 
           gimp_item_get_offset (GIMP_ITEM (source_core->src_drawable),
                                 &off_x, &off_y);
diff --git a/app/tools/gimpsourcetool.c b/app/tools/gimpsourcetool.c
index 9293f500ee..9d9f725182 100644
--- a/app/tools/gimpsourcetool.c
+++ b/app/tools/gimpsourcetool.c
@@ -35,6 +35,7 @@
 
 #include "display/gimpcanvashandle.h"
 #include "display/gimpdisplay.h"
+#include "display/gimpdisplayshell.h"
 #include "display/gimpdisplayshell-items.h"
 
 #include "gimpsourcetool.h"
@@ -78,6 +79,9 @@ static void          gimp_source_tool_oper_update   (GimpTool            *tool,
 
 static void          gimp_source_tool_draw          (GimpDrawTool        *draw_tool);
 
+static void          gimp_source_tool_paint_prepare (GimpPaintTool       *paint_tool,
+                                                     GimpDisplay         *display);
+
 static void          gimp_source_tool_set_src_display (GimpSourceTool      *source_tool,
                                                        GimpDisplay         *display);
 
@@ -90,19 +94,22 @@ G_DEFINE_TYPE (GimpSourceTool, gimp_source_tool, GIMP_TYPE_BRUSH_TOOL)
 static void
 gimp_source_tool_class_init (GimpSourceToolClass *klass)
 {
-  GimpToolClass     *tool_class      = GIMP_TOOL_CLASS (klass);
-  GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
-
-  tool_class->has_display   = gimp_source_tool_has_display;
-  tool_class->has_image     = gimp_source_tool_has_image;
-  tool_class->control       = gimp_source_tool_control;
-  tool_class->button_press  = gimp_source_tool_button_press;
-  tool_class->motion        = gimp_source_tool_motion;
-  tool_class->modifier_key  = gimp_source_tool_modifier_key;
-  tool_class->oper_update   = gimp_source_tool_oper_update;
-  tool_class->cursor_update = gimp_source_tool_cursor_update;
-
-  draw_tool_class->draw     = gimp_source_tool_draw;
+  GimpToolClass      *tool_class       = GIMP_TOOL_CLASS (klass);
+  GimpDrawToolClass  *draw_tool_class  = GIMP_DRAW_TOOL_CLASS (klass);
+  GimpPaintToolClass *paint_tool_class = GIMP_PAINT_TOOL_CLASS (klass);
+
+  tool_class->has_display         = gimp_source_tool_has_display;
+  tool_class->has_image           = gimp_source_tool_has_image;
+  tool_class->control             = gimp_source_tool_control;
+  tool_class->button_press        = gimp_source_tool_button_press;
+  tool_class->motion              = gimp_source_tool_motion;
+  tool_class->modifier_key        = gimp_source_tool_modifier_key;
+  tool_class->oper_update         = gimp_source_tool_oper_update;
+  tool_class->cursor_update       = gimp_source_tool_cursor_update;
+
+  draw_tool_class->draw           = gimp_source_tool_draw;
+
+  paint_tool_class->paint_prepare = gimp_source_tool_paint_prepare;
 }
 
 static void
@@ -461,6 +468,25 @@ gimp_source_tool_draw (GimpDrawTool *draw_tool)
     }
 }
 
+static void
+gimp_source_tool_paint_prepare (GimpPaintTool *paint_tool,
+                                GimpDisplay   *display)
+{
+  GimpSourceTool *source_tool = GIMP_SOURCE_TOOL (paint_tool);
+
+  if (GIMP_PAINT_TOOL_CLASS (parent_class)->paint_prepare)
+    GIMP_PAINT_TOOL_CLASS (parent_class)->paint_prepare (paint_tool, display);
+
+  if (source_tool->src_display)
+    {
+      GimpDisplayShell *src_shell;
+
+      src_shell = gimp_display_get_shell (source_tool->src_display);
+
+      gimp_paint_core_set_show_all (paint_tool->core, src_shell->show_all);
+    }
+}
+
 static void
 gimp_source_tool_set_src_display (GimpSourceTool *source_tool,
                                   GimpDisplay    *display)


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