Commit 45736814 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

added "gboolean push_undo" to GimpItem::translate() and don't push and

2003-05-09  Michael Natterer  <mitch@gimp.org>

	* app/core/gimpitem.[ch]: added "gboolean push_undo" to
	GimpItem::translate() and don't push and undo in
	gimp_item_translate().

	* app/core/gimpchannel.[ch]: removed public function
	gimp_channel_translate() and implement GimpItem::translate().

	* app/core/gimpimage-mask.c
	* app/core/gimplayer.c: changed accordingly.

	* app/vectors/gimpvectors.c: actually translate the vectors
	in translate().

	* app/gui/channels-commands.c (channels_new_channel_query): removed
	useless call to gimp_channel_translate().

	* app/tools/gimpeditselectiontool.c
	* tools/pdbgen/pdb/layer.pdb: when translating a linked layer,
	also translate all linked channels and vectors. Cleanup.

	Note that the "linked" behaviour has changed: before this change,
	moving a layer moved all linked layers unconditionally. Now,
	linked layers/channels/vectors are moved *only* if the moved layer
	is also linked (the linked items behave as a group now and moving
	something not in the group does not affect the group).

	* app/pdb/layer_cmds.c: regenerated.
parent 3a8ef85b
2003-05-09 Michael Natterer <mitch@gimp.org>
* app/core/gimpitem.[ch]: added "gboolean push_undo" to
GimpItem::translate() and don't push and undo in
gimp_item_translate().
* app/core/gimpchannel.[ch]: removed public function
gimp_channel_translate() and implement GimpItem::translate().
* app/core/gimpimage-mask.c
* app/core/gimplayer.c: changed accordingly.
* app/vectors/gimpvectors.c: actually translate the vectors
in translate().
* app/gui/channels-commands.c (channels_new_channel_query): removed
useless call to gimp_channel_translate().
* app/tools/gimpeditselectiontool.c
* tools/pdbgen/pdb/layer.pdb: when translating a linked layer,
also translate all linked channels and vectors. Cleanup.
Note that the "linked" behaviour has changed: before this change,
moving a layer moved all linked layers unconditionally. Now,
linked layers/channels/vectors are moved *only* if the moved layer
is also linked (the linked items behave as a group now and moving
something not in the group does not affect the group).
* app/pdb/layer_cmds.c: regenerated.
2003-05-09 Michael Natterer <mitch@gimp.org>
* app/core/gimpimage-crop.c (gimp_image_crop)
......@@ -321,12 +321,10 @@ channels_new_channel_query (GimpImage *gimage,
{
GimpChannel *new_channel;
gint width, height;
gint off_x, off_y;
GimpRGB color;
if (template)
{
gimp_item_offsets (GIMP_ITEM (template), &off_x, &off_y);
width = gimp_item_width (GIMP_ITEM (template));
height = gimp_item_height (GIMP_ITEM (template));
color = template->color;
......@@ -335,8 +333,6 @@ channels_new_channel_query (GimpImage *gimage,
{
width = gimp_image_get_width (gimage);
height = gimp_image_get_height (gimage);
off_x = 0;
off_y = 0;
gimp_rgba_set (&color, 0.0, 0.0, 0.0, 0.5);
}
......@@ -349,12 +345,9 @@ channels_new_channel_query (GimpImage *gimage,
&color);
if (template)
{
gimp_drawable_fill_by_type (GIMP_DRAWABLE (new_channel),
gimp_get_user_context (gimage->gimp),
GIMP_TRANSPARENT_FILL);
gimp_channel_translate (new_channel, off_x, off_y, FALSE);
}
gimp_drawable_fill_by_type (GIMP_DRAWABLE (new_channel),
gimp_get_user_context (gimage->gimp),
GIMP_TRANSPARENT_FILL);
gimp_image_add_channel (gimage, new_channel, -1);
......
......@@ -58,6 +58,10 @@ static gsize gimp_channel_get_memsize (GimpObject *object);
static GimpItem * gimp_channel_duplicate (GimpItem *item,
GType new_type,
gboolean add_alpha);
static void gimp_channel_translate (GimpItem *item,
gint off_x,
gint off_y,
gboolean push_undo);
static void gimp_channel_scale (GimpItem *item,
gint new_width,
gint new_height,
......@@ -129,6 +133,7 @@ gimp_channel_class_init (GimpChannelClass *klass)
viewable_class->default_stock_id = "gimp-channel";
item_class->duplicate = gimp_channel_duplicate;
item_class->translate = gimp_channel_translate;
item_class->scale = gimp_channel_scale;
item_class->resize = gimp_channel_resize;
item_class->default_name = _("Channel");
......@@ -231,6 +236,104 @@ gimp_channel_duplicate (GimpItem *item,
return new_item;
}
static void
gimp_channel_translate (GimpItem *item,
gint off_x,
gint off_y,
gboolean push_undo)
{
GimpChannel *mask;
GimpChannel *tmp_mask = NULL;
gint width, height;
PixelRegion srcPR, destPR;
guchar empty = TRANSPARENT_OPACITY;
gint x1, y1, x2, y2;
mask = GIMP_CHANNEL (item);
gimp_channel_bounds (mask, &x1, &y1, &x2, &y2);
x1 = CLAMP ((x1 + off_x), 0, GIMP_ITEM (mask)->width);
y1 = CLAMP ((y1 + off_y), 0, GIMP_ITEM (mask)->height);
x2 = CLAMP ((x2 + off_x), 0, GIMP_ITEM (mask)->width);
y2 = CLAMP ((y2 + off_y), 0, GIMP_ITEM (mask)->height);
width = x2 - x1;
height = y2 - y1;
if (push_undo)
{
gimp_channel_push_undo (mask, _("Move Channel"));
/* update the old area */
gimp_drawable_update (GIMP_DRAWABLE (item),
x1, y1,
x2 - x1, y2 - y1);
}
/* make sure width and height are non-zero */
if (width != 0 && height != 0)
{
/* copy the portion of the mask we will keep to a
* temporary buffer
*/
tmp_mask = gimp_channel_new_mask (gimp_item_get_image (GIMP_ITEM (mask)),
width, height);
pixel_region_init (&srcPR, GIMP_DRAWABLE (mask)->tiles,
x1 - off_x, y1 - off_y, width, height, FALSE);
pixel_region_init (&destPR, GIMP_DRAWABLE (tmp_mask)->tiles,
0, 0, width, height, TRUE);
copy_region (&srcPR, &destPR);
}
/* clear the mask */
pixel_region_init (&srcPR, GIMP_DRAWABLE (mask)->tiles,
0, 0,
GIMP_ITEM (mask)->width,
GIMP_ITEM (mask)->height, TRUE);
color_region (&srcPR, &empty);
if (width != 0 && height != 0)
{
/* copy the temp mask back to the mask */
pixel_region_init (&srcPR, GIMP_DRAWABLE (tmp_mask)->tiles,
0, 0, width, height, FALSE);
pixel_region_init (&destPR, GIMP_DRAWABLE (mask)->tiles,
x1, y1, width, height, TRUE);
copy_region (&srcPR, &destPR);
/* free the temporary mask */
g_object_unref (tmp_mask);
}
/* calculate new bounds */
if (width == 0 || height == 0)
{
mask->empty = TRUE;
mask->x1 = 0;
mask->y1 = 0;
mask->x2 = GIMP_ITEM (mask)->width;
mask->y2 = GIMP_ITEM (mask)->height;
}
else
{
mask->x1 = x1;
mask->y1 = y1;
mask->x2 = x2;
mask->y2 = y2;
}
if (push_undo)
{
/* update the new area */
gimp_drawable_update (GIMP_DRAWABLE (item),
mask->x1, mask->y1,
mask->x2 - mask->x1, mask->y2 - mask->y1);
gimp_viewable_size_changed (GIMP_VIEWABLE (item));
}
}
static void
gimp_channel_scale (GimpItem *item,
gint new_width,
......@@ -1560,86 +1663,6 @@ gimp_channel_shrink (GimpChannel *mask,
mask->bounds_known = FALSE;
}
void
gimp_channel_translate (GimpChannel *mask,
gint off_x,
gint off_y,
gboolean push_undo)
{
GimpChannel *tmp_mask = NULL;
gint width, height;
PixelRegion srcPR, destPR;
guchar empty = TRANSPARENT_OPACITY;
gint x1, y1, x2, y2;
g_return_if_fail (GIMP_IS_CHANNEL (mask));
if (push_undo)
gimp_channel_push_undo (mask, _("Translate Channel"));
gimp_channel_bounds (mask, &x1, &y1, &x2, &y2);
x1 = CLAMP ((x1 + off_x), 0, GIMP_ITEM (mask)->width);
y1 = CLAMP ((y1 + off_y), 0, GIMP_ITEM (mask)->height);
x2 = CLAMP ((x2 + off_x), 0, GIMP_ITEM (mask)->width);
y2 = CLAMP ((y2 + off_y), 0, GIMP_ITEM (mask)->height);
width = x2 - x1;
height = y2 - y1;
/* make sure width and height are non-zero */
if (width != 0 && height != 0)
{
/* copy the portion of the mask we will keep to a
* temporary buffer
*/
tmp_mask = gimp_channel_new_mask (gimp_item_get_image (GIMP_ITEM (mask)),
width, height);
pixel_region_init (&srcPR, GIMP_DRAWABLE (mask)->tiles,
x1 - off_x, y1 - off_y, width, height, FALSE);
pixel_region_init (&destPR, GIMP_DRAWABLE (tmp_mask)->tiles,
0, 0, width, height, TRUE);
copy_region (&srcPR, &destPR);
}
/* clear the mask */
pixel_region_init (&srcPR, GIMP_DRAWABLE (mask)->tiles,
0, 0,
GIMP_ITEM (mask)->width,
GIMP_ITEM (mask)->height, TRUE);
color_region (&srcPR, &empty);
if (width != 0 && height != 0)
{
/* copy the temp mask back to the mask */
pixel_region_init (&srcPR, GIMP_DRAWABLE (tmp_mask)->tiles,
0, 0, width, height, FALSE);
pixel_region_init (&destPR, GIMP_DRAWABLE (mask)->tiles,
x1, y1, width, height, TRUE);
copy_region (&srcPR, &destPR);
/* free the temporary mask */
g_object_unref (tmp_mask);
}
/* calculate new bounds */
if (width == 0 || height == 0)
{
mask->empty = TRUE;
mask->x1 = 0;
mask->y1 = 0;
mask->x2 = GIMP_ITEM (mask)->width;
mask->y2 = GIMP_ITEM (mask)->height;
}
else
{
mask->x1 = x1;
mask->y1 = y1;
mask->x2 = x2;
mask->y2 = y2;
}
}
void
gimp_channel_load (GimpChannel *mask,
GimpChannel *channel,
......
......@@ -175,11 +175,6 @@ void gimp_channel_shrink (GimpChannel *mask,
gboolean edge_lock,
gboolean push_undo);
void gimp_channel_translate (GimpChannel *mask,
gint off_x,
gint off_y,
gboolean push_undo);
void gimp_channel_load (GimpChannel *mask,
GimpChannel *channel,
gboolean push_undo);
......
......@@ -58,6 +58,10 @@ static gsize gimp_channel_get_memsize (GimpObject *object);
static GimpItem * gimp_channel_duplicate (GimpItem *item,
GType new_type,
gboolean add_alpha);
static void gimp_channel_translate (GimpItem *item,
gint off_x,
gint off_y,
gboolean push_undo);
static void gimp_channel_scale (GimpItem *item,
gint new_width,
gint new_height,
......@@ -129,6 +133,7 @@ gimp_channel_class_init (GimpChannelClass *klass)
viewable_class->default_stock_id = "gimp-channel";
item_class->duplicate = gimp_channel_duplicate;
item_class->translate = gimp_channel_translate;
item_class->scale = gimp_channel_scale;
item_class->resize = gimp_channel_resize;
item_class->default_name = _("Channel");
......@@ -231,6 +236,104 @@ gimp_channel_duplicate (GimpItem *item,
return new_item;
}
static void
gimp_channel_translate (GimpItem *item,
gint off_x,
gint off_y,
gboolean push_undo)
{
GimpChannel *mask;
GimpChannel *tmp_mask = NULL;
gint width, height;
PixelRegion srcPR, destPR;
guchar empty = TRANSPARENT_OPACITY;
gint x1, y1, x2, y2;
mask = GIMP_CHANNEL (item);
gimp_channel_bounds (mask, &x1, &y1, &x2, &y2);
x1 = CLAMP ((x1 + off_x), 0, GIMP_ITEM (mask)->width);
y1 = CLAMP ((y1 + off_y), 0, GIMP_ITEM (mask)->height);
x2 = CLAMP ((x2 + off_x), 0, GIMP_ITEM (mask)->width);
y2 = CLAMP ((y2 + off_y), 0, GIMP_ITEM (mask)->height);
width = x2 - x1;
height = y2 - y1;
if (push_undo)
{
gimp_channel_push_undo (mask, _("Move Channel"));
/* update the old area */
gimp_drawable_update (GIMP_DRAWABLE (item),
x1, y1,
x2 - x1, y2 - y1);
}
/* make sure width and height are non-zero */
if (width != 0 && height != 0)
{
/* copy the portion of the mask we will keep to a
* temporary buffer
*/
tmp_mask = gimp_channel_new_mask (gimp_item_get_image (GIMP_ITEM (mask)),
width, height);
pixel_region_init (&srcPR, GIMP_DRAWABLE (mask)->tiles,
x1 - off_x, y1 - off_y, width, height, FALSE);
pixel_region_init (&destPR, GIMP_DRAWABLE (tmp_mask)->tiles,
0, 0, width, height, TRUE);
copy_region (&srcPR, &destPR);
}
/* clear the mask */
pixel_region_init (&srcPR, GIMP_DRAWABLE (mask)->tiles,
0, 0,
GIMP_ITEM (mask)->width,
GIMP_ITEM (mask)->height, TRUE);
color_region (&srcPR, &empty);
if (width != 0 && height != 0)
{
/* copy the temp mask back to the mask */
pixel_region_init (&srcPR, GIMP_DRAWABLE (tmp_mask)->tiles,
0, 0, width, height, FALSE);
pixel_region_init (&destPR, GIMP_DRAWABLE (mask)->tiles,
x1, y1, width, height, TRUE);
copy_region (&srcPR, &destPR);
/* free the temporary mask */
g_object_unref (tmp_mask);
}
/* calculate new bounds */
if (width == 0 || height == 0)
{
mask->empty = TRUE;
mask->x1 = 0;
mask->y1 = 0;
mask->x2 = GIMP_ITEM (mask)->width;
mask->y2 = GIMP_ITEM (mask)->height;
}
else
{
mask->x1 = x1;
mask->y1 = y1;
mask->x2 = x2;
mask->y2 = y2;
}
if (push_undo)
{
/* update the new area */
gimp_drawable_update (GIMP_DRAWABLE (item),
mask->x1, mask->y1,
mask->x2 - mask->x1, mask->y2 - mask->y1);
gimp_viewable_size_changed (GIMP_VIEWABLE (item));
}
}
static void
gimp_channel_scale (GimpItem *item,
gint new_width,
......@@ -1560,86 +1663,6 @@ gimp_channel_shrink (GimpChannel *mask,
mask->bounds_known = FALSE;
}
void
gimp_channel_translate (GimpChannel *mask,
gint off_x,
gint off_y,
gboolean push_undo)
{
GimpChannel *tmp_mask = NULL;
gint width, height;
PixelRegion srcPR, destPR;
guchar empty = TRANSPARENT_OPACITY;
gint x1, y1, x2, y2;
g_return_if_fail (GIMP_IS_CHANNEL (mask));
if (push_undo)
gimp_channel_push_undo (mask, _("Translate Channel"));
gimp_channel_bounds (mask, &x1, &y1, &x2, &y2);
x1 = CLAMP ((x1 + off_x), 0, GIMP_ITEM (mask)->width);
y1 = CLAMP ((y1 + off_y), 0, GIMP_ITEM (mask)->height);
x2 = CLAMP ((x2 + off_x), 0, GIMP_ITEM (mask)->width);
y2 = CLAMP ((y2 + off_y), 0, GIMP_ITEM (mask)->height);
width = x2 - x1;
height = y2 - y1;
/* make sure width and height are non-zero */
if (width != 0 && height != 0)
{
/* copy the portion of the mask we will keep to a
* temporary buffer
*/
tmp_mask = gimp_channel_new_mask (gimp_item_get_image (GIMP_ITEM (mask)),
width, height);
pixel_region_init (&srcPR, GIMP_DRAWABLE (mask)->tiles,
x1 - off_x, y1 - off_y, width, height, FALSE);
pixel_region_init (&destPR, GIMP_DRAWABLE (tmp_mask)->tiles,
0, 0, width, height, TRUE);
copy_region (&srcPR, &destPR);
}
/* clear the mask */
pixel_region_init (&srcPR, GIMP_DRAWABLE (mask)->tiles,
0, 0,
GIMP_ITEM (mask)->width,
GIMP_ITEM (mask)->height, TRUE);
color_region (&srcPR, &empty);
if (width != 0 && height != 0)
{
/* copy the temp mask back to the mask */
pixel_region_init (&srcPR, GIMP_DRAWABLE (tmp_mask)->tiles,
0, 0, width, height, FALSE);
pixel_region_init (&destPR, GIMP_DRAWABLE (mask)->tiles,
x1, y1, width, height, TRUE);
copy_region (&srcPR, &destPR);
/* free the temporary mask */
g_object_unref (tmp_mask);
}
/* calculate new bounds */
if (width == 0 || height == 0)
{
mask->empty = TRUE;
mask->x1 = 0;
mask->y1 = 0;
mask->x2 = GIMP_ITEM (mask)->width;
mask->y2 = GIMP_ITEM (mask)->height;
}
else
{
mask->x1 = x1;
mask->y1 = y1;
mask->x2 = x2;
mask->y2 = y2;
}
}
void
gimp_channel_load (GimpChannel *mask,
GimpChannel *channel,
......
......@@ -175,11 +175,6 @@ void gimp_channel_shrink (GimpChannel *mask,
gboolean edge_lock,
gboolean push_undo);
void gimp_channel_translate (GimpChannel *mask,
gint off_x,
gint off_y,
gboolean push_undo);
void gimp_channel_load (GimpChannel *mask,
GimpChannel *channel,
gboolean push_undo);
......
......@@ -575,11 +575,12 @@ gimp_image_mask_translate (GimpImage *gimage,
g_return_if_fail (GIMP_IS_IMAGE (gimage));
if (push_undo)
gimp_image_mask_push_undo (gimage, _("Translate Selection"));
gimp_image_mask_push_undo (gimage, _("Move Selection"));
else
gimp_image_mask_invalidate (gimage);
gimp_channel_translate (gimp_image_get_mask (gimage), off_x, off_y, FALSE);
gimp_item_translate (GIMP_ITEM (gimp_image_get_mask (gimage)),
off_x, off_y, FALSE);
gimp_image_mask_changed (gimage);
}
......
......@@ -71,7 +71,8 @@ static void gimp_item_real_rename (GimpItem *item,
const gchar *undo_desc);
static void gimp_item_real_translate (GimpItem *item,
gint offset_x,
gint offset_y);
gint offset_y,
gboolean push_undo);
static void gimp_item_real_scale (GimpItem *item,
gint new_width,
gint new_height,
......@@ -305,7 +306,8 @@ gimp_item_real_rename (GimpItem *item,
static void
gimp_item_real_translate (GimpItem *item,
gint offset_x,
gint offset_y)
gint offset_y,
gboolean push_undo)
{
item->offset_x += offset_x;
item->offset_y += offset_y;
......@@ -474,12 +476,7 @@ gimp_item_translate (GimpItem *item,
item_class = GIMP_ITEM_GET_CLASS (item);
if (push_undo)
gimp_image_undo_push_item_displace (gimp_item_get_image (item),
item_class->translate_desc,
item);
item_class->translate (item, off_x, off_y);
item_class->translate (item, off_x, off_y, push_undo);
}
/**
......
......@@ -67,7 +67,8 @@ struct _GimpItemClass
const gchar *undo_desc);
void (* translate) (GimpItem *item,
gint offset_x,
gint offset_y);
gint offset_y,
gboolean push_undo);
void (* scale) (GimpItem *item,
gint new_width,
gint new_height,
......@@ -82,8 +83,6 @@ struct _GimpItemClass
const gchar *default_name;
const gchar *rename_desc;
const gchar *translate_desc;
const gchar *scale_desc;
};
......
......@@ -76,7 +76,8 @@ static void gimp_layer_rename (GimpItem *item,
const gchar *undo_desc);
static void gimp_layer_translate (GimpItem *item,
gint offset_x,
gint offset_y);
gint offset_y,
gboolean push_undo);
static void gimp_layer_scale (GimpItem *item,
gint new_width,
gint new_height,
......@@ -194,7 +195,6 @@ gimp_layer_class_init (GimpLayerClass *klass)
item_class->resize = gimp_layer_resize;
item_class->default_name = _("Layer");
item_class->rename_desc = _("Rename Layer");
item_class->translate_desc = _("Move Layer");
klass->opacity_changed = NULL;
klass->mode_changed = NULL;
......@@ -350,20 +350,27 @@ gimp_layer_rename (GimpItem *item,
static void
gimp_layer_translate (GimpItem *item,
gint off_x,
gint off_y)
gint offset_x,
gint offset_y,
gboolean