Files
gimp/app/core/gimpimage-quick-mask.c
Michael Natterer c4075975bf Bring parent items to the public API in the core
* app/core/gimpimage.[ch]: make the parent parameter public in
add_layer(), add_layers(), add_channel() and add_vectors().

* app/vectors/gimpvectors-import.[ch]: add parent parameters to
  the vectors import functions.

* app/core/gimpchannelundo.[ch]
* app/core/gimplayerundo.[ch]
* app/vectors/gimpvectorsundo.[ch]
* app/core/gimpimage-undo-push.[ch]: remember the parent item when
  removing layers, channels and vectors.

* app/actions/channels-commands.c
* app/actions/debug-commands.c
* app/actions/edit-commands.c
* app/actions/layers-commands.c
* app/actions/vectors-commands.c
* app/core/gimp-edit.c
* app/core/gimpimage-duplicate.c
* app/core/gimpimage-merge.c
* app/core/gimpimage-quick-mask.c
* app/core/gimplayer-floating-sel.c
* app/core/gimpselection.c
* app/core/gimptemplate.c
* app/dialogs/file-open-dialog.c
* app/display/gimpdisplayshell-dnd.c
* app/text/gimptext-compat.c
* app/tools/gimptexttool.c
* app/tools/gimpvectortool.c
* app/widgets/gimptoolbox-dnd.c
* app/xcf/xcf-load.c
* tools/pdbgen/pdb/image.pdb
* tools/pdbgen/pdb/paths.pdb
* tools/pdbgen/pdb/vectors.pdb: pass NULL as parent item to above
  functions and add FIXMEs all over the place because there is some
  more hacking needed to make adding with index = -1 (on top of the
  current item) work again.

* app/pdb/image-cmds.c
* app/pdb/paths-cmds.c
* app/pdb/vectors-cmds.c: regenerated.

* app/core/gimpimage-duplicate.c: duplicate the original image's
  tree structure in the copy.

* app/widgets/gimpitemtreeview.[ch]: add parent to GimpAddItemFunc,
  add utility function gimp_item_tree_view_get_drop_index() which
  figures where to add something dropped to an item tree.

* app/widgets/gimpchanneltreeview.c
* app/widgets/gimplayertreeview.c
* app/widgets/gimpvectorstreeview.c: changed accordingly, using above
  new GimpItemTreeView API.
2009-08-03 19:21:51 +02:00

211 lines
6.0 KiB
C

/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gegl.h>
#include "libgimpcolor/gimpcolor.h"
#include "core-types.h"
#include "gimp.h"
#include "gimpchannel.h"
#include "gimpimage.h"
#include "gimpimage-quick-mask.h"
#include "gimpimage-undo.h"
#include "gimpimage-undo-push.h"
#include "gimplayer.h"
#include "gimplayer-floating-sel.h"
#include "gimpselection.h"
#include "gimp-intl.h"
#define CHANNEL_WAS_ACTIVE (0x2)
/* public functions */
void
gimp_image_set_quick_mask_state (GimpImage *image,
gboolean active)
{
GimpChannel *selection;
GimpChannel *mask;
gboolean channel_was_active;
g_return_if_fail (GIMP_IS_IMAGE (image));
if (active == gimp_image_get_quick_mask_state (image))
return;
/* 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;
else
channel_was_active = gimp_image_get_active_channel (image) != NULL;
/* Set image->quick_mask_state early so we can return early when
* being called recursively.
*/
image->quick_mask_state = (active
? TRUE | (channel_was_active ?
CHANNEL_WAS_ACTIVE : 0)
: FALSE);
selection = gimp_image_get_mask (image);
mask = gimp_image_get_quick_mask (image);
if (active)
{
if (! mask)
{
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_QUICK_MASK,
_("Enable Quick Mask"));
if (gimp_channel_is_empty (selection))
{
/* if no selection */
GimpLayer *floating_sel = gimp_image_get_floating_selection (image);
if (floating_sel)
floating_sel_to_layer (floating_sel, NULL);
mask = gimp_channel_new (image,
gimp_image_get_width (image),
gimp_image_get_height (image),
GIMP_IMAGE_QUICK_MASK_NAME,
&image->quick_mask_color);
/* Clear the mask */
gimp_channel_clear (mask, NULL, FALSE);
}
else
{
/* if selection */
mask = GIMP_CHANNEL (gimp_item_duplicate (GIMP_ITEM (selection),
GIMP_TYPE_CHANNEL));
/* Clear the selection */
gimp_channel_clear (selection, NULL, TRUE);
gimp_channel_set_color (mask, &image->quick_mask_color, FALSE);
gimp_item_rename (GIMP_ITEM (mask), GIMP_IMAGE_QUICK_MASK_NAME,
NULL);
}
if (image->quick_mask_inverted)
gimp_channel_invert (mask, FALSE);
gimp_image_add_channel (image, mask, NULL, 0, TRUE);
gimp_image_undo_group_end (image);
}
}
else
{
if (mask)
{
GimpLayer *floating_sel = gimp_image_get_floating_selection (image);
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_QUICK_MASK,
_("Disable Quick Mask"));
if (image->quick_mask_inverted)
gimp_channel_invert (mask, TRUE);
if (floating_sel &&
gimp_layer_get_floating_sel_drawable (floating_sel) == GIMP_DRAWABLE (mask))
floating_sel_anchor (floating_sel);
gimp_selection_load (GIMP_SELECTION (gimp_image_get_mask (image)),
mask);
gimp_image_remove_channel (image, mask, TRUE, NULL);
if (! channel_was_active)
gimp_image_unset_active_channel (image);
gimp_image_undo_group_end (image);
}
}
gimp_image_quick_mask_changed (image);
}
gboolean
gimp_image_get_quick_mask_state (const GimpImage *image)
{
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
return image->quick_mask_state;
}
void
gimp_image_set_quick_mask_color (GimpImage *image,
const GimpRGB *color)
{
GimpChannel *quick_mask;
g_return_if_fail (GIMP_IS_IMAGE (image));
g_return_if_fail (color != NULL);
image->quick_mask_color = *color;
quick_mask = gimp_image_get_quick_mask (image);
if (quick_mask)
gimp_channel_set_color (quick_mask, color, TRUE);
}
void
gimp_image_get_quick_mask_color (const GimpImage *image,
GimpRGB *color)
{
g_return_if_fail (GIMP_IS_IMAGE (image));
g_return_if_fail (color != NULL);
*color = image->quick_mask_color;
}
GimpChannel *
gimp_image_get_quick_mask (const GimpImage *image)
{
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
return gimp_image_get_channel_by_name (image, GIMP_IMAGE_QUICK_MASK_NAME);
}
void
gimp_image_quick_mask_invert (GimpImage *image)
{
g_return_if_fail (GIMP_IS_IMAGE (image));
if (image->quick_mask_state)
{
GimpChannel *quick_mask = gimp_image_get_quick_mask (image);
if (quick_mask)
gimp_channel_invert (quick_mask, TRUE);
}
image->quick_mask_inverted = ! image->quick_mask_inverted;
}