Commit 3afdd7c5 authored by Ell's avatar Ell

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.
parent 0601b7f9
......@@ -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),
......
......@@ -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);
}
......
......@@ -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));
......
......@@ -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,
......
......@@ -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);
}
......
......@@ -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);
......
......@@ -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);
}
}
......
......@@ -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)))
{
......
......@@ -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)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment