app: add boolean "mask_inverted" to GimpDisplayShell

and to gimp_display_shell_set_mask(). It allows to choose whether the
mask is drawn inverted, instead of always drawing it inverted.
This commit is contained in:
Michael Natterer
2014-06-11 21:33:57 +02:00
parent 6857d0141d
commit 21a8f9c96b
4 changed files with 26 additions and 20 deletions

View File

@ -205,8 +205,6 @@ gimp_display_shell_render (GimpDisplayShell *shell,
if (shell->mask)
{
gint mask_height;
if (! shell->mask_surface)
{
shell->mask_surface =
@ -231,21 +229,24 @@ gimp_display_shell_render (GimpDisplayShell *shell,
data, stride,
GEGL_ABYSS_CLAMP);
/* invert the mask so what is *not* the foreground object is masked */
mask_height = scaled_height;
while (mask_height--)
if (shell->mask_inverted)
{
gint mask_width = scaled_width;
guchar *d = data;
gint mask_height = scaled_height;
while (mask_width--)
while (mask_height--)
{
guchar inv = 255 - *d;
gint mask_width = scaled_width;
guchar *d = data;
*d++ = inv;
while (mask_width--)
{
guchar inv = 255 - *d;
*d++ = inv;
}
data += stride;
}
data += stride;
}
}

View File

@ -1918,15 +1918,16 @@ gimp_display_shell_set_highlight (GimpDisplayShell *shell,
* @shell: a #GimpDisplayShell
* @mask: a #GimpDrawable (1 byte per pixel)
* @color: the color to use for drawing the mask
* @inverted: #TRUE if the mask should be drawn inverted
*
* Previews a selection (used by the foreground selection tool).
* Pixels that are not selected (> 127) in the mask are tinted with
* the given color.
* Previews an image-sized mask. Depending on @inverted, pixels that
* are selected or not selected are tinted with the given color.
**/
void
gimp_display_shell_set_mask (GimpDisplayShell *shell,
GeglBuffer *mask,
const GimpRGB *color)
const GimpRGB *color,
gboolean inverted)
{
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
g_return_if_fail (mask == NULL || GEGL_IS_BUFFER (mask));
@ -1943,5 +1944,7 @@ gimp_display_shell_set_mask (GimpDisplayShell *shell,
if (mask)
shell->mask_color = *color;
shell->mask_inverted = inverted;
gimp_display_shell_expose_full (shell);
}

View File

@ -191,6 +191,7 @@ struct _GimpDisplayShell
GeglBuffer *mask;
GimpRGB mask_color;
gboolean mask_inverted;
GimpMotionBuffer *motion_buffer;
@ -281,7 +282,8 @@ void gimp_display_shell_set_highlight (GimpDisplayShell *shell,
const GdkRectangle *highlight);
void gimp_display_shell_set_mask (GimpDisplayShell *shell,
GeglBuffer *mask,
const GimpRGB *color);
const GimpRGB *color,
gboolean inverted);
#endif /* __GIMP_DISPLAY_SHELL_H__ */

View File

@ -944,7 +944,7 @@ gimp_foreground_select_tool_halt (GimpForegroundSelectTool *fg_select)
if (tool->display)
gimp_display_shell_set_mask (gimp_display_get_shell (tool->display),
NULL, NULL);
NULL, NULL, FALSE);
gimp_tool_control_set_tool_cursor (tool->control,
GIMP_TOOL_CURSOR_FREE_SELECT);
@ -1006,7 +1006,7 @@ gimp_foreground_select_tool_set_trimap (GimpForegroundSelectTool *fg_select)
gimp_foreground_select_options_get_mask_color (options, &color);
gimp_display_shell_set_mask (gimp_display_get_shell (tool->display),
fg_select->trimap, &color);
fg_select->trimap, &color, TRUE);
gimp_tool_control_set_tool_cursor (tool->control,
GIMP_TOOL_CURSOR_PAINTBRUSH);
@ -1034,7 +1034,7 @@ gimp_foreground_select_tool_set_preview (GimpForegroundSelectTool *fg_select)
gimp_foreground_select_options_get_mask_color (options, &color);
gimp_display_shell_set_mask (gimp_display_get_shell (tool->display),
fg_select->mask, &color);
fg_select->mask, &color, TRUE);
gimp_tool_control_set_tool_cursor (tool->control,
GIMP_TOOL_CURSOR_PAINTBRUSH);