2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2001-01-29 00:44:22 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2001-01-29 00:44:22 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2001-01-29 00:44:22 +08:00
|
|
|
* (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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2001-01-29 00:44:22 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2001-01-29 00:44:22 +08:00
|
|
|
|
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "core-types.h"
|
2001-01-29 00:44:22 +08:00
|
|
|
|
2008-11-12 18:56:06 +08:00
|
|
|
#include "gimperror.h"
|
2004-01-27 00:18:16 +08:00
|
|
|
#include "gimpimage.h"
|
2005-03-25 03:23:14 +08:00
|
|
|
#include "gimpimage-undo-push.h"
|
2001-12-14 23:30:31 +08:00
|
|
|
#include "gimplayer.h"
|
2001-01-29 00:44:22 +08:00
|
|
|
#include "gimplayermask.h"
|
2001-11-23 07:46:13 +08:00
|
|
|
#include "gimpmarshal.h"
|
2001-05-15 19:25:25 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2001-01-29 00:44:22 +08:00
|
|
|
|
|
|
|
|
2001-03-06 21:28:39 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
APPLY_CHANGED,
|
|
|
|
EDIT_CHANGED,
|
|
|
|
SHOW_CHANGED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-08-30 01:47:52 +08:00
|
|
|
static gboolean gimp_layer_mask_is_attached (const GimpItem *item);
|
2009-08-29 21:08:06 +08:00
|
|
|
static gboolean gimp_layer_mask_is_content_locked (const GimpItem *item);
|
2010-02-06 23:17:23 +08:00
|
|
|
static GimpItemTree * gimp_layer_mask_get_tree (GimpItem *item);
|
2009-08-29 21:08:06 +08:00
|
|
|
static GimpItem * gimp_layer_mask_duplicate (GimpItem *item,
|
|
|
|
GType new_type);
|
|
|
|
static gboolean gimp_layer_mask_rename (GimpItem *item,
|
|
|
|
const gchar *new_name,
|
|
|
|
const gchar *undo_desc,
|
|
|
|
GError **error);
|
|
|
|
|
2001-01-29 00:44:22 +08:00
|
|
|
|
2006-05-15 17:46:31 +08:00
|
|
|
G_DEFINE_TYPE (GimpLayerMask, gimp_layer_mask, GIMP_TYPE_CHANNEL)
|
2001-01-29 00:44:22 +08:00
|
|
|
|
2005-12-11 03:24:36 +08:00
|
|
|
#define parent_class gimp_layer_mask_parent_class
|
2001-03-06 21:28:39 +08:00
|
|
|
|
2005-12-11 03:24:36 +08:00
|
|
|
static guint layer_mask_signals[LAST_SIGNAL] = { 0 };
|
2001-01-29 00:44:22 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_layer_mask_class_init (GimpLayerMaskClass *klass)
|
|
|
|
{
|
2004-05-24 18:49:34 +08:00
|
|
|
GimpViewableClass *viewable_class = GIMP_VIEWABLE_CLASS (klass);
|
|
|
|
GimpItemClass *item_class = GIMP_ITEM_CLASS (klass);
|
2003-02-11 21:52:47 +08:00
|
|
|
|
2001-03-06 21:28:39 +08:00
|
|
|
layer_mask_signals[APPLY_CHANGED] =
|
2005-05-27 21:05:26 +08:00
|
|
|
g_signal_new ("apply-changed",
|
2004-03-17 00:23:06 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpLayerMaskClass, apply_changed),
|
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
2001-03-06 21:28:39 +08:00
|
|
|
|
|
|
|
layer_mask_signals[EDIT_CHANGED] =
|
2005-05-27 21:05:26 +08:00
|
|
|
g_signal_new ("edit-changed",
|
2004-03-17 00:23:06 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpLayerMaskClass, edit_changed),
|
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
2001-03-06 21:28:39 +08:00
|
|
|
|
|
|
|
layer_mask_signals[SHOW_CHANGED] =
|
2005-05-27 21:05:26 +08:00
|
|
|
g_signal_new ("show-changed",
|
2004-03-17 00:23:06 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpLayerMaskClass, show_changed),
|
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
2003-02-11 21:52:47 +08:00
|
|
|
|
2004-01-27 10:51:19 +08:00
|
|
|
viewable_class->default_stock_id = "gimp-layer-mask";
|
|
|
|
|
2010-10-03 06:28:40 +08:00
|
|
|
klass->edit_changed = NULL;
|
2008-01-04 05:53:34 +08:00
|
|
|
|
2009-08-29 21:08:06 +08:00
|
|
|
item_class->is_attached = gimp_layer_mask_is_attached;
|
|
|
|
item_class->is_content_locked = gimp_layer_mask_is_content_locked;
|
2010-02-06 23:17:23 +08:00
|
|
|
item_class->get_tree = gimp_layer_mask_get_tree;
|
2009-08-29 21:08:06 +08:00
|
|
|
item_class->duplicate = gimp_layer_mask_duplicate;
|
|
|
|
item_class->rename = gimp_layer_mask_rename;
|
2010-06-08 19:24:11 +08:00
|
|
|
item_class->translate_desc = C_("undo-type", "Move Layer Mask");
|
2010-07-21 05:09:19 +08:00
|
|
|
item_class->to_selection_desc = C_("undo-type", "Layer Mask to Selection");
|
2001-01-29 00:44:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_layer_mask_init (GimpLayerMask *layer_mask)
|
|
|
|
{
|
2001-03-06 21:28:39 +08:00
|
|
|
layer_mask->layer = NULL;
|
|
|
|
layer_mask->apply_mask = TRUE;
|
|
|
|
layer_mask->edit_mask = TRUE;
|
|
|
|
layer_mask->show_mask = FALSE;
|
2001-01-29 00:44:22 +08:00
|
|
|
}
|
|
|
|
|
2009-08-29 21:08:06 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_layer_mask_is_content_locked (const GimpItem *item)
|
|
|
|
{
|
|
|
|
GimpLayerMask *mask = GIMP_LAYER_MASK (item);
|
|
|
|
GimpLayer *layer = gimp_layer_mask_get_layer (mask);
|
|
|
|
|
|
|
|
if (layer)
|
|
|
|
return gimp_item_is_content_locked (GIMP_ITEM (layer));
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-01-27 00:18:16 +08:00
|
|
|
static gboolean
|
2009-08-30 01:47:52 +08:00
|
|
|
gimp_layer_mask_is_attached (const GimpItem *item)
|
2004-01-27 00:18:16 +08:00
|
|
|
{
|
|
|
|
GimpLayerMask *mask = GIMP_LAYER_MASK (item);
|
|
|
|
GimpLayer *layer = gimp_layer_mask_get_layer (mask);
|
|
|
|
|
2008-12-28 08:09:33 +08:00
|
|
|
return (GIMP_IS_IMAGE (gimp_item_get_image (item)) &&
|
|
|
|
GIMP_IS_LAYER (layer) &&
|
|
|
|
gimp_layer_get_mask (layer) == mask &&
|
2004-01-27 00:18:16 +08:00
|
|
|
gimp_item_is_attached (GIMP_ITEM (layer)));
|
|
|
|
}
|
|
|
|
|
2010-02-06 23:17:23 +08:00
|
|
|
static GimpItemTree *
|
|
|
|
gimp_layer_mask_get_tree (GimpItem *item)
|
2009-08-02 02:22:07 +08:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-02-11 21:52:47 +08:00
|
|
|
static GimpItem *
|
|
|
|
gimp_layer_mask_duplicate (GimpItem *item,
|
2008-01-08 19:46:15 +08:00
|
|
|
GType new_type)
|
2003-02-11 21:52:47 +08:00
|
|
|
{
|
2005-12-23 09:15:19 +08:00
|
|
|
GimpItem *new_item;
|
2003-02-11 21:52:47 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (g_type_is_a (new_type, GIMP_TYPE_DRAWABLE), NULL);
|
|
|
|
|
2008-01-08 19:46:15 +08:00
|
|
|
new_item = GIMP_ITEM_CLASS (parent_class)->duplicate (item, new_type);
|
2003-02-11 21:52:47 +08:00
|
|
|
|
2005-12-23 09:15:19 +08:00
|
|
|
if (GIMP_IS_LAYER_MASK (new_item))
|
|
|
|
{
|
|
|
|
GimpLayerMask *layer_mask = GIMP_LAYER_MASK (item);
|
|
|
|
GimpLayerMask *new_layer_mask = GIMP_LAYER_MASK (new_item);
|
2003-02-11 21:52:47 +08:00
|
|
|
|
2005-12-23 09:15:19 +08:00
|
|
|
new_layer_mask->apply_mask = layer_mask->apply_mask;
|
|
|
|
new_layer_mask->edit_mask = layer_mask->edit_mask;
|
|
|
|
new_layer_mask->show_mask = layer_mask->show_mask;
|
|
|
|
}
|
2003-02-11 21:52:47 +08:00
|
|
|
|
2003-02-14 18:21:30 +08:00
|
|
|
return new_item;
|
2003-02-11 21:52:47 +08:00
|
|
|
}
|
|
|
|
|
2004-02-02 04:38:26 +08:00
|
|
|
static gboolean
|
2007-12-12 21:57:11 +08:00
|
|
|
gimp_layer_mask_rename (GimpItem *item,
|
|
|
|
const gchar *new_name,
|
|
|
|
const gchar *undo_desc,
|
|
|
|
GError **error)
|
2004-02-02 04:38:26 +08:00
|
|
|
{
|
|
|
|
/* reject renaming, layer masks are always named "<layer name> mask" */
|
|
|
|
|
2008-11-12 18:56:06 +08:00
|
|
|
g_set_error (error, GIMP_ERROR, GIMP_FAILED,
|
|
|
|
_("Cannot rename layer masks."));
|
2007-12-12 21:57:11 +08:00
|
|
|
|
2004-02-02 04:38:26 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2001-01-29 00:44:22 +08:00
|
|
|
GimpLayerMask *
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_layer_mask_new (GimpImage *image,
|
2004-03-17 00:23:06 +08:00
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
const gchar *name,
|
|
|
|
const GimpRGB *color)
|
2001-01-29 00:44:22 +08:00
|
|
|
{
|
|
|
|
GimpLayerMask *layer_mask;
|
|
|
|
|
2001-08-10 22:41:39 +08:00
|
|
|
layer_mask = g_object_new (GIMP_TYPE_LAYER_MASK, NULL);
|
2001-01-29 00:44:22 +08:00
|
|
|
|
To optimize duplicate and/or wrong image updates away, introduced new
2003-09-06 Michael Natterer <mitch@gimp.org>
To optimize duplicate and/or wrong image updates away, introduced
new policy that a child object must never explicitly update or
invalidate its parent object (just like the GUI is not updated
explicitly by the core):
* app/core/gimpdrawable.[ch]: added new signal
GimpDrawable::update(). Never update or invalidate the image when
the drawable is updated or invalidated.
(gimp_drawable_set_visible): don't gimp_drawable_update() the
drawable since its pixels have not changed.
* app/core/gimpimage.[ch]: connect to the "add" and "remove"
signals of the layers and channels containers. Also connect to the
"update" and "visibility_changed" signals of all drawables in
these containers (optimizes away updates issued by drawables which
are not yet added to the image and updates of the selection
mask). Also, don't propagate updates to the image if the emitting
drawable is invisible (optimizes away updates issued by invisible
drawables).
(gimp_image_add_layer,channel)
(gimp_image_remove_layer,channel): don't update the image since
that's done by our "add" and "remove" handlers now.
(gimp_image_position_layer,channel): update just the image, not
the drawable since its pixels have not changed.
(gimp_image_real_colormap_changed)
(gimp_image_set_component_visible): always call
gimp_image_update() *and* gimp_viewable_invalidate_preview() to
get everything updated, since update and invalidate of images are
not connected.
* app/core/gimpimage-undo-push.c (undo_pop_layer,channel): don't
update the drawable since (a) its pixels don't change and (b) the
image updates itself upon adding/removing now.
(undo_pop_layer_mod): replaced gimp_image_update() by
gimp_drawable_update() (just for consistency with other similar
functions).
* app/core/gimplayer.c: connect to "update" of the layer mask and
issue updates on the layer if the mask update has any effect on
the projection.
(gimp_layer_create_mask): don't set the mask's offsets here since
they may be different when we later add the mask to the layer.
* app/core/gimplayermask.c (gimp_layer_mask_set_layer): set the
mask offsets here instead.
* app/core/gimpchannel.c (gimp_channel_translate): update the
channel even if push_undo == FALSE.
* app/paint/gimppaintcore.c (gimp_paint_core_finish)
* app/tools/gimpinktool.c (ink_finish): invalidate both the
drawable and the image preview since invalidating the drawable
doesn't invalidate the image any more.
* app/text/gimptextlayer.c (gimp_text_layer_render_now): also
update the new extents of the text layer, not only the old one.
(gimp_text_layer_render_layout): don't update the drawable since
gimp_drawable_fill() already updated it.
2003-09-07 04:06:53 +08:00
|
|
|
gimp_drawable_configure (GIMP_DRAWABLE (layer_mask),
|
2006-04-12 20:49:29 +08:00
|
|
|
image,
|
2003-02-01 00:37:03 +08:00
|
|
|
0, 0, width, height,
|
|
|
|
GIMP_GRAY_IMAGE, name);
|
2001-01-29 00:44:22 +08:00
|
|
|
|
|
|
|
/* set the layer_mask color and opacity */
|
2007-12-24 00:58:41 +08:00
|
|
|
gimp_channel_set_color (GIMP_CHANNEL (layer_mask), color, FALSE);
|
|
|
|
gimp_channel_set_show_masked (GIMP_CHANNEL (layer_mask), TRUE);
|
2001-01-29 00:44:22 +08:00
|
|
|
|
|
|
|
/* selection mask variables */
|
2001-12-13 07:48:18 +08:00
|
|
|
GIMP_CHANNEL (layer_mask)->x2 = width;
|
|
|
|
GIMP_CHANNEL (layer_mask)->y2 = height;
|
2001-01-29 00:44:22 +08:00
|
|
|
|
|
|
|
return layer_mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-12-14 23:30:31 +08:00
|
|
|
gimp_layer_mask_set_layer (GimpLayerMask *layer_mask,
|
2006-04-12 20:49:29 +08:00
|
|
|
GimpLayer *layer)
|
2001-01-29 00:44:22 +08:00
|
|
|
{
|
2001-12-14 23:30:31 +08:00
|
|
|
g_return_if_fail (GIMP_IS_LAYER_MASK (layer_mask));
|
To optimize duplicate and/or wrong image updates away, introduced new
2003-09-06 Michael Natterer <mitch@gimp.org>
To optimize duplicate and/or wrong image updates away, introduced
new policy that a child object must never explicitly update or
invalidate its parent object (just like the GUI is not updated
explicitly by the core):
* app/core/gimpdrawable.[ch]: added new signal
GimpDrawable::update(). Never update or invalidate the image when
the drawable is updated or invalidated.
(gimp_drawable_set_visible): don't gimp_drawable_update() the
drawable since its pixels have not changed.
* app/core/gimpimage.[ch]: connect to the "add" and "remove"
signals of the layers and channels containers. Also connect to the
"update" and "visibility_changed" signals of all drawables in
these containers (optimizes away updates issued by drawables which
are not yet added to the image and updates of the selection
mask). Also, don't propagate updates to the image if the emitting
drawable is invisible (optimizes away updates issued by invisible
drawables).
(gimp_image_add_layer,channel)
(gimp_image_remove_layer,channel): don't update the image since
that's done by our "add" and "remove" handlers now.
(gimp_image_position_layer,channel): update just the image, not
the drawable since its pixels have not changed.
(gimp_image_real_colormap_changed)
(gimp_image_set_component_visible): always call
gimp_image_update() *and* gimp_viewable_invalidate_preview() to
get everything updated, since update and invalidate of images are
not connected.
* app/core/gimpimage-undo-push.c (undo_pop_layer,channel): don't
update the drawable since (a) its pixels don't change and (b) the
image updates itself upon adding/removing now.
(undo_pop_layer_mod): replaced gimp_image_update() by
gimp_drawable_update() (just for consistency with other similar
functions).
* app/core/gimplayer.c: connect to "update" of the layer mask and
issue updates on the layer if the mask update has any effect on
the projection.
(gimp_layer_create_mask): don't set the mask's offsets here since
they may be different when we later add the mask to the layer.
* app/core/gimplayermask.c (gimp_layer_mask_set_layer): set the
mask offsets here instead.
* app/core/gimpchannel.c (gimp_channel_translate): update the
channel even if push_undo == FALSE.
* app/paint/gimppaintcore.c (gimp_paint_core_finish)
* app/tools/gimpinktool.c (ink_finish): invalidate both the
drawable and the image preview since invalidating the drawable
doesn't invalidate the image any more.
* app/text/gimptextlayer.c (gimp_text_layer_render_now): also
update the new extents of the text layer, not only the old one.
(gimp_text_layer_render_layout): don't update the drawable since
gimp_drawable_fill() already updated it.
2003-09-07 04:06:53 +08:00
|
|
|
g_return_if_fail (layer == NULL || GIMP_IS_LAYER (layer));
|
2001-12-14 23:30:31 +08:00
|
|
|
|
|
|
|
layer_mask->layer = layer;
|
To optimize duplicate and/or wrong image updates away, introduced new
2003-09-06 Michael Natterer <mitch@gimp.org>
To optimize duplicate and/or wrong image updates away, introduced
new policy that a child object must never explicitly update or
invalidate its parent object (just like the GUI is not updated
explicitly by the core):
* app/core/gimpdrawable.[ch]: added new signal
GimpDrawable::update(). Never update or invalidate the image when
the drawable is updated or invalidated.
(gimp_drawable_set_visible): don't gimp_drawable_update() the
drawable since its pixels have not changed.
* app/core/gimpimage.[ch]: connect to the "add" and "remove"
signals of the layers and channels containers. Also connect to the
"update" and "visibility_changed" signals of all drawables in
these containers (optimizes away updates issued by drawables which
are not yet added to the image and updates of the selection
mask). Also, don't propagate updates to the image if the emitting
drawable is invisible (optimizes away updates issued by invisible
drawables).
(gimp_image_add_layer,channel)
(gimp_image_remove_layer,channel): don't update the image since
that's done by our "add" and "remove" handlers now.
(gimp_image_position_layer,channel): update just the image, not
the drawable since its pixels have not changed.
(gimp_image_real_colormap_changed)
(gimp_image_set_component_visible): always call
gimp_image_update() *and* gimp_viewable_invalidate_preview() to
get everything updated, since update and invalidate of images are
not connected.
* app/core/gimpimage-undo-push.c (undo_pop_layer,channel): don't
update the drawable since (a) its pixels don't change and (b) the
image updates itself upon adding/removing now.
(undo_pop_layer_mod): replaced gimp_image_update() by
gimp_drawable_update() (just for consistency with other similar
functions).
* app/core/gimplayer.c: connect to "update" of the layer mask and
issue updates on the layer if the mask update has any effect on
the projection.
(gimp_layer_create_mask): don't set the mask's offsets here since
they may be different when we later add the mask to the layer.
* app/core/gimplayermask.c (gimp_layer_mask_set_layer): set the
mask offsets here instead.
* app/core/gimpchannel.c (gimp_channel_translate): update the
channel even if push_undo == FALSE.
* app/paint/gimppaintcore.c (gimp_paint_core_finish)
* app/tools/gimpinktool.c (ink_finish): invalidate both the
drawable and the image preview since invalidating the drawable
doesn't invalidate the image any more.
* app/text/gimptextlayer.c (gimp_text_layer_render_now): also
update the new extents of the text layer, not only the old one.
(gimp_text_layer_render_layout): don't update the drawable since
gimp_drawable_fill() already updated it.
2003-09-07 04:06:53 +08:00
|
|
|
|
|
|
|
if (layer)
|
|
|
|
{
|
2004-02-02 04:38:26 +08:00
|
|
|
gchar *mask_name;
|
2008-11-04 05:17:50 +08:00
|
|
|
gint offset_x;
|
|
|
|
gint offset_y;
|
2004-02-02 04:38:26 +08:00
|
|
|
|
2008-11-04 05:17:50 +08:00
|
|
|
gimp_item_get_offset (GIMP_ITEM (layer), &offset_x, &offset_y);
|
|
|
|
gimp_item_set_offset (GIMP_ITEM (layer_mask), offset_x, offset_y);
|
2004-02-02 04:38:26 +08:00
|
|
|
|
2009-09-01 04:47:18 +08:00
|
|
|
mask_name = g_strdup_printf (_("%s mask"), gimp_object_get_name (layer));
|
2006-04-07 18:51:22 +08:00
|
|
|
|
|
|
|
gimp_object_take_name (GIMP_OBJECT (layer_mask), mask_name);
|
To optimize duplicate and/or wrong image updates away, introduced new
2003-09-06 Michael Natterer <mitch@gimp.org>
To optimize duplicate and/or wrong image updates away, introduced
new policy that a child object must never explicitly update or
invalidate its parent object (just like the GUI is not updated
explicitly by the core):
* app/core/gimpdrawable.[ch]: added new signal
GimpDrawable::update(). Never update or invalidate the image when
the drawable is updated or invalidated.
(gimp_drawable_set_visible): don't gimp_drawable_update() the
drawable since its pixels have not changed.
* app/core/gimpimage.[ch]: connect to the "add" and "remove"
signals of the layers and channels containers. Also connect to the
"update" and "visibility_changed" signals of all drawables in
these containers (optimizes away updates issued by drawables which
are not yet added to the image and updates of the selection
mask). Also, don't propagate updates to the image if the emitting
drawable is invisible (optimizes away updates issued by invisible
drawables).
(gimp_image_add_layer,channel)
(gimp_image_remove_layer,channel): don't update the image since
that's done by our "add" and "remove" handlers now.
(gimp_image_position_layer,channel): update just the image, not
the drawable since its pixels have not changed.
(gimp_image_real_colormap_changed)
(gimp_image_set_component_visible): always call
gimp_image_update() *and* gimp_viewable_invalidate_preview() to
get everything updated, since update and invalidate of images are
not connected.
* app/core/gimpimage-undo-push.c (undo_pop_layer,channel): don't
update the drawable since (a) its pixels don't change and (b) the
image updates itself upon adding/removing now.
(undo_pop_layer_mod): replaced gimp_image_update() by
gimp_drawable_update() (just for consistency with other similar
functions).
* app/core/gimplayer.c: connect to "update" of the layer mask and
issue updates on the layer if the mask update has any effect on
the projection.
(gimp_layer_create_mask): don't set the mask's offsets here since
they may be different when we later add the mask to the layer.
* app/core/gimplayermask.c (gimp_layer_mask_set_layer): set the
mask offsets here instead.
* app/core/gimpchannel.c (gimp_channel_translate): update the
channel even if push_undo == FALSE.
* app/paint/gimppaintcore.c (gimp_paint_core_finish)
* app/tools/gimpinktool.c (ink_finish): invalidate both the
drawable and the image preview since invalidating the drawable
doesn't invalidate the image any more.
* app/text/gimptextlayer.c (gimp_text_layer_render_now): also
update the new extents of the text layer, not only the old one.
(gimp_text_layer_render_layout): don't update the drawable since
gimp_drawable_fill() already updated it.
2003-09-07 04:06:53 +08:00
|
|
|
}
|
2001-01-29 00:44:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GimpLayer *
|
2001-12-14 23:30:31 +08:00
|
|
|
gimp_layer_mask_get_layer (const GimpLayerMask *layer_mask)
|
2001-01-29 00:44:22 +08:00
|
|
|
{
|
2001-12-14 23:30:31 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_LAYER_MASK (layer_mask), NULL);
|
|
|
|
|
|
|
|
return layer_mask->layer;
|
2001-01-29 00:44:22 +08:00
|
|
|
}
|
2001-03-06 21:28:39 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
gimp_layer_mask_set_apply (GimpLayerMask *layer_mask,
|
2005-03-25 01:10:03 +08:00
|
|
|
gboolean apply,
|
|
|
|
gboolean push_undo)
|
2001-03-06 21:28:39 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_LAYER_MASK (layer_mask));
|
|
|
|
|
|
|
|
if (layer_mask->apply_mask != apply)
|
|
|
|
{
|
2008-12-28 08:09:33 +08:00
|
|
|
GimpImage *image = gimp_item_get_image (GIMP_ITEM (layer_mask));
|
2005-03-25 01:10:03 +08:00
|
|
|
|
|
|
|
if (push_undo)
|
2010-06-08 19:24:11 +08:00
|
|
|
gimp_image_undo_push_layer_mask_apply (image, C_("undo-type", "Apply Layer Mask"),
|
2005-03-25 06:15:10 +08:00
|
|
|
layer_mask);
|
2005-03-25 01:10:03 +08:00
|
|
|
|
2001-12-14 23:30:31 +08:00
|
|
|
layer_mask->apply_mask = apply ? TRUE : FALSE;
|
2001-03-06 21:28:39 +08:00
|
|
|
|
|
|
|
if (layer_mask->layer)
|
|
|
|
{
|
2004-03-17 00:23:06 +08:00
|
|
|
GimpDrawable *drawable = GIMP_DRAWABLE (layer_mask->layer);
|
2001-03-06 21:28:39 +08:00
|
|
|
|
2001-07-08 06:49:01 +08:00
|
|
|
gimp_drawable_update (drawable,
|
2006-04-12 20:49:29 +08:00
|
|
|
0, 0,
|
2008-11-03 08:09:01 +08:00
|
|
|
gimp_item_get_width (GIMP_ITEM (drawable)),
|
|
|
|
gimp_item_get_height (GIMP_ITEM (drawable)));
|
2001-03-06 21:28:39 +08:00
|
|
|
}
|
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_emit (layer_mask, layer_mask_signals[APPLY_CHANGED], 0);
|
2001-03-06 21:28:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2001-12-13 07:48:18 +08:00
|
|
|
gimp_layer_mask_get_apply (const GimpLayerMask *layer_mask)
|
2001-03-06 21:28:39 +08:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_LAYER_MASK (layer_mask), FALSE);
|
|
|
|
|
|
|
|
return layer_mask->apply_mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_layer_mask_set_edit (GimpLayerMask *layer_mask,
|
2005-03-25 06:34:36 +08:00
|
|
|
gboolean edit)
|
2001-03-06 21:28:39 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_LAYER_MASK (layer_mask));
|
|
|
|
|
|
|
|
if (layer_mask->edit_mask != edit)
|
|
|
|
{
|
2001-12-14 23:30:31 +08:00
|
|
|
layer_mask->edit_mask = edit ? TRUE : FALSE;
|
2001-03-06 21:28:39 +08:00
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_emit (layer_mask, layer_mask_signals[EDIT_CHANGED], 0);
|
2001-03-06 21:28:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2001-12-13 07:48:18 +08:00
|
|
|
gimp_layer_mask_get_edit (const GimpLayerMask *layer_mask)
|
2001-03-06 21:28:39 +08:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_LAYER_MASK (layer_mask), FALSE);
|
|
|
|
|
|
|
|
return layer_mask->edit_mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_layer_mask_set_show (GimpLayerMask *layer_mask,
|
2005-03-25 01:10:03 +08:00
|
|
|
gboolean show,
|
|
|
|
gboolean push_undo)
|
2001-03-06 21:28:39 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_LAYER_MASK (layer_mask));
|
|
|
|
|
|
|
|
if (layer_mask->show_mask != show)
|
|
|
|
{
|
2008-12-28 08:09:33 +08:00
|
|
|
GimpImage *image = gimp_item_get_image (GIMP_ITEM (layer_mask));
|
2005-03-25 01:10:03 +08:00
|
|
|
|
|
|
|
if (push_undo)
|
2010-06-08 19:24:11 +08:00
|
|
|
gimp_image_undo_push_layer_mask_show (image, C_("undo-type", "Show Layer Mask"),
|
2005-03-25 06:15:10 +08:00
|
|
|
layer_mask);
|
2005-03-25 01:10:03 +08:00
|
|
|
|
2001-12-14 23:30:31 +08:00
|
|
|
layer_mask->show_mask = show ? TRUE : FALSE;
|
2001-03-06 21:28:39 +08:00
|
|
|
|
|
|
|
if (layer_mask->layer)
|
|
|
|
{
|
2004-03-17 00:23:06 +08:00
|
|
|
GimpDrawable *drawable = GIMP_DRAWABLE (layer_mask->layer);
|
2001-03-06 21:28:39 +08:00
|
|
|
|
2001-07-08 06:49:01 +08:00
|
|
|
gimp_drawable_update (drawable,
|
2006-04-12 20:49:29 +08:00
|
|
|
0, 0,
|
2008-11-03 08:09:01 +08:00
|
|
|
gimp_item_get_width (GIMP_ITEM (drawable)),
|
|
|
|
gimp_item_get_height (GIMP_ITEM (drawable)));
|
2001-03-06 21:28:39 +08:00
|
|
|
}
|
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_emit (layer_mask, layer_mask_signals[SHOW_CHANGED], 0);
|
2001-03-06 21:28:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2001-12-13 07:48:18 +08:00
|
|
|
gimp_layer_mask_get_show (const GimpLayerMask *layer_mask)
|
2001-03-06 21:28:39 +08:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_LAYER_MASK (layer_mask), FALSE);
|
|
|
|
|
|
|
|
return layer_mask->show_mask;
|
|
|
|
}
|