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.
This commit is contained in:
Sven Neumann 2010-09-29 00:10:37 +02:00
parent a7413bd784
commit 2ef259cd20
6 changed files with 65 additions and 37 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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__ */

View File

@ -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;
}
}

View File

@ -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__ */

View File

@ -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);
}
}
}