[gimp/gimp-2-10] app: make GimpBucketFillTool a GimpColorTool.



commit 73b348de1c743997ce8a7d9636d45efd3c609599
Author: Jehan <jehan girinstud io>
Date:   Tue Nov 27 17:25:05 2018 +0100

    app: make GimpBucketFillTool a GimpColorTool.
    
    In particular, it allows to easily color pick. This just makes sense as
    the bucket fill is definitely what one could call a "color tool", and
    being able to easily change color without having to constantly switch to
    color picker tool nor open a color chooser dialog is a must.
    
    The fill type option (FG/BG/Pattern) was already mapped to the common
    toggle behavior key (Ctrl on Linux), which is commonly used for
    switching to color picker on paint tools. So I decided to remap the fill
    type switch to GDK_MOD1_MASK (Alt on Linux) to keep consistent with
    other tools (at the price of a change for anyone used to this modifier,
    though I doubt it was that much used).
    I also made possible to combine the 2 modifiers (so you could pick the
    foreground or background color with ctrl and ctrl-alt).
    
    (cherry picked from commit 5d4281944fa085f64b7e6423bca2b9f31b400905)

 app/tools/gimpbucketfilloptions.c |  2 +-
 app/tools/gimpbucketfilltool.c    | 88 ++++++++++++++++++++++++++++++++++++++-
 app/tools/gimpbucketfilltool.h    |  6 +--
 3 files changed, 90 insertions(+), 6 deletions(-)
---
diff --git a/app/tools/gimpbucketfilloptions.c b/app/tools/gimpbucketfilloptions.c
index a5e7726492..f5d604e6bf 100644
--- a/app/tools/gimpbucketfilloptions.c
+++ b/app/tools/gimpbucketfilloptions.c
@@ -344,7 +344,7 @@ gimp_bucket_fill_options_gui (GimpToolOptions *tool_options)
   GtkWidget             *combo;
   gchar                 *str;
   GdkModifierType        extend_mask = gimp_get_extend_selection_mask ();
-  GdkModifierType        toggle_mask = gimp_get_toggle_behavior_mask ();
+  GdkModifierType        toggle_mask = GDK_MOD1_MASK;
 
   /*  fill type  */
   str = g_strdup_printf (_("Fill Type  (%s)"),
diff --git a/app/tools/gimpbucketfilltool.c b/app/tools/gimpbucketfilltool.c
index 4918f0858b..913ccff7e9 100644
--- a/app/tools/gimpbucketfilltool.c
+++ b/app/tools/gimpbucketfilltool.c
@@ -39,6 +39,7 @@
 #include "core/gimppickable-contiguous-region.h"
 #include "core/gimpprogress.h"
 #include "core/gimpprojection.h"
+#include "core/gimptoolinfo.h"
 #include "core/gimpwaitable.h"
 
 #include "gegl/gimp-gegl-nodes.h"
@@ -52,6 +53,7 @@
 
 #include "gimpbucketfilloptions.h"
 #include "gimpbucketfilltool.h"
+#include "gimpcoloroptions.h"
 #include "gimptoolcontrol.h"
 #include "gimptools-utils.h"
 
@@ -144,7 +146,7 @@ static void     gimp_bucket_fill_tool_drawable_painted (GimpDrawable         *dr
                                                         GimpBucketFillTool   *tool);
 
 
-G_DEFINE_TYPE_WITH_PRIVATE (GimpBucketFillTool, gimp_bucket_fill_tool, GIMP_TYPE_TOOL)
+G_DEFINE_TYPE_WITH_PRIVATE (GimpBucketFillTool, gimp_bucket_fill_tool, GIMP_TYPE_COLOR_TOOL)
 
 #define parent_class gimp_bucket_fill_tool_parent_class
 
@@ -221,6 +223,9 @@ gimp_bucket_fill_tool_constructed (GObject *object)
     gimp_bucket_fill_tool_connect_handlers (tool);
   else
     g_idle_add (gimp_bucket_fill_tool_connect_handlers, tool);
+
+  GIMP_COLOR_TOOL (tool)->pick_target = (options->fill_mode == GIMP_BUCKET_FILL_BG) ?
+                                           GIMP_COLOR_PICK_TARGET_BACKGROUND : 
GIMP_COLOR_PICK_TARGET_FOREGROUND;
 }
 
 static void
@@ -507,6 +512,13 @@ gimp_bucket_fill_tool_button_press (GimpTool            *tool,
   GimpBucketFillOptions *options     = GIMP_BUCKET_FILL_TOOL_GET_OPTIONS (tool);
   GimpImage             *image       = gimp_display_get_image (display);
 
+  if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)))
+    {
+      GIMP_TOOL_CLASS (parent_class)->button_press (tool, coords, time, state,
+                                                    press_type, display);
+      return;
+    }
+
   if (press_type == GIMP_BUTTON_PRESS_NORMAL &&
       gimp_image_coords_in_active_pickable (image, coords,
                                             options->sample_merged, TRUE))
