[gimp] app: use GimpRGB as mask color



commit 2ef259cd2006a82d73487fcee37438fae570c955
Author: Sven Neumann <sven gimp org>
Date:   Wed Sep 29 00:10:37 2010 +0200

    app: use GimpRGB as mask color
    
    Instead of passing GimpChannelType as mask color to
    gimp_display_shell_set_mask(), change that function to accept a
    GimpRGB color.
    
    Adapt GimpForegroundSelectTool, the only user of the display mask
    feature, to this change.

 app/display/gimpdisplayshell-render.c   |   23 +++--------------------
 app/display/gimpdisplayshell.c          |   12 ++++++------
 app/display/gimpdisplayshell.h          |    4 ++--
 app/tools/gimpforegroundselectoptions.c |   28 ++++++++++++++++++++++++++++
 app/tools/gimpforegroundselectoptions.h |    7 +++++--
 app/tools/gimpforegroundselecttool.c    |   28 +++++++++++++++++++++-------
 6 files changed, 65 insertions(+), 37 deletions(-)
---
diff --git a/app/display/gimpdisplayshell-render.c b/app/display/gimpdisplayshell-render.c
index c309731..2c8b416 100644
--- a/app/display/gimpdisplayshell-render.c
+++ b/app/display/gimpdisplayshell-render.c
@@ -20,6 +20,8 @@
 #include <gegl.h>
 #include <gtk/gtk.h>
 
+#include "libgimpwidgets/gimpwidgets.h"
+
 #include "display-types.h"
 
 #include "base/tile-manager.h"
@@ -222,26 +224,7 @@ gimp_display_shell_render (GimpDisplayShell *shell,
 
     if (shell->mask)
       {
-        /*  FIXME: mask_color should be GimpRGB  */
-        switch (shell->mask_color)
-          {
-          case GIMP_RED_CHANNEL:
-            cairo_set_source_rgba (cr, 1, 0, 0, 0.5);
-            break;
-
-          case GIMP_GREEN_CHANNEL:
-            cairo_set_source_rgba (cr, 0, 1, 0, 0.5);
-            break;
-
-          case GIMP_BLUE_CHANNEL:
-            cairo_set_source_rgba (cr, 0, 0, 1, 0.5);
-            break;
-
-          default:
-            g_warn_if_reached ();
-            return;
-          }
-
+        gimp_cairo_set_source_rgba (cr, &shell->mask_color);
         cairo_mask_surface (cr, shell->mask_surface,
                             x + disp_xoffset, y + disp_yoffset);
       }
diff --git a/app/display/gimpdisplayshell.c b/app/display/gimpdisplayshell.c
index 221127d..f349495 100644
--- a/app/display/gimpdisplayshell.c
+++ b/app/display/gimpdisplayshell.c
@@ -1813,15 +1813,13 @@ gimp_display_shell_set_highlight (GimpDisplayShell   *shell,
 void
 gimp_display_shell_set_mask (GimpDisplayShell *shell,
                              GimpDrawable     *mask,
-                             GimpChannelType   color)
+                             const GimpRGB    *color)
 {
   g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
   g_return_if_fail (mask == NULL ||
                     (GIMP_IS_DRAWABLE (mask) &&
                      gimp_drawable_bytes (mask) == 1));
-
-  if (shell->mask == mask && shell->mask_color == color)
-    return;
+  g_return_if_fail (mask == NULL || color != NULL);
 
   if (mask)
     g_object_ref (mask);
@@ -1829,8 +1827,10 @@ gimp_display_shell_set_mask (GimpDisplayShell *shell,
   if (shell->mask)
     g_object_unref (shell->mask);
 
-  shell->mask       = mask;
-  shell->mask_color = color;
+  shell->mask = mask;
+
+  if (mask)
+    shell->mask_color = *color;
 
   gimp_display_shell_expose_full (shell);
 }
diff --git a/app/display/gimpdisplayshell.h b/app/display/gimpdisplayshell.h
index 7283761..a6eb26d 100644
--- a/app/display/gimpdisplayshell.h
+++ b/app/display/gimpdisplayshell.h
@@ -187,7 +187,7 @@ struct _GimpDisplayShell
 
   GdkRectangle      *highlight;        /* in image coordinates, can be NULL   */
   GimpDrawable      *mask;
-  GimpChannelType    mask_color;
+  GimpRGB            mask_color;
 
   GArray            *event_history;
   GArray            *event_queue;
@@ -277,7 +277,7 @@ void              gimp_display_shell_set_highlight (GimpDisplayShell   *shell,
                                                     const GdkRectangle *highlight);
 void              gimp_display_shell_set_mask      (GimpDisplayShell   *shell,
                                                     GimpDrawable       *mask,
-                                                    GimpChannelType     color);
+                                                    const GimpRGB      *color);
 
 
 #endif /* __GIMP_DISPLAY_SHELL_H__ */
diff --git a/app/tools/gimpforegroundselectoptions.c b/app/tools/gimpforegroundselectoptions.c
index 8404880..5853ba5 100644
--- a/app/tools/gimpforegroundselectoptions.c
+++ b/app/tools/gimpforegroundselectoptions.c
@@ -19,6 +19,7 @@
 
 #include <gtk/gtk.h>
 
+#include "libgimpcolor/gimpcolor.h"
 #include "libgimpconfig/gimpconfig.h"
 #include "libgimpwidgets/gimpwidgets.h"
 
@@ -370,3 +371,30 @@ gimp_foreground_select_options_gui (GimpToolOptions *tool_options)
 
   return vbox;
 }
+
+void
+gimp_foreground_select_options_get_mask_color (GimpForegroundSelectOptions *options,
+                                               GimpRGB                     *color)
+{
+  g_return_if_fail (GIMP_IS_FOREGROUND_SELECT_OPTIONS (options));
+  g_return_if_fail (color != NULL);
+
+  switch (options->mask_color)
+    {
+    case GIMP_RED_CHANNEL:
+      gimp_rgba_set (color, 1, 0, 0, 0.5);
+      break;
+
+    case GIMP_GREEN_CHANNEL:
+      gimp_rgba_set (color, 0, 1, 0, 0.5);
+      break;
+
+    case GIMP_BLUE_CHANNEL:
+      gimp_rgba_set (color, 0, 0, 1, 0.5);
+      break;
+
+    default:
+      g_warn_if_reached ();
+      break;
+    }
+}
diff --git a/app/tools/gimpforegroundselectoptions.h b/app/tools/gimpforegroundselectoptions.h
index be6d947..5423898 100644
--- a/app/tools/gimpforegroundselectoptions.h
+++ b/app/tools/gimpforegroundselectoptions.h
@@ -47,9 +47,12 @@ struct _GimpForegroundSelectOptions
 };
 
 
-GType       gimp_foreground_select_options_get_type (void) G_GNUC_CONST;
+GType       gimp_foreground_select_options_get_type       (void) G_GNUC_CONST;
 
-GtkWidget * gimp_foreground_select_options_gui      (GimpToolOptions *tool_options);
+GtkWidget * gimp_foreground_select_options_gui            (GimpToolOptions             *tool_options);
+
+void        gimp_foreground_select_options_get_mask_color (GimpForegroundSelectOptions *options,
+                                                           GimpRGB                     *color);
 
 
 #endif /* __GIMP_FOREGROUND_SELECT_OPTIONS_H__ */
diff --git a/app/tools/gimpforegroundselecttool.c b/app/tools/gimpforegroundselecttool.c
index 892c1a9..7236c3f 100644
--- a/app/tools/gimpforegroundselecttool.c
+++ b/app/tools/gimpforegroundselecttool.c
@@ -735,10 +735,20 @@ gimp_foreground_select_tool_set_mask (GimpForegroundSelectTool *fg_select,
     }
 
   if (mask)
-    fg_select->mask = g_object_ref (mask);
+    {
+      GimpRGB color;
 
-  gimp_display_shell_set_mask (gimp_display_get_shell (display),
-                               GIMP_DRAWABLE (mask), options->mask_color);
+      fg_select->mask = g_object_ref (mask);
+
+      gimp_foreground_select_options_get_mask_color (options, &color);
+      gimp_display_shell_set_mask (gimp_display_get_shell (display),
+                                   GIMP_DRAWABLE (mask), &color);
+    }
+  else
+    {
+      gimp_display_shell_set_mask (gimp_display_get_shell (display),
+                                   NULL, NULL);
+    }
 
   if (mask)
     {
@@ -896,9 +906,13 @@ gimp_foreground_select_options_notify (GimpForegroundSelectOptions *options,
     {
       GimpTool *tool = GIMP_TOOL (fg_select);
 
-      if (tool->display)
-        gimp_display_shell_set_mask (gimp_display_get_shell (tool->display),
-                                     GIMP_DRAWABLE (fg_select->mask),
-                                     options->mask_color);
+      if (tool->display && fg_select->mask)
+        {
+          GimpRGB color;
+
+          gimp_foreground_select_options_get_mask_color (options, &color);
+          gimp_display_shell_set_mask (gimp_display_get_shell (tool->display),
+                                       GIMP_DRAWABLE (fg_select->mask), &color);
+        }
     }
 }



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