[gimp] app: in GimpDrawable::set_buffer(), take bounds rect instead of offset only
- From: Ell <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: in GimpDrawable::set_buffer(), take bounds rect instead of offset only
- Date: Thu, 1 Aug 2019 21:41:50 +0000 (UTC)
commit 3afdd7c5c2bbaebe088cd021be1b1d1b89f996c4
Author: Ell <ell_se yahoo com>
Date: Thu Aug 1 21:41:47 2019 +0300
app: in GimpDrawable::set_buffer(), take bounds rect instead of offset only
In GimpDrawable::set_buffer(), and the corresponding
gimp_drawable_set_buffer_full() function, take a bounds rectangle,
which specifies both the drawable's new offset and its new size,
instead of only taking the new offset. In
gimp_drawable_real_set_buffer(), set the item size according to the
rect dimensions, instead of the buffer dimensions. The rect's
width/height may be 0, in which case the buffer's dimensions are
used.
Adapt the rest of the code.
We do this in preparation for maintaining the drawable's bounding
box separately from its logical bounds, allowing the drawable
content to extend beyond its bounds.
app/core/gimpchannel.c | 26 ++++++------
app/core/gimpdrawable-transform.c | 2 +-
app/core/gimpdrawable.c | 87 +++++++++++++++++++++++----------------
app/core/gimpdrawable.h | 6 +--
app/core/gimpdrawablemodundo.c | 4 +-
app/core/gimpgrouplayer.c | 9 ++--
app/core/gimpgrouplayerundo.c | 3 +-
app/core/gimplayer.c | 17 ++++----
app/text/gimptextlayer.c | 17 ++++----
9 files changed, 89 insertions(+), 82 deletions(-)
---
diff --git a/app/core/gimpchannel.c b/app/core/gimpchannel.c
index 0b69ca0c2a..5ad39e5d36 100644
--- a/app/core/gimpchannel.c
+++ b/app/core/gimpchannel.c
@@ -165,8 +165,7 @@ static void gimp_channel_set_buffer (GimpDrawable *drawable,
gboolean push_undo,
const gchar *undo_desc,
GeglBuffer *buffer,
- gint offset_x,
- gint offset_y);
+ const GeglRectangle *bounds);
static gdouble gimp_channel_get_opacity_at (GimpPickable *pickable,
gint x,
@@ -604,8 +603,10 @@ gimp_channel_convert (GimpItem *item,
gimp_drawable_set_buffer_full (drawable, FALSE, NULL,
new_buffer,
- gimp_item_get_offset_x (item),
- gimp_item_get_offset_y (item),
+ GEGL_RECTANGLE (
+ gimp_item_get_offset_x (item),
+ gimp_item_get_offset_y (item),
+ 0, 0),
TRUE);
g_object_unref (new_buffer);
}
@@ -736,7 +737,8 @@ gimp_channel_scale (GimpItem *item,
gimp_drawable_set_buffer_full (drawable,
gimp_item_is_attached (item), NULL,
new_buffer,
- new_offset_x, new_offset_y,
+ GEGL_RECTANGLE (new_offset_x, new_offset_y,
+ 0, 0),
TRUE);
g_object_unref (new_buffer);
@@ -1002,12 +1004,11 @@ gimp_channel_get_active_components (GimpDrawable *drawable,
}
static void
-gimp_channel_set_buffer (GimpDrawable *drawable,
- gboolean push_undo,
- const gchar *undo_desc,
- GeglBuffer *buffer,
- gint offset_x,
- gint offset_y)
+gimp_channel_set_buffer (GimpDrawable *drawable,
+ gboolean push_undo,
+ const gchar *undo_desc,
+ GeglBuffer *buffer,
+ const GeglRectangle *bounds)
{
GimpChannel *channel = GIMP_CHANNEL (drawable);
GeglBuffer *old_buffer = gimp_drawable_get_buffer (drawable);
@@ -1021,8 +1022,7 @@ gimp_channel_set_buffer (GimpDrawable *drawable,
GIMP_DRAWABLE_CLASS (parent_class)->set_buffer (drawable,
push_undo, undo_desc,
- buffer,
- offset_x, offset_y);
+ buffer, bounds);
gegl_buffer_signal_connect (buffer, "changed",
G_CALLBACK (gimp_channel_buffer_changed),
diff --git a/app/core/gimpdrawable-transform.c b/app/core/gimpdrawable-transform.c
index b5c1743a2e..60958a3444 100644
--- a/app/core/gimpdrawable-transform.c
+++ b/app/core/gimpdrawable-transform.c
@@ -1120,7 +1120,7 @@ gimp_drawable_transform_paste (GimpDrawable *drawable,
{
gimp_drawable_set_buffer_full (drawable, TRUE, NULL,
buffer,
- offset_x, offset_y,
+ GEGL_RECTANGLE (offset_x, offset_y, 0, 0),
TRUE);
}
diff --git a/app/core/gimpdrawable.c b/app/core/gimpdrawable.c
index 8fc9c0a200..834e8b2a18 100644
--- a/app/core/gimpdrawable.c
+++ b/app/core/gimpdrawable.c
@@ -186,8 +186,7 @@ static void gimp_drawable_real_set_buffer (GimpDrawable *drawable,
gboolean push_undo,
const gchar *undo_desc,
GeglBuffer *buffer,
- gint offset_x,
- gint offset_y);
+ const GeglRectangle *bounds);
static void gimp_drawable_real_push_undo (GimpDrawable *drawable,
const gchar *undo_desc,
@@ -537,7 +536,8 @@ gimp_drawable_scale (GimpItem *item,
gimp_drawable_set_buffer_full (drawable, gimp_item_is_attached (item), NULL,
new_buffer,
- new_offset_x, new_offset_y,
+ GEGL_RECTANGLE (new_offset_x, new_offset_y,
+ 0, 0),
TRUE);
g_object_unref (new_buffer);
}
@@ -616,7 +616,8 @@ gimp_drawable_resize (GimpItem *item,
gimp_drawable_set_buffer_full (drawable, gimp_item_is_attached (item), NULL,
new_buffer,
- new_offset_x, new_offset_y,
+ GEGL_RECTANGLE (new_offset_x, new_offset_y,
+ 0, 0),
TRUE);
g_object_unref (new_buffer);
}
@@ -860,12 +861,11 @@ gimp_drawable_real_get_buffer (GimpDrawable *drawable)
}
static void
-gimp_drawable_real_set_buffer (GimpDrawable *drawable,
- gboolean push_undo,
- const gchar *undo_desc,
- GeglBuffer *buffer,
- gint offset_x,
- gint offset_y)
+gimp_drawable_real_set_buffer (GimpDrawable *drawable,
+ gboolean push_undo,
+ const gchar *undo_desc,
+ GeglBuffer *buffer,
+ const GeglRectangle *bounds)
{
GimpItem *item = GIMP_ITEM (drawable);
const Babl *old_format = NULL;
@@ -893,10 +893,12 @@ gimp_drawable_real_set_buffer (GimpDrawable *drawable,
"buffer", gimp_drawable_get_buffer (drawable),
NULL);
- gimp_item_set_offset (item, offset_x, offset_y);
+ gimp_item_set_offset (item, bounds->x, bounds->y);
gimp_item_set_size (item,
- gegl_buffer_get_width (buffer),
- gegl_buffer_get_height (buffer));
+ bounds->width ? bounds->width :
+ gegl_buffer_get_width (buffer),
+ bounds->height ? bounds->height :
+ gegl_buffer_get_height (buffer));
if (gimp_drawable_get_format (drawable) != old_format)
gimp_drawable_format_changed (drawable);
@@ -1308,30 +1310,26 @@ gimp_drawable_set_buffer (GimpDrawable *drawable,
const gchar *undo_desc,
GeglBuffer *buffer)
{
- gint offset_x, offset_y;
-
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
g_return_if_fail (GEGL_IS_BUFFER (buffer));
if (! gimp_item_is_attached (GIMP_ITEM (drawable)))
push_undo = FALSE;
- gimp_item_get_offset (GIMP_ITEM (drawable), &offset_x, &offset_y);
-
- gimp_drawable_set_buffer_full (drawable, push_undo, undo_desc, buffer,
- offset_x, offset_y, TRUE);
+ gimp_drawable_set_buffer_full (drawable, push_undo, undo_desc, buffer, NULL,
+ TRUE);
}
void
-gimp_drawable_set_buffer_full (GimpDrawable *drawable,
- gboolean push_undo,
- const gchar *undo_desc,
- GeglBuffer *buffer,
- gint offset_x,
- gint offset_y,
- gboolean update)
+gimp_drawable_set_buffer_full (GimpDrawable *drawable,
+ gboolean push_undo,
+ const gchar *undo_desc,
+ GeglBuffer *buffer,
+ const GeglRectangle *bounds,
+ gboolean update)
{
- GimpItem *item;
+ GimpItem *item;
+ GeglRectangle curr_bounds;
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
g_return_if_fail (GEGL_IS_BUFFER (buffer));
@@ -1341,21 +1339,40 @@ gimp_drawable_set_buffer_full (GimpDrawable *drawable,
if (! gimp_item_is_attached (GIMP_ITEM (drawable)))
push_undo = FALSE;
- if (update &&
- (gimp_item_get_width (item) != gegl_buffer_get_width (buffer) ||
- gimp_item_get_height (item) != gegl_buffer_get_height (buffer) ||
- gimp_item_get_offset_x (item) != offset_x ||
- gimp_item_get_offset_y (item) != offset_y))
+ if (! bounds)
+ {
+ gimp_item_get_offset (GIMP_ITEM (drawable),
+ &curr_bounds.x, &curr_bounds.y);
+
+ curr_bounds.width = 0;
+ curr_bounds.height = 0;
+
+ bounds = &curr_bounds;
+ }
+
+ if (update && gimp_drawable_get_buffer (drawable))
{
- gimp_drawable_update (drawable, 0, 0, -1, -1);
+ GeglBuffer *old_buffer = gimp_drawable_get_buffer (drawable);
+ GeglRectangle old_extent;
+ GeglRectangle new_extent;
+
+ old_extent = *gegl_buffer_get_extent (old_buffer);
+ old_extent.x += gimp_item_get_offset_x (item);
+ old_extent.y += gimp_item_get_offset_x (item);
+
+ new_extent = *gegl_buffer_get_extent (buffer);
+ new_extent.x += bounds->x;
+ new_extent.y += bounds->y;
+
+ if (! gegl_rectangle_equal (&old_extent, &new_extent))
+ gimp_drawable_update (drawable, 0, 0, -1, -1);
}
g_object_freeze_notify (G_OBJECT (drawable));
GIMP_DRAWABLE_GET_CLASS (drawable)->set_buffer (drawable,
push_undo, undo_desc,
- buffer,
- offset_x, offset_y);
+ buffer, bounds);
g_object_thaw_notify (G_OBJECT (drawable));
diff --git a/app/core/gimpdrawable.h b/app/core/gimpdrawable.h
index fe4c286e23..4921a870f1 100644
--- a/app/core/gimpdrawable.h
+++ b/app/core/gimpdrawable.h
@@ -90,8 +90,7 @@ struct _GimpDrawableClass
gboolean push_undo,
const gchar *undo_desc,
GeglBuffer *buffer,
- gint offset_x,
- gint offset_y);
+ const GeglRectangle *bounds);
void (* push_undo) (GimpDrawable *drawable,
const gchar *undo_desc,
GeglBuffer *buffer,
@@ -170,8 +169,7 @@ void gimp_drawable_set_buffer_full (GimpDrawable *drawable,
gboolean push_undo,
const gchar *undo_desc,
GeglBuffer *buffer,
- gint offset_x,
- gint offset_y,
+ const GeglRectangle *bounds,
gboolean update);
void gimp_drawable_steal_buffer (GimpDrawable *drawable,
diff --git a/app/core/gimpdrawablemodundo.c b/app/core/gimpdrawablemodundo.c
index 3c005abf3a..fe5bd37504 100644
--- a/app/core/gimpdrawablemodundo.c
+++ b/app/core/gimpdrawablemodundo.c
@@ -200,7 +200,9 @@ gimp_drawable_mod_undo_pop (GimpUndo *undo,
&drawable_mod_undo->offset_y);
gimp_drawable_set_buffer_full (drawable, FALSE, NULL,
- buffer, offset_x, offset_y, TRUE);
+ buffer,
+ GEGL_RECTANGLE (offset_x, offset_y, 0, 0),
+ TRUE);
g_object_unref (buffer);
}
diff --git a/app/core/gimpgrouplayer.c b/app/core/gimpgrouplayer.c
index b65f7ff40f..249b661b1c 100644
--- a/app/core/gimpgrouplayer.c
+++ b/app/core/gimpgrouplayer.c
@@ -1072,9 +1072,7 @@ gimp_group_layer_convert_type (GimpLayer *layer,
gimp_drawable_set_buffer_full (GIMP_DRAWABLE (group),
FALSE, NULL,
- buffer,
- gimp_item_get_offset_x (GIMP_ITEM (group)),
- gimp_item_get_offset_y (GIMP_ITEM (group)),
+ buffer, NULL,
TRUE);
/* reset, the actual format is right now */
@@ -1997,8 +1995,7 @@ gimp_group_layer_update_size (GimpGroupLayer *group)
gimp_drawable_set_buffer_full (GIMP_DRAWABLE (group),
FALSE, NULL,
- buffer,
- x, y,
+ buffer, NULL,
FALSE /* don't update the drawable, the
* flush() below will take care of
* that.
@@ -2104,7 +2101,7 @@ gimp_group_layer_update_mask_size (GimpGroupLayer *group)
gimp_drawable_set_buffer_full (GIMP_DRAWABLE (mask),
FALSE, NULL,
- buffer, bounds.x, bounds.y,
+ buffer, &bounds,
TRUE);
g_object_unref (buffer);
diff --git a/app/core/gimpgrouplayerundo.c b/app/core/gimpgrouplayerundo.c
index 63a390d4fe..579b1b04ea 100644
--- a/app/core/gimpgrouplayerundo.c
+++ b/app/core/gimpgrouplayerundo.c
@@ -158,8 +158,7 @@ gimp_group_layer_undo_pop (GimpUndo *undo,
gimp_drawable_set_buffer_full (GIMP_DRAWABLE (mask),
FALSE, NULL,
group_layer_undo->mask_buffer,
- group_layer_undo->mask_bounds.x,
- group_layer_undo->mask_bounds.y,
+ &group_layer_undo->mask_bounds,
TRUE);
}
}
diff --git a/app/core/gimplayer.c b/app/core/gimplayer.c
index d97468dae3..0fc36779c5 100644
--- a/app/core/gimplayer.c
+++ b/app/core/gimplayer.c
@@ -201,8 +201,7 @@ static void gimp_layer_set_buffer (GimpDrawable *drawable,
gboolean push_undo,
const gchar *undo_desc,
GeglBuffer *buffer,
- gint offset_x,
- gint offset_y);
+ const GeglRectangle *bounds);
static GimpColorProfile *
gimp_layer_get_color_profile (GimpColorManaged *managed);
@@ -1506,12 +1505,11 @@ gimp_layer_get_active_mask (GimpDrawable *drawable)
}
static void
-gimp_layer_set_buffer (GimpDrawable *drawable,
- gboolean push_undo,
- const gchar *undo_desc,
- GeglBuffer *buffer,
- gint offset_x,
- gint offset_y)
+gimp_layer_set_buffer (GimpDrawable *drawable,
+ gboolean push_undo,
+ const gchar *undo_desc,
+ GeglBuffer *buffer,
+ const GeglRectangle *bounds)
{
GeglBuffer *old_buffer = gimp_drawable_get_buffer (drawable);
gint old_trc = -1;
@@ -1521,8 +1519,7 @@ gimp_layer_set_buffer (GimpDrawable *drawable,
GIMP_DRAWABLE_CLASS (parent_class)->set_buffer (drawable,
push_undo, undo_desc,
- buffer,
- offset_x, offset_y);
+ buffer, bounds);
if (gimp_filter_peek_node (GIMP_FILTER (drawable)))
{
diff --git a/app/text/gimptextlayer.c b/app/text/gimptextlayer.c
index 14d17d0204..d473569273 100644
--- a/app/text/gimptextlayer.c
+++ b/app/text/gimptextlayer.c
@@ -95,8 +95,7 @@ static void gimp_text_layer_set_buffer (GimpDrawable *drawable,
gboolean push_undo,
const gchar *undo_desc,
GeglBuffer *buffer,
- gint offset_x,
- gint offset_y);
+ const GeglRectangle *bounds);
static void gimp_text_layer_push_undo (GimpDrawable *drawable,
const gchar *undo_desc,
GeglBuffer *buffer,
@@ -324,12 +323,11 @@ gimp_text_layer_rename (GimpItem *item,
}
static void
-gimp_text_layer_set_buffer (GimpDrawable *drawable,
- gboolean push_undo,
- const gchar *undo_desc,
- GeglBuffer *buffer,
- gint offset_x,
- gint offset_y)
+gimp_text_layer_set_buffer (GimpDrawable *drawable,
+ gboolean push_undo,
+ const gchar *undo_desc,
+ GeglBuffer *buffer,
+ const GeglRectangle *bounds)
{
GimpTextLayer *layer = GIMP_TEXT_LAYER (drawable);
GimpImage *image = gimp_item_get_image (GIMP_ITEM (layer));
@@ -340,8 +338,7 @@ gimp_text_layer_set_buffer (GimpDrawable *drawable,
GIMP_DRAWABLE_CLASS (parent_class)->set_buffer (drawable,
push_undo, undo_desc,
- buffer,
- offset_x, offset_y);
+ buffer, bounds);
if (push_undo && ! layer->modified)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]