[gimp] app: allow the fuzzy and by-color select tools to show the mask directly



commit 604c14a08c1784e8a982d72d6bfe42b6f00c84d5
Author: Michael Natterer <mitch gimp org>
Date:   Wed Jun 11 22:15:00 2014 +0200

    app: allow the fuzzy and by-color select tools to show the mask directly
    
    instead of the outline. This is experimental, please comment. The
    color is currently hardcoded to magenta.

 app/tools/gimpregionselectoptions.c |   25 ++++++++++-
 app/tools/gimpregionselectoptions.h |    1 +
 app/tools/gimpregionselecttool.c    |   86 ++++++++++++++++++++---------------
 3 files changed, 75 insertions(+), 37 deletions(-)
---
diff --git a/app/tools/gimpregionselectoptions.c b/app/tools/gimpregionselectoptions.c
index e90c8d7..0fe87bf 100644
--- a/app/tools/gimpregionselectoptions.c
+++ b/app/tools/gimpregionselectoptions.c
@@ -45,7 +45,8 @@ enum
   PROP_SELECT_TRANSPARENT,
   PROP_SAMPLE_MERGED,
   PROP_THRESHOLD,
-  PROP_SELECT_CRITERION
+  PROP_SELECT_CRITERION,
+  PROP_DRAW_MASK
 };
 
 
@@ -103,6 +104,14 @@ gimp_region_select_options_class_init (GimpRegionSelectOptionsClass *klass)
                                  GIMP_TYPE_SELECT_CRITERION,
                                  GIMP_SELECT_CRITERION_COMPOSITE,
                                  GIMP_PARAM_STATIC_STRINGS);
+
+  g_object_class_install_property (object_class, PROP_DRAW_MASK,
+                                   g_param_spec_boolean ("draw-mask",
+                                                         "Draw mask",
+                                                         _("Draw the selected region's mask"),
+                                                         FALSE,
+                                                         G_PARAM_READWRITE |
+                                                         GIMP_PARAM_STATIC_STRINGS));
 }
 
 static void
@@ -136,6 +145,10 @@ gimp_region_select_options_set_property (GObject      *object,
       options->select_criterion = g_value_get_enum (value);
       break;
 
+    case PROP_DRAW_MASK:
+      options->draw_mask = g_value_get_boolean (value);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -168,6 +181,10 @@ gimp_region_select_options_get_property (GObject    *object,
       g_value_set_enum (value, options->select_criterion);
       break;
 
+    case PROP_DRAW_MASK:
+      g_value_set_boolean (value, options->draw_mask);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -223,5 +240,11 @@ gimp_region_select_options_gui (GimpToolOptions *tool_options)
   gtk_box_pack_start (GTK_BOX (vbox), combo, TRUE, TRUE, 0);
   gtk_widget_show (combo);
 
+  /*  the show mask toggle  */
+  button = gimp_prop_check_button_new (config, "draw-mask",
+                                       _("Draw Mask"));
+  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+  gtk_widget_show (button);
+
   return vbox;
 }
diff --git a/app/tools/gimpregionselectoptions.h b/app/tools/gimpregionselectoptions.h
index 9c0e501..0661483 100644
--- a/app/tools/gimpregionselectoptions.h
+++ b/app/tools/gimpregionselectoptions.h
@@ -41,6 +41,7 @@ struct _GimpRegionSelectOptions
   gboolean              sample_merged;
   gdouble               threshold;
   GimpSelectCriterion   select_criterion;
+  gboolean              draw_mask;
 };
 
 
diff --git a/app/tools/gimpregionselecttool.c b/app/tools/gimpregionselecttool.c
index 07b3a95..86e0ea0 100644
--- a/app/tools/gimpregionselecttool.c
+++ b/app/tools/gimpregionselecttool.c
@@ -26,6 +26,7 @@
 
 #include "tools-types.h"
 
+#include "core/gimp-utils.h"
 #include "core/gimpboundary.h"
 #include "core/gimpchannel.h"
 #include "core/gimpchannel-select.h"
@@ -69,9 +70,8 @@ static void   gimp_region_select_tool_cursor_update  (GimpTool              *too
 
 static void   gimp_region_select_tool_draw           (GimpDrawTool          *draw_tool);
 
-static GimpBoundSeg * gimp_region_select_tool_calculate (GimpRegionSelectTool *region_sel,
-                                                         GimpDisplay          *display,
-                                                         gint                 *n_segs);
+static void   gimp_region_select_tool_get_mask       (GimpRegionSelectTool  *region_sel,
+                                                      GimpDisplay           *display);
 
 
 G_DEFINE_TYPE (GimpRegionSelectTool, gimp_region_select_tool,
@@ -161,9 +161,7 @@ gimp_region_select_tool_button_press (GimpTool            *tool,
   gimp_tool_push_status (tool, display,
                          _("Move the mouse to change threshold"));
 
-  /*  calculate the region boundary  */
-  region_sel->segs = gimp_region_select_tool_calculate (region_sel, display,
-                                                        &region_sel->n_segs);
+  gimp_region_select_tool_get_mask (region_sel, display);
 
   gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display);
 }
@@ -187,6 +185,10 @@ gimp_region_select_tool_button_release (GimpTool              *tool,
 
   gimp_tool_control_halt (tool->control);
 
+  if (options->draw_mask)
+    gimp_display_shell_set_mask (gimp_display_get_shell (display),
+                                 NULL, NULL, FALSE);
+
   if (release_type != GIMP_BUTTON_RELEASE_CANCEL)
     {
       if (GIMP_SELECTION_TOOL (tool)->function == SELECTION_ANCHOR)
@@ -281,11 +283,7 @@ gimp_region_select_tool_motion (GimpTool         *tool,
 
   gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
 
-  if (region_sel->segs)
-    g_free (region_sel->segs);
-
-  region_sel->segs = gimp_region_select_tool_calculate (region_sel, display,
-                                                        &region_sel->n_segs);
+  gimp_region_select_tool_get_mask (region_sel, display);
 
   gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
 }
@@ -315,11 +313,27 @@ gimp_region_select_tool_draw (GimpDrawTool *draw_tool)
   GimpRegionSelectTool    *region_sel = GIMP_REGION_SELECT_TOOL (draw_tool);
   GimpRegionSelectOptions *options    = GIMP_REGION_SELECT_TOOL_GET_OPTIONS (draw_tool);
 
-  if (region_sel->segs)
+  if (! options->draw_mask && region_sel->region_mask)
     {
       gint off_x = 0;
       gint off_y = 0;
 
+      if (! region_sel->segs)
+        {
+          /*  calculate and allocate a new segment array which represents
+           *  the boundary of the contiguous region
+           */
+          region_sel->segs = gimp_boundary_find (region_sel->region_mask, NULL,
+                                                 babl_format ("Y float"),
+                                                 GIMP_BOUNDARY_WITHIN_BOUNDS,
+                                                 0, 0,
+                                                 gegl_buffer_get_width  (region_sel->region_mask),
+                                                 gegl_buffer_get_height (region_sel->region_mask),
+                                                 GIMP_BOUNDARY_HALF_WAY,
+                                                 &region_sel->n_segs);
+
+        }
+
       if (! options->sample_merged)
         {
           GimpImage    *image    = gimp_display_get_image (draw_tool->display);
@@ -336,16 +350,22 @@ gimp_region_select_tool_draw (GimpDrawTool *draw_tool)
     }
 }
 
-static GimpBoundSeg *
-gimp_region_select_tool_calculate (GimpRegionSelectTool *region_sel,
-                                   GimpDisplay          *display,
-                                   gint                 *n_segs)
+static void
+gimp_region_select_tool_get_mask (GimpRegionSelectTool *region_sel,
+                                  GimpDisplay          *display)
 {
-  GimpDisplayShell *shell = gimp_display_get_shell (display);
-  GimpBoundSeg     *segs  = NULL;
+  GimpRegionSelectOptions *options = GIMP_REGION_SELECT_TOOL_GET_OPTIONS (region_sel);
+  GimpDisplayShell        *shell   = gimp_display_get_shell (display);
 
   gimp_display_shell_set_override_cursor (shell, GDK_WATCH);
 
+  if (region_sel->segs)
+    {
+      g_free (region_sel->segs);
+      region_sel->segs   = NULL;
+      region_sel->n_segs = 0;
+    }
+
   if (region_sel->region_mask)
     g_object_unref (region_sel->region_mask);
 
@@ -353,26 +373,20 @@ gimp_region_select_tool_calculate (GimpRegionSelectTool *region_sel,
     GIMP_REGION_SELECT_TOOL_GET_CLASS (region_sel)->get_mask (region_sel,
                                                               display);
 
-  if (region_sel->region_mask)
-    {
-      /*  calculate and allocate a new segment array which represents
-       *  the boundary of the contiguous region
-       */
-      segs = gimp_boundary_find (region_sel->region_mask, NULL,
-                                 babl_format ("Y float"),
-                                 GIMP_BOUNDARY_WITHIN_BOUNDS,
-                                 0, 0,
-                                 gegl_buffer_get_width  (region_sel->region_mask),
-                                 gegl_buffer_get_height (region_sel->region_mask),
-                                 GIMP_BOUNDARY_HALF_WAY,
-                                 n_segs);
-    }
-  else
+  if (options->draw_mask)
     {
-      *n_segs = 0;
+      if (region_sel->region_mask)
+        {
+          GimpRGB color = { 1.0, 0.0, 1.0, 1.0 };
+
+          gimp_display_shell_set_mask (shell, region_sel->region_mask,
+                                       &color, FALSE);
+        }
+      else
+        {
+          gimp_display_shell_set_mask (shell, NULL, NULL, FALSE);
+        }
     }
 
   gimp_display_shell_unset_override_cursor (shell);
-
-  return segs;
 }


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