@@ -567,6 +579,9 @@ gimp_bucket_fill_tool_motion (GimpTool         *tool,
 
   GIMP_TOOL_CLASS (parent_class)->motion (tool, coords, time, state, display);
 
+  if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)))
+    return;
+
   if (gimp_image_coords_in_active_pickable (image, coords,
                                             options->sample_merged, TRUE) &&
       /* Fill selection only needs to happen once. */
@@ -615,6 +630,14 @@ gimp_bucket_fill_tool_button_release (GimpTool              *tool,
   GimpBucketFillTool *bucket_tool = GIMP_BUCKET_FILL_TOOL (tool);
   gboolean            commit;
 
+  if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)))
+    {
+      GIMP_TOOL_CLASS (parent_class)->button_release (tool, coords, time,
+                                                      state, release_type,
+                                                      display);
+      return;
+    }
+
   commit = (release_type != GIMP_BUTTON_RELEASE_CANCEL);
 
   if (commit)
@@ -635,7 +658,7 @@ gimp_bucket_fill_tool_modifier_key (GimpTool        *tool,
 {
   GimpBucketFillOptions *options = GIMP_BUCKET_FILL_TOOL_GET_OPTIONS (tool);
 
-  if (key == gimp_get_toggle_behavior_mask ())
+  if (key == GDK_MOD1_MASK)
     {
       switch (options->fill_mode)
         {
@@ -651,6 +674,38 @@ gimp_bucket_fill_tool_modifier_key (GimpTool        *tool,
           break;
         }
     }
+  else if (key == gimp_get_toggle_behavior_mask ())
+    {
+      GimpToolInfo *info = gimp_get_tool_info (display->gimp,
+                                               "gimp-color-picker-tool");
+      if (! gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)))
+        {
+          switch (GIMP_COLOR_TOOL (tool)->pick_target)
+            {
+            case GIMP_COLOR_PICK_TARGET_BACKGROUND:
+              gimp_tool_push_status (tool, display,
+                                     _("Click in any image to pick the "
+                                       "background color"));
+              break;
+
+            case GIMP_COLOR_PICK_TARGET_FOREGROUND:
+            default:
+              gimp_tool_push_status (tool, display,
+                                     _("Click in any image to pick the "
+                                       "foreground color"));
+              break;
+            }
+          GIMP_TOOL (tool)->display = display;
+          gimp_color_tool_enable (GIMP_COLOR_TOOL (tool),
+                                  GIMP_COLOR_OPTIONS (info->tool_options));
+        }
+      else
+        {
+          gimp_tool_pop_status (tool, display);
+          gimp_color_tool_disable (GIMP_COLOR_TOOL (tool));
+          GIMP_TOOL (tool)->display = NULL;
+        }
+    }
   else if (key == gimp_get_extend_selection_mask ())
     {
       g_object_set (options, "fill-selection", ! options->fill_selection, NULL);
@@ -805,6 +860,10 @@ gimp_bucket_fill_tool_connect_handlers (gpointer data)
                         G_CALLBACK (gimp_bucket_fill_tool_options_notified),
                         tool);
 
+      g_signal_connect (options, "notify::fill-mode",
+                        G_CALLBACK (gimp_bucket_fill_tool_options_notified),
+                        tool);
+
       g_signal_connect (context, "image-changed",
                         G_CALLBACK (gimp_bucket_fill_tool_image_changed),
                         tool);
@@ -828,6 +887,31 @@ gimp_bucket_fill_tool_options_notified (GimpBucketFillOptions *options,
     {
       gimp_bucket_fill_compute_line_art (tool);
     }
+  else if (! strcmp (pspec->name, "fill-mode"))
+    {
+      if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)))
+        gimp_tool_pop_status (GIMP_TOOL (tool), GIMP_TOOL (tool)->display);
+
+      switch (options->fill_mode)
+        {
+        case GIMP_BUCKET_FILL_BG:
+          GIMP_COLOR_TOOL (tool)->pick_target = GIMP_COLOR_PICK_TARGET_BACKGROUND;
+          if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)))
+            gimp_tool_push_status (GIMP_TOOL (tool), GIMP_TOOL (tool)->display,
+                                   _("Click in any image to pick the "
+                                     "background color"));
+          break;
+
+        case GIMP_BUCKET_FILL_FG:
+        default:
+          GIMP_COLOR_TOOL (tool)->pick_target = GIMP_COLOR_PICK_TARGET_FOREGROUND;
+          if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)))
+            gimp_tool_push_status (GIMP_TOOL (tool), GIMP_TOOL (tool)->display,
+                                   _("Click in any image to pick the "
+                                     "foreground color"));
+          break;
+        }
+    }
 }
 
 static void
diff --git a/app/tools/gimpbucketfilltool.h b/app/tools/gimpbucketfilltool.h
index 0b7b8279c0..37a1b9647e 100644
--- a/app/tools/gimpbucketfilltool.h
+++ b/app/tools/gimpbucketfilltool.h
@@ -19,7 +19,7 @@
 #define  __GIMP_BUCKET_FILL_TOOL_H__
 
 
-#include "gimptool.h"
+#include "gimpcolortool.h"
 
 
 #define GIMP_TYPE_BUCKET_FILL_TOOL            (gimp_bucket_fill_tool_get_type ())
@@ -38,14 +38,14 @@ typedef struct _GimpBucketFillToolPrivate GimpBucketFillToolPrivate;
 
 struct _GimpBucketFillTool
 {
-  GimpTool                   parent_instance;
+  GimpColorTool              parent_instance;
 
   GimpBucketFillToolPrivate *priv;
 };
 
 struct _GimpBucketFillToolClass
 {
-  GimpToolClass  parent_class;
+  GimpColorToolClass  parent_class;
 };
 
 


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