Move the quick mask members to GimpImagePrivate

and add API to access the "inverted" state.
This commit is contained in:
Michael Natterer 2010-02-04 09:49:45 +01:00
parent 02f5931c96
commit 4c1ec79281
9 changed files with 89 additions and 47 deletions

View File

@ -25,6 +25,7 @@
#include "actions-types.h"
#include "core/gimpimage.h"
#include "core/gimpimage-quick-mask.h"
#include "widgets/gimpactiongroup.h"
#include "widgets/gimphelp-ids.h"
@ -96,6 +97,17 @@ quick_mask_actions_update (GimpActionGroup *group,
gpointer data)
{
GimpImage *image = action_data_get_image (data);
gboolean quick_mask_state = FALSE;
gboolean quick_mask_inverted = FALSE;
GimpRGB quick_mask_color;
if (image)
{
quick_mask_state = gimp_image_get_quick_mask_state (image);
quick_mask_inverted = gimp_image_get_quick_mask_inverted (image);
gimp_image_get_quick_mask_color (image, &quick_mask_color);
}
#define SET_SENSITIVE(action,sensitive) \
gimp_action_group_set_action_sensitive (group, action, (sensitive) != 0)
@ -105,12 +117,12 @@ quick_mask_actions_update (GimpActionGroup *group,
gimp_action_group_set_action_color (group, action, (color), FALSE)
SET_SENSITIVE ("quick-mask-toggle", image);
SET_ACTIVE ("quick-mask-toggle", image && image->quick_mask_state);
SET_ACTIVE ("quick-mask-toggle", quick_mask_state);
SET_SENSITIVE ("quick-mask-invert-on", image);
SET_SENSITIVE ("quick-mask-invert-off", image);
if (image && image->quick_mask_inverted)
if (quick_mask_inverted)
SET_ACTIVE ("quick-mask-invert-on", TRUE);
else
SET_ACTIVE ("quick-mask-invert-off", TRUE);
@ -118,7 +130,7 @@ quick_mask_actions_update (GimpActionGroup *group,
SET_SENSITIVE ("quick-mask-configure", image);
if (image)
SET_COLOR ("quick-mask-configure", &image->quick_mask_color);
SET_COLOR ("quick-mask-configure", &quick_mask_color);
#undef SET_SENSITIVE
#undef SET_ACTIVE

View File

@ -77,7 +77,7 @@ quick_mask_invert_cmd_callback (GtkAction *action,
value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action));
if (value != image->quick_mask_inverted)
if (value != gimp_image_get_quick_mask_inverted (image))
{
gimp_image_quick_mask_invert (image);
gimp_image_flush (image);

View File

@ -430,9 +430,12 @@ static void
gimp_image_duplicate_quick_mask (GimpImage *image,
GimpImage *new_image)
{
new_image->quick_mask_state = image->quick_mask_state;
new_image->quick_mask_inverted = image->quick_mask_inverted;
new_image->quick_mask_color = image->quick_mask_color;
GimpImagePrivate *private = GIMP_IMAGE_GET_PRIVATE (image);
GimpImagePrivate *new_private = GIMP_IMAGE_GET_PRIVATE (new_image);
new_private->quick_mask_state = private->quick_mask_state;
new_private->quick_mask_inverted = private->quick_mask_inverted;
new_private->quick_mask_color = private->quick_mask_color;
}
static void

View File

@ -78,6 +78,10 @@ struct _GimpImagePrivate
gboolean visible[MAX_CHANNELS]; /* visible channels */
gboolean active[MAX_CHANNELS]; /* active channels */
gboolean quick_mask_state; /* TRUE if quick mask is on */
gboolean quick_mask_inverted; /* TRUE if quick mask is inverted */
GimpRGB quick_mask_color; /* rgba triplet of the color */
};
#define GIMP_IMAGE_GET_PRIVATE(image) \

View File

@ -26,6 +26,7 @@
#include "gimp.h"
#include "gimpchannel.h"
#include "gimpimage.h"
#include "gimpimage-private.h"
#include "gimpimage-quick-mask.h"
#include "gimpimage-undo.h"
#include "gimpimage-undo-push.h"
@ -45,6 +46,7 @@ void
gimp_image_set_quick_mask_state (GimpImage *image,
gboolean active)
{
GimpImagePrivate *private;
GimpChannel *selection;
GimpChannel *mask;
gboolean channel_was_active;
@ -54,18 +56,20 @@ gimp_image_set_quick_mask_state (GimpImage *image,
if (active == gimp_image_get_quick_mask_state (image))
return;
private = GIMP_IMAGE_GET_PRIVATE (image);
/* Keep track of the state so that we can make the right drawable
* active again when deactiviting quick mask (see bug #134371).
*/
if (image->quick_mask_state)
channel_was_active = (image->quick_mask_state & CHANNEL_WAS_ACTIVE) != 0;
if (private->quick_mask_state)
channel_was_active = (private->quick_mask_state & CHANNEL_WAS_ACTIVE) != 0;
else
channel_was_active = gimp_image_get_active_channel (image) != NULL;
/* Set image->quick_mask_state early so we can return early when
/* Set private->quick_mask_state early so we can return early when
* being called recursively.
*/
image->quick_mask_state = (active
private->quick_mask_state = (active
? TRUE | (channel_was_active ?
CHANNEL_WAS_ACTIVE : 0)
: FALSE);
@ -93,7 +97,7 @@ gimp_image_set_quick_mask_state (GimpImage *image,
gimp_image_get_width (image),
gimp_image_get_height (image),
GIMP_IMAGE_QUICK_MASK_NAME,
&image->quick_mask_color);
&private->quick_mask_color);
/* Clear the mask */
gimp_channel_clear (mask, NULL, FALSE);
@ -108,12 +112,12 @@ gimp_image_set_quick_mask_state (GimpImage *image,
/* Clear the selection */
gimp_channel_clear (selection, NULL, TRUE);
gimp_channel_set_color (mask, &image->quick_mask_color, FALSE);
gimp_channel_set_color (mask, &private->quick_mask_color, FALSE);
gimp_item_rename (GIMP_ITEM (mask), GIMP_IMAGE_QUICK_MASK_NAME,
NULL);
}
if (image->quick_mask_inverted)
if (private->quick_mask_inverted)
gimp_channel_invert (mask, FALSE);
gimp_image_add_channel (image, mask, NULL, 0, TRUE);
@ -130,7 +134,7 @@ gimp_image_set_quick_mask_state (GimpImage *image,
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_QUICK_MASK,
_("Disable Quick Mask"));
if (image->quick_mask_inverted)
if (private->quick_mask_inverted)
gimp_channel_invert (mask, TRUE);
if (floating_sel &&
@ -156,7 +160,7 @@ gimp_image_get_quick_mask_state (const GimpImage *image)
{
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
return image->quick_mask_state;
return GIMP_IMAGE_GET_PRIVATE (image)->quick_mask_state;
}
void
@ -168,7 +172,7 @@ gimp_image_set_quick_mask_color (GimpImage *image,
g_return_if_fail (GIMP_IS_IMAGE (image));
g_return_if_fail (color != NULL);
image->quick_mask_color = *color;
GIMP_IMAGE_GET_PRIVATE (image)->quick_mask_color = *color;
quick_mask = gimp_image_get_quick_mask (image);
if (quick_mask)
@ -182,7 +186,7 @@ gimp_image_get_quick_mask_color (const GimpImage *image,
g_return_if_fail (GIMP_IS_IMAGE (image));
g_return_if_fail (color != NULL);
*color = image->quick_mask_color;
*color = GIMP_IMAGE_GET_PRIVATE (image)->quick_mask_color;
}
GimpChannel *
@ -196,9 +200,13 @@ gimp_image_get_quick_mask (const GimpImage *image)
void
gimp_image_quick_mask_invert (GimpImage *image)
{
GimpImagePrivate *private;
g_return_if_fail (GIMP_IS_IMAGE (image));
if (image->quick_mask_state)
private = GIMP_IMAGE_GET_PRIVATE (image);
if (private->quick_mask_state)
{
GimpChannel *quick_mask = gimp_image_get_quick_mask (image);
@ -206,5 +214,13 @@ gimp_image_quick_mask_invert (GimpImage *image)
gimp_channel_invert (quick_mask, TRUE);
}
image->quick_mask_inverted = ! image->quick_mask_inverted;
private->quick_mask_inverted = ! private->quick_mask_inverted;
}
gboolean
gimp_image_get_quick_mask_inverted (const GimpImage *image)
{
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
return GIMP_IMAGE_GET_PRIVATE (image)->quick_mask_inverted;
}

View File

@ -37,6 +37,7 @@ void gimp_image_get_quick_mask_color (const GimpImage *image,
GimpChannel * gimp_image_get_quick_mask (const GimpImage *image);
void gimp_image_quick_mask_invert (GimpImage *image);
gboolean gimp_image_get_quick_mask_inverted (const GimpImage *image);
#endif /* __GIMP_IMAGE_QUICK_MASK_H__ */

View File

@ -667,9 +667,9 @@ gimp_image_init (GimpImage *image)
private->active[i] = TRUE;
}
image->quick_mask_state = FALSE;
image->quick_mask_inverted = FALSE;
gimp_rgba_set (&image->quick_mask_color, 1.0, 0.0, 0.0, 0.5);
private->quick_mask_state = FALSE;
private->quick_mask_inverted = FALSE;
gimp_rgba_set (&private->quick_mask_color, 1.0, 0.0, 0.0, 0.5);
image->undo_stack = gimp_undo_stack_new (image);
image->redo_stack = gimp_undo_stack_new (image);
@ -1349,7 +1349,7 @@ gimp_image_channel_color_changed (GimpChannel *channel,
if (! strcmp (GIMP_IMAGE_QUICK_MASK_NAME,
gimp_object_get_name (channel)))
{
image->quick_mask_color = channel->color;
GIMP_IMAGE_GET_PRIVATE (image)->quick_mask_color = channel->color;
}
}
@ -1885,6 +1885,9 @@ gimp_image_get_visible_array (const GimpImage *image,
components[i] = private->visible[i];
}
/* emitting image signals */
void
gimp_image_mode_changed (GimpImage *image)
{

View File

@ -105,10 +105,6 @@ struct _GimpImage
Gimp *gimp; /* the GIMP the image belongs to*/
gboolean quick_mask_state; /* TRUE if quick mask is on */
gboolean quick_mask_inverted; /* TRUE if quick mask is inverted */
GimpRGB quick_mask_color; /* rgba triplet of the color */
/* Undo apparatus */
GimpUndoStack *undo_stack; /* stack for undo operations */
GimpUndoStack *redo_stack; /* stack for redo operations */
@ -264,6 +260,9 @@ gboolean gimp_image_get_component_visible (const GimpImage *image,
void gimp_image_get_visible_array (const GimpImage *image,
gboolean *components);
/* emitting image signals */
void gimp_image_mode_changed (GimpImage *image);
void gimp_image_alpha_changed (GimpImage *image);
void gimp_image_invalidate (GimpImage *image,

View File

@ -33,6 +33,7 @@
#include "core/gimpcontainer.h"
#include "core/gimpimage.h"
#include "core/gimpimage-grid.h"
#include "core/gimpimage-quick-mask.h"
#include "core/gimpitem.h"
#include "core/gimptreehandler.h"
@ -484,6 +485,7 @@ gimp_display_shell_quick_mask_changed_handler (GimpImage *image,
GimpDisplayShell *shell)
{
GtkImage *gtk_image;
gboolean quick_mask_state;
gtk_image = GTK_IMAGE (gtk_bin_get_child (GTK_BIN (shell->quick_mask_button)));
@ -491,10 +493,12 @@ gimp_display_shell_quick_mask_changed_handler (GimpImage *image,
gimp_display_shell_quick_mask_toggled,
shell);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (shell->quick_mask_button),
image->quick_mask_state);
quick_mask_state = gimp_image_get_quick_mask_state (image);
if (image->quick_mask_state)
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (shell->quick_mask_button),
quick_mask_state);
if (quick_mask_state)
gtk_image_set_from_stock (gtk_image, GIMP_STOCK_QUICK_MASK_ON,
GTK_ICON_SIZE_MENU);
else