[gimp] app: add gimp_paint_tool_set_active()



commit 05dd5029ee368d4bf6115822c0b68638d536f2cc
Author: Ell <ell_se yahoo com>
Date:   Thu Jan 31 06:15:53 2019 -0500

    app: add gimp_paint_tool_set_active()
    
    ... which can use to enable/disable certain aspects of
    GimpPaintTool (in particular, brush-outline drawing).  Should be
    used by subclasses, to temporarily disable the paint tool while in
    a non-paint mode (currently, this is only needed by the
    perspective-clone tool; see next commit.)

 app/tools/gimppainttool.c | 50 +++++++++++++++++++++++++++++++++++++----------
 app/tools/gimppainttool.h |  4 ++++
 2 files changed, 44 insertions(+), 10 deletions(-)
---
diff --git a/app/tools/gimppainttool.c b/app/tools/gimppainttool.c
index b303831019..f9ee67332a 100644
--- a/app/tools/gimppainttool.c
+++ b/app/tools/gimppainttool.c
@@ -111,7 +111,7 @@ static gboolean  gimp_paint_tool_check_alpha (GimpPaintTool         *paint_tool,
 
 static void   gimp_paint_tool_hard_notify    (GimpPaintOptions      *options,
                                               const GParamSpec      *pspec,
-                                              GimpTool              *tool);
+                                              GimpPaintTool         *paint_tool);
 static void   gimp_paint_tool_cursor_notify  (GimpDisplayConfig     *config,
                                               GParamSpec            *pspec,
                                               GimpPaintTool         *paint_tool);
@@ -153,6 +153,7 @@ gimp_paint_tool_init (GimpPaintTool *paint_tool)
   gimp_tool_control_set_action_opacity (tool->control,
                                         "context/context-opacity-set");
 
+  paint_tool->active        = TRUE;
   paint_tool->pick_colors   = FALSE;
   paint_tool->draw_line     = FALSE;
 
@@ -196,9 +197,9 @@ gimp_paint_tool_constructed (GObject *object)
 
   g_signal_connect_object (options, "notify::hard",
                            G_CALLBACK (gimp_paint_tool_hard_notify),
-                           tool, 0);
+                           paint_tool, 0);
 
-  gimp_paint_tool_hard_notify (options, NULL, tool);
+  gimp_paint_tool_hard_notify (options, NULL, paint_tool);
 
   paint_tool->show_cursor = display_config->show_paint_tool_cursor;
   paint_tool->draw_brush  = display_config->show_brush_outline;
@@ -657,9 +658,12 @@ gimp_paint_tool_oper_update (GimpTool         *tool,
 static void
 gimp_paint_tool_draw (GimpDrawTool *draw_tool)
 {
-  if (! gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (draw_tool)))
+  GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (draw_tool);
+
+
+  if (paint_tool->active &&
+      ! gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (draw_tool)))
     {
-      GimpPaintTool  *paint_tool = GIMP_PAINT_TOOL (draw_tool);
       GimpPaintCore  *core       = paint_tool->core;
       GimpImage      *image      = gimp_display_get_image (draw_tool->display);
       GimpDrawable   *drawable   = gimp_image_get_active_drawable (image);
@@ -860,12 +864,17 @@ gimp_paint_tool_check_alpha (GimpPaintTool  *paint_tool,
 static void
 gimp_paint_tool_hard_notify (GimpPaintOptions *options,
                              const GParamSpec *pspec,
-                             GimpTool         *tool)
+                             GimpPaintTool    *paint_tool)
 {
-  gimp_tool_control_set_precision (tool->control,
-                                   options->hard ?
-                                   GIMP_CURSOR_PRECISION_PIXEL_CENTER :
-                                   GIMP_CURSOR_PRECISION_SUBPIXEL);
+  if (paint_tool->active)
+    {
+      GimpTool *tool = GIMP_TOOL (paint_tool);
+
+      gimp_tool_control_set_precision (tool->control,
+                                       options->hard ?
+                                       GIMP_CURSOR_PRECISION_PIXEL_CENTER :
+                                       GIMP_CURSOR_PRECISION_SUBPIXEL);
+    }
 }
 
 static void
@@ -881,6 +890,27 @@ gimp_paint_tool_cursor_notify (GimpDisplayConfig *config,
   gimp_draw_tool_resume (GIMP_DRAW_TOOL (paint_tool));
 }
 
+void
+gimp_paint_tool_set_active (GimpPaintTool *tool,
+                            gboolean       active)
+{
+  g_return_if_fail (GIMP_IS_PAINT_TOOL (tool));
+
+  if (active != tool->active)
+    {
+      GimpPaintOptions *options = GIMP_PAINT_TOOL_GET_OPTIONS (tool);
+
+      gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
+
+      tool->active = active;
+
+      if (active)
+        gimp_paint_tool_hard_notify (options, NULL, tool);
+
+      gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
+    }
+}
+
 /**
  * gimp_paint_tool_enable_color_picker:
  * @tool:   a #GimpPaintTool
diff --git a/app/tools/gimppainttool.h b/app/tools/gimppainttool.h
index 387239e7f4..dc383cc9b5 100644
--- a/app/tools/gimppainttool.h
+++ b/app/tools/gimppainttool.h
@@ -41,6 +41,7 @@ struct _GimpPaintTool
 {
   GimpColorTool  parent_instance;
 
+  gboolean       active;
   gboolean       pick_colors;  /*  pick color if ctrl is pressed   */
   gboolean       draw_line;
 
@@ -84,6 +85,9 @@ struct _GimpPaintToolClass
 
 GType   gimp_paint_tool_get_type            (void) G_GNUC_CONST;
 
+void    gimp_paint_tool_set_active          (GimpPaintTool       *tool,
+                                             gboolean             active);
+
 void    gimp_paint_tool_enable_color_picker (GimpPaintTool       *tool,
                                              GimpColorPickTarget  target);
 


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