[gimp] app: add GimpColorTool::can_pick() virtual function



commit bfadac145bd6b07de709189462c0209739ca9961
Author: Ell <ell_se yahoo com>
Date:   Wed May 3 13:24:39 2017 -0400

    app: add GimpColorTool::can_pick() virtual function
    
    Determines if the tool can pick at a given coordinate, without
    actually picking.  The default implementation uses
    gimp_image_coords_in_active_pickable(); GimpFilterTool overrides
    this function, to return TRUE whenever the active picker has
    pick_abyss == TRUE.
    
    Use this function when updating the cursor, and when determining
    whether to draw the sample-average region indicator.

 app/tools/gimpcolortool.c  |   58 ++++++++++++++++++++++++++++++++++++-------
 app/tools/gimpcolortool.h  |   30 +++++++++++++----------
 app/tools/gimpfiltertool.c |   21 ++++++++++++++++
 3 files changed, 86 insertions(+), 23 deletions(-)
---
diff --git a/app/tools/gimpcolortool.c b/app/tools/gimpcolortool.c
index 8ceeecb..d14d57e 100644
--- a/app/tools/gimpcolortool.c
+++ b/app/tools/gimpcolortool.c
@@ -95,6 +95,10 @@ static void   gimp_color_tool_cursor_update  (GimpTool              *tool,
 
 static void   gimp_color_tool_draw           (GimpDrawTool          *draw_tool);
 
+static gboolean
+               gimp_color_tool_real_can_pick (GimpColorTool         *color_tool,
+                                              const GimpCoords      *coords,
+                                              GimpDisplay           *display);
 static gboolean   gimp_color_tool_real_pick  (GimpColorTool         *color_tool,
                                               gint                   x,
                                               gint                   y,
@@ -109,6 +113,9 @@ static void   gimp_color_tool_real_picked    (GimpColorTool         *color_tool,
                                               gpointer               pixel,
                                               const GimpRGB         *color);
 
+static gboolean   gimp_color_tool_can_pick   (GimpColorTool         *tool,
+                                              const GimpCoords      *coords,
+                                              GimpDisplay           *display);
 static void   gimp_color_tool_pick           (GimpColorTool         *tool,
                                               GimpColorPickState     pick_state,
                                               gint                   x,
@@ -154,6 +161,7 @@ gimp_color_tool_class_init (GimpColorToolClass *klass)
 
   draw_class->draw           = gimp_color_tool_draw;
 
+  klass->can_pick            = gimp_color_tool_real_can_pick;
   klass->pick                = gimp_color_tool_real_pick;
   klass->picked              = gimp_color_tool_real_picked;
 }
@@ -207,7 +215,7 @@ gimp_color_tool_button_press (GimpTool            *tool,
       gimp_sample_point_tool_start_edit (tool, display,
                                          color_tool->sample_point);
     }
-  else
+  else if (gimp_color_tool_can_pick (color_tool, coords, display))
     {
       gimp_color_tool_pick (color_tool, GIMP_COLOR_PICK_STATE_START,
                             coords->x, coords->y);
@@ -231,7 +239,8 @@ gimp_color_tool_button_release (GimpTool              *tool,
   if (! color_tool->enabled)
     return;
 
-  if (! color_tool->sample_point)
+  if (! color_tool->sample_point &&
+      gimp_color_tool_can_pick (color_tool, coords, display))
     {
       gimp_color_tool_pick (color_tool, GIMP_COLOR_PICK_STATE_END,
                             coords->x, coords->y);
@@ -254,13 +263,18 @@ gimp_color_tool_motion (GimpTool         *tool,
     {
       gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
 
+      color_tool->can_pick = gimp_color_tool_can_pick (color_tool,
+                                                       coords, display);
       color_tool->center_x = coords->x;
       color_tool->center_y = coords->y;
 
-      gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
+      if (color_tool->can_pick)
+        {
+          gimp_color_tool_pick (color_tool, GIMP_COLOR_PICK_STATE_UPDATE,
+                                coords->x, coords->y);
+        }
 
-      gimp_color_tool_pick (color_tool, GIMP_COLOR_PICK_STATE_UPDATE,
-                            coords->x, coords->y);
+      gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
     }
 }
 
@@ -303,6 +317,8 @@ gimp_color_tool_oper_update (GimpTool         *tool,
 
       color_tool->sample_point = sample_point;
 
+      color_tool->can_pick = gimp_color_tool_can_pick (color_tool,
+                                                       coords, display);
       color_tool->center_x = coords->x;
       color_tool->center_y = coords->y;
 
@@ -323,7 +339,6 @@ gimp_color_tool_cursor_update (GimpTool         *tool,
                                GimpDisplay      *display)
 {
   GimpColorTool *color_tool = GIMP_COLOR_TOOL (tool);
-  GimpImage     *image      = gimp_display_get_image (display);
 
   if (color_tool->enabled)
     {
@@ -338,9 +353,7 @@ gimp_color_tool_cursor_update (GimpTool         *tool,
         {
           GimpCursorModifier modifier = GIMP_CURSOR_MODIFIER_BAD;
 
-          if (gimp_image_coords_in_active_pickable (image, coords,
-                                                    color_tool->options->sample_merged,
-                                                    FALSE))
+          if (gimp_color_tool_can_pick (color_tool, coords, display))
             {
               switch (color_tool->pick_mode)
                 {
@@ -394,7 +407,7 @@ gimp_color_tool_draw (GimpDrawTool *draw_tool)
           item = gimp_draw_tool_add_sample_point (draw_tool, x, y, index);
           gimp_canvas_item_set_highlight (item, TRUE);
         }
-      else if (color_tool->options->sample_average)
+      else if (color_tool->can_pick && color_tool->options->sample_average)
         {
           gdouble radius = color_tool->options->average_radius;
 
@@ -409,6 +422,19 @@ gimp_color_tool_draw (GimpDrawTool *draw_tool)
 }
 
 static gboolean
+gimp_color_tool_real_can_pick (GimpColorTool    *color_tool,
+                               const GimpCoords *coords,
+                               GimpDisplay      *display)
+{
+  GimpImage *image = gimp_display_get_image (display);
+
+  return
+    gimp_image_coords_in_active_pickable (image, coords,
+                                          color_tool->options->sample_merged,
+                                          FALSE);
+}
+
+static gboolean
 gimp_color_tool_real_pick (GimpColorTool  *color_tool,
                            gint            x,
                            gint            y,
@@ -542,6 +568,18 @@ gimp_color_tool_real_picked (GimpColorTool      *color_tool,
     }
 }
 
+static gboolean
+gimp_color_tool_can_pick (GimpColorTool    *tool,
+                          const GimpCoords *coords,
+                          GimpDisplay      *display)
+{
+  GimpColorToolClass *klass;
+
+  klass = GIMP_COLOR_TOOL_GET_CLASS (tool);
+
+  return klass->can_pick && klass->can_pick (tool, coords, display);
+}
+
 static void
 gimp_color_tool_pick (GimpColorTool      *tool,
                       GimpColorPickState  pick_state,
diff --git a/app/tools/gimpcolortool.h b/app/tools/gimpcolortool.h
index 113e23f..618d4a1 100644
--- a/app/tools/gimpcolortool.h
+++ b/app/tools/gimpcolortool.h
@@ -44,6 +44,7 @@ struct _GimpColorTool
 
   GimpColorPickMode  pick_mode;
 
+  gboolean           can_pick;
   gint               center_x;
   gint               center_y;
   GimpSamplePoint   *sample_point;
@@ -54,21 +55,24 @@ struct _GimpColorToolClass
   GimpDrawToolClass  parent_class;
 
   /*  virtual functions  */
-  gboolean (* pick)   (GimpColorTool      *tool,
-                       gint                x,
-                       gint                y,
-                       const Babl        **sample_format,
-                       gpointer            pixel,
-                       GimpRGB            *color);
+  gboolean (* can_pick) (GimpColorTool      *tool,
+                         const GimpCoords   *coords,
+                         GimpDisplay        *display);
+  gboolean (* pick)     (GimpColorTool      *tool,
+                         gint                x,
+                         gint                y,
+                         const Babl        **sample_format,
+                         gpointer            pixel,
+                         GimpRGB            *color);
 
   /*  signals  */
-  void     (* picked) (GimpColorTool      *tool,
-                       GimpColorPickState  pick_state,
-                       gdouble             x,
-                       gdouble             y,
-                       const Babl         *sample_format,
-                       gpointer            pixel,
-                       const GimpRGB      *color);
+  void     (* picked)   (GimpColorTool      *tool,
+                         GimpColorPickState  pick_state,
+                         gdouble             x,
+                         gdouble             y,
+                         const Babl         *sample_format,
+                         gpointer            pixel,
+                         const GimpRGB      *color);
 };
 
 
diff --git a/app/tools/gimpfiltertool.c b/app/tools/gimpfiltertool.c
index bad49a0..51c24e5 100644
--- a/app/tools/gimpfiltertool.c
+++ b/app/tools/gimpfiltertool.c
@@ -108,6 +108,9 @@ static void      gimp_filter_tool_options_notify (GimpTool            *tool,
                                                   GimpToolOptions     *options,
                                                   const GParamSpec    *pspec);
 
+static gboolean  gimp_filter_tool_can_pick_color (GimpColorTool       *color_tool,
+                                                  const GimpCoords    *coords,
+                                                  GimpDisplay         *display);
 static gboolean  gimp_filter_tool_pick_color     (GimpColorTool       *color_tool,
                                                   gint                 x,
                                                   gint                 y,
@@ -179,6 +182,7 @@ gimp_filter_tool_class_init (GimpFilterToolClass *klass)
   tool_class->cursor_update  = gimp_filter_tool_cursor_update;
   tool_class->options_notify = gimp_filter_tool_options_notify;
 
+  color_tool_class->can_pick = gimp_filter_tool_can_pick_color;
   color_tool_class->pick     = gimp_filter_tool_pick_color;
   color_tool_class->picked   = gimp_filter_tool_color_picked;
 
@@ -792,6 +796,23 @@ gimp_filter_tool_options_notify (GimpTool         *tool,
 }
 
 static gboolean
+gimp_filter_tool_can_pick_color (GimpColorTool    *color_tool,
+                                 const GimpCoords *coords,
+                                 GimpDisplay      *display)
+{
+  GimpFilterTool *filter_tool = GIMP_FILTER_TOOL (color_tool);
+  gboolean        pick_abyss;
+
+  pick_abyss =
+    GPOINTER_TO_INT (g_object_get_data (G_OBJECT (filter_tool->active_picker),
+                     "picker-pick-abyss"));
+
+  return pick_abyss ||
+         GIMP_COLOR_TOOL_CLASS (parent_class)->can_pick (color_tool,
+                                                         coords, display);
+}
+
+static gboolean
 gimp_filter_tool_pick_color (GimpColorTool  *color_tool,
                              gint            x,
                              gint            y,


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