2008-10-10 20:04:03 +00:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimpdrawablestack.c
|
|
|
|
* Copyright (C) 2008 Michael Natterer <mitch@gimp.org>
|
|
|
|
*
|
2009-01-17 22:28:01 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2008-10-10 20:04:03 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 22:28:01 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2008-10-10 20:04:03 +00: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
|
2018-07-11 23:27:07 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2008-10-10 20:04:03 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2013-10-15 01:58:39 +02:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2008-10-10 20:04:03 +00:00
|
|
|
#include <gegl.h>
|
|
|
|
|
|
|
|
#include "core-types.h"
|
|
|
|
|
|
|
|
#include "gimpdrawable.h"
|
|
|
|
#include "gimpdrawablestack.h"
|
2008-11-02 19:53:51 +00:00
|
|
|
#include "gimpmarshal.h"
|
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
UPDATE,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
2008-10-10 20:04:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* local function prototypes */
|
|
|
|
|
2011-01-12 22:53:58 +01:00
|
|
|
static void gimp_drawable_stack_constructed (GObject *object);
|
|
|
|
|
|
|
|
static void gimp_drawable_stack_add (GimpContainer *container,
|
|
|
|
GimpObject *object);
|
|
|
|
static void gimp_drawable_stack_remove (GimpContainer *container,
|
|
|
|
GimpObject *object);
|
|
|
|
static void gimp_drawable_stack_reorder (GimpContainer *container,
|
|
|
|
GimpObject *object,
|
2025-08-08 17:01:50 +02:00
|
|
|
gint old_index,
|
2011-01-12 22:53:58 +01:00
|
|
|
gint new_index);
|
|
|
|
|
|
|
|
static void gimp_drawable_stack_drawable_update (GimpItem *item,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
GimpDrawableStack *stack);
|
app: add GimpFilter::active property; move ::visible to GimpItem
Add an "active" property to GimpFilter, which replaces its
"visible" property. The new property assumes the lower-level role
"visible" had -- controlling whether the filter has any effect as
part of its parent filter-stack.
Add a "visible" property to GimpItem, separate from the "active"
property, which assumes the higher-level role "visible" had --
controlling whether the item is considered "visible", as per the
GUI. By default, the item's "visible" property is bound to the
filter's "active" property, so that changes in visibility directly
affect the filter's "activeness"; this binding can be controlled
using the new gimp_item_bind_visible_to_active() function.
This distinction is currently necessary for floating selections.
Floating selection layers must not be active in their parent stack,
regardless of their visibility, in particular, so that their mode
node doesn't hide the entire backdrop when their composite mode
excludes the backdrop (i.e., when it's dst-atop or src-in).
Instead, their visibility should affect the activeness of the
floating-selection filter of the drawable they're attached to.
This is handled by the next commit.
2017-12-05 13:46:50 -05:00
|
|
|
static void gimp_drawable_stack_drawable_active (GimpItem *item,
|
2011-01-12 22:53:58 +01:00
|
|
|
GimpDrawableStack *stack);
|
2008-10-10 20:04:03 +00:00
|
|
|
|
|
|
|
|
2008-11-06 19:09:59 +00:00
|
|
|
G_DEFINE_TYPE (GimpDrawableStack, gimp_drawable_stack, GIMP_TYPE_ITEM_STACK)
|
2008-10-10 20:04:03 +00:00
|
|
|
|
|
|
|
#define parent_class gimp_drawable_stack_parent_class
|
|
|
|
|
2008-11-02 19:53:51 +00:00
|
|
|
static guint stack_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2008-10-10 20:04:03 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_drawable_stack_class_init (GimpDrawableStackClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpContainerClass *container_class = GIMP_CONTAINER_CLASS (klass);
|
|
|
|
|
2008-11-02 19:53:51 +00:00
|
|
|
stack_signals[UPDATE] =
|
|
|
|
g_signal_new ("update",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpDrawableStackClass, update),
|
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__INT_INT_INT_INT,
|
|
|
|
G_TYPE_NONE, 4,
|
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_INT);
|
|
|
|
|
2011-01-12 22:53:58 +01:00
|
|
|
object_class->constructed = gimp_drawable_stack_constructed;
|
2008-11-02 19:53:51 +00:00
|
|
|
|
|
|
|
container_class->add = gimp_drawable_stack_add;
|
|
|
|
container_class->remove = gimp_drawable_stack_remove;
|
|
|
|
container_class->reorder = gimp_drawable_stack_reorder;
|
2008-10-10 20:04:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-11-02 19:53:51 +00:00
|
|
|
gimp_drawable_stack_init (GimpDrawableStack *stack)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-01-12 22:53:58 +01:00
|
|
|
static void
|
|
|
|
gimp_drawable_stack_constructed (GObject *object)
|
2008-10-10 20:04:03 +00:00
|
|
|
{
|
2011-01-12 22:53:58 +01:00
|
|
|
GimpContainer *container = GIMP_CONTAINER (object);
|
2008-11-02 19:53:51 +00:00
|
|
|
|
2012-11-12 21:51:22 +01:00
|
|
|
G_OBJECT_CLASS (parent_class)->constructed (object);
|
2008-11-02 19:53:51 +00:00
|
|
|
|
2025-07-17 09:44:09 +02:00
|
|
|
gimp_assert (g_type_is_a (gimp_container_get_child_type (container),
|
2018-02-11 22:23:10 +01:00
|
|
|
GIMP_TYPE_DRAWABLE));
|
2008-11-02 19:53:51 +00:00
|
|
|
|
|
|
|
gimp_container_add_handler (container, "update",
|
|
|
|
G_CALLBACK (gimp_drawable_stack_drawable_update),
|
|
|
|
container);
|
app: add GimpFilter::active property; move ::visible to GimpItem
Add an "active" property to GimpFilter, which replaces its
"visible" property. The new property assumes the lower-level role
"visible" had -- controlling whether the filter has any effect as
part of its parent filter-stack.
Add a "visible" property to GimpItem, separate from the "active"
property, which assumes the higher-level role "visible" had --
controlling whether the item is considered "visible", as per the
GUI. By default, the item's "visible" property is bound to the
filter's "active" property, so that changes in visibility directly
affect the filter's "activeness"; this binding can be controlled
using the new gimp_item_bind_visible_to_active() function.
This distinction is currently necessary for floating selections.
Floating selection layers must not be active in their parent stack,
regardless of their visibility, in particular, so that their mode
node doesn't hide the entire backdrop when their composite mode
excludes the backdrop (i.e., when it's dst-atop or src-in).
Instead, their visibility should affect the activeness of the
floating-selection filter of the drawable they're attached to.
This is handled by the next commit.
2017-12-05 13:46:50 -05:00
|
|
|
gimp_container_add_handler (container, "active-changed",
|
|
|
|
G_CALLBACK (gimp_drawable_stack_drawable_active),
|
2008-11-02 19:53:51 +00:00
|
|
|
container);
|
2008-10-10 20:04:03 +00:00
|
|
|
}
|
|
|
|
|
2008-10-11 10:18:46 +00:00
|
|
|
static void
|
|
|
|
gimp_drawable_stack_add (GimpContainer *container,
|
|
|
|
GimpObject *object)
|
|
|
|
{
|
|
|
|
GimpDrawableStack *stack = GIMP_DRAWABLE_STACK (container);
|
|
|
|
|
|
|
|
GIMP_CONTAINER_CLASS (parent_class)->add (container, object);
|
|
|
|
|
app: add GimpFilter::active property; move ::visible to GimpItem
Add an "active" property to GimpFilter, which replaces its
"visible" property. The new property assumes the lower-level role
"visible" had -- controlling whether the filter has any effect as
part of its parent filter-stack.
Add a "visible" property to GimpItem, separate from the "active"
property, which assumes the higher-level role "visible" had --
controlling whether the item is considered "visible", as per the
GUI. By default, the item's "visible" property is bound to the
filter's "active" property, so that changes in visibility directly
affect the filter's "activeness"; this binding can be controlled
using the new gimp_item_bind_visible_to_active() function.
This distinction is currently necessary for floating selections.
Floating selection layers must not be active in their parent stack,
regardless of their visibility, in particular, so that their mode
node doesn't hide the entire backdrop when their composite mode
excludes the backdrop (i.e., when it's dst-atop or src-in).
Instead, their visibility should affect the activeness of the
floating-selection filter of the drawable they're attached to.
This is handled by the next commit.
2017-12-05 13:46:50 -05:00
|
|
|
if (gimp_filter_get_active (GIMP_FILTER (object)))
|
|
|
|
gimp_drawable_stack_drawable_active (GIMP_ITEM (object), stack);
|
2008-10-11 10:18:46 +00:00
|
|
|
}
|
|
|
|
|
2008-10-10 20:04:03 +00:00
|
|
|
static void
|
|
|
|
gimp_drawable_stack_remove (GimpContainer *container,
|
|
|
|
GimpObject *object)
|
|
|
|
{
|
2008-10-10 21:18:24 +00:00
|
|
|
GimpDrawableStack *stack = GIMP_DRAWABLE_STACK (container);
|
|
|
|
|
2008-10-10 20:04:03 +00:00
|
|
|
GIMP_CONTAINER_CLASS (parent_class)->remove (container, object);
|
2008-11-02 19:53:51 +00:00
|
|
|
|
app: add GimpFilter::active property; move ::visible to GimpItem
Add an "active" property to GimpFilter, which replaces its
"visible" property. The new property assumes the lower-level role
"visible" had -- controlling whether the filter has any effect as
part of its parent filter-stack.
Add a "visible" property to GimpItem, separate from the "active"
property, which assumes the higher-level role "visible" had --
controlling whether the item is considered "visible", as per the
GUI. By default, the item's "visible" property is bound to the
filter's "active" property, so that changes in visibility directly
affect the filter's "activeness"; this binding can be controlled
using the new gimp_item_bind_visible_to_active() function.
This distinction is currently necessary for floating selections.
Floating selection layers must not be active in their parent stack,
regardless of their visibility, in particular, so that their mode
node doesn't hide the entire backdrop when their composite mode
excludes the backdrop (i.e., when it's dst-atop or src-in).
Instead, their visibility should affect the activeness of the
floating-selection filter of the drawable they're attached to.
This is handled by the next commit.
2017-12-05 13:46:50 -05:00
|
|
|
if (gimp_filter_get_active (GIMP_FILTER (object)))
|
|
|
|
gimp_drawable_stack_drawable_active (GIMP_ITEM (object), stack);
|
2008-10-10 20:04:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_drawable_stack_reorder (GimpContainer *container,
|
|
|
|
GimpObject *object,
|
2025-08-08 17:01:50 +02:00
|
|
|
gint old_index,
|
2008-10-10 20:04:03 +00:00
|
|
|
gint new_index)
|
|
|
|
{
|
2013-04-11 03:47:07 +02:00
|
|
|
GimpDrawableStack *stack = GIMP_DRAWABLE_STACK (container);
|
2008-10-10 21:18:24 +00:00
|
|
|
|
2025-08-08 17:01:50 +02:00
|
|
|
GIMP_CONTAINER_CLASS (parent_class)->reorder (container, object,
|
|
|
|
old_index, new_index);
|
2008-10-10 21:18:24 +00:00
|
|
|
|
app: add GimpFilter::active property; move ::visible to GimpItem
Add an "active" property to GimpFilter, which replaces its
"visible" property. The new property assumes the lower-level role
"visible" had -- controlling whether the filter has any effect as
part of its parent filter-stack.
Add a "visible" property to GimpItem, separate from the "active"
property, which assumes the higher-level role "visible" had --
controlling whether the item is considered "visible", as per the
GUI. By default, the item's "visible" property is bound to the
filter's "active" property, so that changes in visibility directly
affect the filter's "activeness"; this binding can be controlled
using the new gimp_item_bind_visible_to_active() function.
This distinction is currently necessary for floating selections.
Floating selection layers must not be active in their parent stack,
regardless of their visibility, in particular, so that their mode
node doesn't hide the entire backdrop when their composite mode
excludes the backdrop (i.e., when it's dst-atop or src-in).
Instead, their visibility should affect the activeness of the
floating-selection filter of the drawable they're attached to.
This is handled by the next commit.
2017-12-05 13:46:50 -05:00
|
|
|
if (gimp_filter_get_active (GIMP_FILTER (object)))
|
|
|
|
gimp_drawable_stack_drawable_active (GIMP_ITEM (object), stack);
|
2008-10-10 20:04:03 +00:00
|
|
|
}
|
|
|
|
|
2008-10-10 21:18:24 +00:00
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2008-10-10 20:04:03 +00:00
|
|
|
GimpContainer *
|
|
|
|
gimp_drawable_stack_new (GType drawable_type)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (g_type_is_a (drawable_type, GIMP_TYPE_DRAWABLE), NULL);
|
|
|
|
|
|
|
|
return g_object_new (GIMP_TYPE_DRAWABLE_STACK,
|
2025-07-17 09:28:26 +02:00
|
|
|
"name", g_type_name (drawable_type),
|
|
|
|
"child-type", drawable_type,
|
|
|
|
"policy", GIMP_CONTAINER_POLICY_STRONG,
|
2008-10-10 20:04:03 +00:00
|
|
|
NULL);
|
|
|
|
}
|
2008-10-10 21:18:24 +00:00
|
|
|
|
|
|
|
|
2017-05-08 16:02:37 -04:00
|
|
|
/* protected functions */
|
2008-10-10 21:18:24 +00:00
|
|
|
|
2017-05-08 16:02:37 -04:00
|
|
|
void
|
2008-11-02 19:53:51 +00:00
|
|
|
gimp_drawable_stack_update (GimpDrawableStack *stack,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
|
|
|
{
|
2017-05-08 16:02:37 -04:00
|
|
|
g_return_if_fail (GIMP_IS_DRAWABLE_STACK (stack));
|
|
|
|
|
2008-11-02 19:53:51 +00:00
|
|
|
g_signal_emit (stack, stack_signals[UPDATE], 0,
|
|
|
|
x, y, width, height);
|
|
|
|
}
|
|
|
|
|
2017-05-08 16:02:37 -04:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2008-11-02 19:53:51 +00:00
|
|
|
static void
|
|
|
|
gimp_drawable_stack_drawable_update (GimpItem *item,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
GimpDrawableStack *stack)
|
|
|
|
{
|
app: add GimpFilter::active property; move ::visible to GimpItem
Add an "active" property to GimpFilter, which replaces its
"visible" property. The new property assumes the lower-level role
"visible" had -- controlling whether the filter has any effect as
part of its parent filter-stack.
Add a "visible" property to GimpItem, separate from the "active"
property, which assumes the higher-level role "visible" had --
controlling whether the item is considered "visible", as per the
GUI. By default, the item's "visible" property is bound to the
filter's "active" property, so that changes in visibility directly
affect the filter's "activeness"; this binding can be controlled
using the new gimp_item_bind_visible_to_active() function.
This distinction is currently necessary for floating selections.
Floating selection layers must not be active in their parent stack,
regardless of their visibility, in particular, so that their mode
node doesn't hide the entire backdrop when their composite mode
excludes the backdrop (i.e., when it's dst-atop or src-in).
Instead, their visibility should affect the activeness of the
floating-selection filter of the drawable they're attached to.
This is handled by the next commit.
2017-12-05 13:46:50 -05:00
|
|
|
if (gimp_filter_get_active (GIMP_FILTER (item)))
|
2008-11-02 19:53:51 +00:00
|
|
|
{
|
|
|
|
gint offset_x;
|
|
|
|
gint offset_y;
|
|
|
|
|
2008-11-02 23:03:29 +00:00
|
|
|
gimp_item_get_offset (item, &offset_x, &offset_y);
|
2008-11-02 19:53:51 +00:00
|
|
|
|
|
|
|
gimp_drawable_stack_update (stack,
|
|
|
|
x + offset_x, y + offset_y,
|
|
|
|
width, height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
app: add GimpFilter::active property; move ::visible to GimpItem
Add an "active" property to GimpFilter, which replaces its
"visible" property. The new property assumes the lower-level role
"visible" had -- controlling whether the filter has any effect as
part of its parent filter-stack.
Add a "visible" property to GimpItem, separate from the "active"
property, which assumes the higher-level role "visible" had --
controlling whether the item is considered "visible", as per the
GUI. By default, the item's "visible" property is bound to the
filter's "active" property, so that changes in visibility directly
affect the filter's "activeness"; this binding can be controlled
using the new gimp_item_bind_visible_to_active() function.
This distinction is currently necessary for floating selections.
Floating selection layers must not be active in their parent stack,
regardless of their visibility, in particular, so that their mode
node doesn't hide the entire backdrop when their composite mode
excludes the backdrop (i.e., when it's dst-atop or src-in).
Instead, their visibility should affect the activeness of the
floating-selection filter of the drawable they're attached to.
This is handled by the next commit.
2017-12-05 13:46:50 -05:00
|
|
|
gimp_drawable_stack_drawable_active (GimpItem *item,
|
|
|
|
GimpDrawableStack *stack)
|
2008-11-02 19:53:51 +00:00
|
|
|
{
|
app: maintain drawable bounding box separately from its logical boundary
Maintain the bounding box of drawables (i.e., the bounds of their
actual rendered content) separately from their logical boundary (as
shown in the UI).
The bounding box is calculated through the new
GimpDrawable::get_bounding_box() virtual function, which has a
corresponding gimp_drawable_get_bounding_box() function; the
default implementation simply returns the drawable's logical
boundary. The bounding box is specified in drawable coordinates,
i.e., it's not affected by the drawable's offset.
The bounding box is recalculated through
gimp_drawable_update_bounding_box(), which should be called
whenever a change may affect the bounding box (for example, when
setting a new buffer, as done implicitly by GimpDrawable's
::set_buffer() implementation, or when a drawable filter's
properties change, as will be done by GimpDrawableFilter in a
following commit). When the bounding box changes, the affected
regions of the drawable are updated, and the
GimpDrawable::bounding-box-changed signal is emitted.
When gimp_drawable_update() is called with negative width/height
values, the entire drawable's bounding box is updated, rather than
only its logical boundary.
Likewise, GimpDrawableStack and GimpLayerStack are adapted to use
the bounding box, instead of the logical bounds, when updating the
drawable's area.
2019-08-01 21:52:40 +03:00
|
|
|
GeglRectangle bounding_box;
|
2008-11-02 19:53:51 +00:00
|
|
|
|
app: maintain drawable bounding box separately from its logical boundary
Maintain the bounding box of drawables (i.e., the bounds of their
actual rendered content) separately from their logical boundary (as
shown in the UI).
The bounding box is calculated through the new
GimpDrawable::get_bounding_box() virtual function, which has a
corresponding gimp_drawable_get_bounding_box() function; the
default implementation simply returns the drawable's logical
boundary. The bounding box is specified in drawable coordinates,
i.e., it's not affected by the drawable's offset.
The bounding box is recalculated through
gimp_drawable_update_bounding_box(), which should be called
whenever a change may affect the bounding box (for example, when
setting a new buffer, as done implicitly by GimpDrawable's
::set_buffer() implementation, or when a drawable filter's
properties change, as will be done by GimpDrawableFilter in a
following commit). When the bounding box changes, the affected
regions of the drawable are updated, and the
GimpDrawable::bounding-box-changed signal is emitted.
When gimp_drawable_update() is called with negative width/height
values, the entire drawable's bounding box is updated, rather than
only its logical boundary.
Likewise, GimpDrawableStack and GimpLayerStack are adapted to use
the bounding box, instead of the logical bounds, when updating the
drawable's area.
2019-08-01 21:52:40 +03:00
|
|
|
bounding_box = gimp_drawable_get_bounding_box (GIMP_DRAWABLE (item));
|
|
|
|
|
|
|
|
bounding_box.x += gimp_item_get_offset_x (item);
|
|
|
|
bounding_box.y += gimp_item_get_offset_y (item);
|
2008-11-02 19:53:51 +00:00
|
|
|
|
|
|
|
gimp_drawable_stack_update (stack,
|
app: maintain drawable bounding box separately from its logical boundary
Maintain the bounding box of drawables (i.e., the bounds of their
actual rendered content) separately from their logical boundary (as
shown in the UI).
The bounding box is calculated through the new
GimpDrawable::get_bounding_box() virtual function, which has a
corresponding gimp_drawable_get_bounding_box() function; the
default implementation simply returns the drawable's logical
boundary. The bounding box is specified in drawable coordinates,
i.e., it's not affected by the drawable's offset.
The bounding box is recalculated through
gimp_drawable_update_bounding_box(), which should be called
whenever a change may affect the bounding box (for example, when
setting a new buffer, as done implicitly by GimpDrawable's
::set_buffer() implementation, or when a drawable filter's
properties change, as will be done by GimpDrawableFilter in a
following commit). When the bounding box changes, the affected
regions of the drawable are updated, and the
GimpDrawable::bounding-box-changed signal is emitted.
When gimp_drawable_update() is called with negative width/height
values, the entire drawable's bounding box is updated, rather than
only its logical boundary.
Likewise, GimpDrawableStack and GimpLayerStack are adapted to use
the bounding box, instead of the logical bounds, when updating the
drawable's area.
2019-08-01 21:52:40 +03:00
|
|
|
bounding_box.x, bounding_box.y,
|
|
|
|
bounding_box.width, bounding_box.height);
|
2008-11-02 19:53:51 +00:00
|
|
|
}
|