added gimp_item_translate() and virtual function GimpItem::translate().

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

	* app/core/gimpitem.[ch]: added gimp_item_translate() and
	virtual function GimpItem::translate().

	* app/core/gimplayer.[ch]: removed public function
	gimp_layer_translate() and implement GimpItem::translate()
	instead.

	* app/core/core-enums.[ch]
	* app/core/gimpimage-undo-push.[ch]: changed layer_displace undo
	types and functions to be item_displace ones.

	* app/core/gimpimage-crop.c
	* app/core/gimpimage-resize.c
	* app/display/gimpdisplayshell-dnd.c
	* app/gui/layers-commands.c
	* app/tools/gimpeditselectiontool.c
	* app/widgets/gimptoolbox.c
	* tools/pdbgen/pdb/layer.pdb: changed accordingly.

	* app/pdb/layer_cmds.c: regenerated.
This commit is contained in:
Michael Natterer 2003-05-08 19:11:17 +00:00 committed by Michael Natterer
parent ab0ac8472f
commit 129c78d271
17 changed files with 203 additions and 150 deletions

View File

@ -1,3 +1,26 @@
2003-05-08 Michael Natterer <mitch@gimp.org>
* app/core/gimpitem.[ch]: added gimp_item_translate() and
virtual function GimpItem::translate().
* app/core/gimplayer.[ch]: removed public function
gimp_layer_translate() and implement GimpItem::translate()
instead.
* app/core/core-enums.[ch]
* app/core/gimpimage-undo-push.[ch]: changed layer_displace undo
types and functions to be item_displace ones.
* app/core/gimpimage-crop.c
* app/core/gimpimage-resize.c
* app/display/gimpdisplayshell-dnd.c
* app/gui/layers-commands.c
* app/tools/gimpeditselectiontool.c
* app/widgets/gimptoolbox.c
* tools/pdbgen/pdb/layer.pdb: changed accordingly.
* app/pdb/layer_cmds.c: regenerated.
2003-05-08 Michael Natterer <mitch@gimp.org>
* app/core/gimplayer.[ch]: removed the remaining layer scale API.

View File

@ -557,7 +557,7 @@ layers_new_layer_query (GimpImage *gimage,
gimp_drawable_fill_by_type (GIMP_DRAWABLE (new_layer),
gimp_get_user_context (gimage->gimp),
GIMP_TRANSPARENT_FILL);
gimp_layer_translate (new_layer, off_x, off_y, FALSE);
gimp_item_translate (GIMP_ITEM (new_layer), off_x, off_y, FALSE);
}
gimp_image_add_layer (gimage, new_layer, -1);

View File

@ -437,10 +437,10 @@ static const GEnumValue gimp_undo_type_enum_values[] =
{ GIMP_UNDO_GROUP_IMAGE_GUIDE, N_("Guide"), "group-image-guide" },
{ GIMP_UNDO_GROUP_MASK, N_("Selection Mask"), "group-mask" },
{ GIMP_UNDO_GROUP_ITEM_PROPERTIES, N_("Item Properties"), "group-item-properties" },
{ GIMP_UNDO_GROUP_ITEM_DISPLACE, N_("Move Item"), "group-item-displace" },
{ GIMP_UNDO_GROUP_DRAWABLE_VISIBILITY, N_("Drawable Visibility"), "group-drawable-visibility" },
{ GIMP_UNDO_GROUP_LAYER_SCALE, N_("Scale Layer"), "group-layer-scale" },
{ GIMP_UNDO_GROUP_LAYER_RESIZE, N_("Resize Layer"), "group-layer-resize" },
{ GIMP_UNDO_GROUP_LAYER_DISPLACE, N_("Move Layer"), "group-layer-displace" },
{ GIMP_UNDO_GROUP_LAYER_LINKED, N_("Linked Layer"), "group-layer-linked" },
{ GIMP_UNDO_GROUP_LAYER_APPLY_MASK, N_("Apply Layer Mask"), "group-layer-apply-mask" },
{ GIMP_UNDO_GROUP_FS_TO_LAYER, N_("Floating Selection to Layer"), "group-fs-to-layer" },
@ -465,6 +465,7 @@ static const GEnumValue gimp_undo_type_enum_values[] =
{ GIMP_UNDO_IMAGE_COLORMAP, N_("Change Indexed Palette"), "image-colormap" },
{ GIMP_UNDO_MASK, N_("Selection Mask"), "mask" },
{ GIMP_UNDO_ITEM_RENAME, N_("Rename Item"), "item-rename" },
{ GIMP_UNDO_ITEM_DISPLACE, N_("Move Item"), "item-displace" },
{ GIMP_UNDO_DRAWABLE_VISIBILITY, N_("Drawable Visibility"), "drawable-visibility" },
{ GIMP_UNDO_LAYER_ADD, N_("New Layer"), "layer-add" },
{ GIMP_UNDO_LAYER_REMOVE, N_("Delete Layer"), "layer-remove" },
@ -472,7 +473,6 @@ static const GEnumValue gimp_undo_type_enum_values[] =
{ GIMP_UNDO_LAYER_MASK_ADD, N_("Add Layer Mask"), "layer-mask-add" },
{ GIMP_UNDO_LAYER_MASK_REMOVE, N_("Delete Layer Mask"), "layer-mask-remove" },
{ GIMP_UNDO_LAYER_REPOSITION, N_("Reposition Layer"), "layer-reposition" },
{ GIMP_UNDO_LAYER_DISPLACE, N_("Move Layer"), "layer-displace" },
{ GIMP_UNDO_LAYER_MODE, N_("Set Layer Mode"), "layer-mode" },
{ GIMP_UNDO_LAYER_OPACITY, N_("Set Layer Opacity"), "layer-opacity" },
{ GIMP_UNDO_LAYER_PRESERVE_TRANS, N_("Set Preserve Trans"), "layer-preserve-trans" },

View File

@ -324,10 +324,10 @@ typedef enum /*< pdb-skip >*/
GIMP_UNDO_GROUP_IMAGE_GUIDE, /*< desc="Guide" >*/
GIMP_UNDO_GROUP_MASK, /*< desc="Selection Mask" >*/
GIMP_UNDO_GROUP_ITEM_PROPERTIES, /*< desc="Item Properties" >*/
GIMP_UNDO_GROUP_ITEM_DISPLACE, /*< desc="Move Item" >*/
GIMP_UNDO_GROUP_DRAWABLE_VISIBILITY,/*< desc="Drawable Visibility" >*/
GIMP_UNDO_GROUP_LAYER_SCALE, /*< desc="Scale Layer" >*/
GIMP_UNDO_GROUP_LAYER_RESIZE, /*< desc="Resize Layer" >*/
GIMP_UNDO_GROUP_LAYER_DISPLACE, /*< desc="Move Layer" >*/
GIMP_UNDO_GROUP_LAYER_LINKED, /*< desc="Linked Layer" >*/
GIMP_UNDO_GROUP_LAYER_APPLY_MASK, /*< desc="Apply Layer Mask" >*/
GIMP_UNDO_GROUP_FS_TO_LAYER, /*< desc="Floating Selection to Layer" >*/
@ -357,6 +357,7 @@ typedef enum /*< pdb-skip >*/
GIMP_UNDO_IMAGE_COLORMAP, /*< desc="Change Indexed Palette" >*/
GIMP_UNDO_MASK, /*< desc="Selection Mask" >*/
GIMP_UNDO_ITEM_RENAME, /*< desc="Rename Item" >*/
GIMP_UNDO_ITEM_DISPLACE, /*< desc="Move Item" >*/
GIMP_UNDO_DRAWABLE_VISIBILITY, /*< desc="Drawable Visibility" >*/
GIMP_UNDO_LAYER_ADD, /*< desc="New Layer" >*/
GIMP_UNDO_LAYER_REMOVE, /*< desc="Delete Layer" >*/
@ -364,7 +365,6 @@ typedef enum /*< pdb-skip >*/
GIMP_UNDO_LAYER_MASK_ADD, /*< desc="Add Layer Mask" >*/
GIMP_UNDO_LAYER_MASK_REMOVE, /*< desc="Delete Layer Mask" >*/
GIMP_UNDO_LAYER_REPOSITION, /*< desc="Reposition Layer" >*/
GIMP_UNDO_LAYER_DISPLACE, /*< desc="Move Layer" >*/
GIMP_UNDO_LAYER_MODE, /*< desc="Set Layer Mode" >*/
GIMP_UNDO_LAYER_OPACITY, /*< desc="Set Layer Opacity" >*/
GIMP_UNDO_LAYER_PRESERVE_TRANS, /*< desc="Set Preserve Trans" >*/

View File

@ -182,7 +182,7 @@ gimp_image_crop (GimpImage *gimage,
next = g_list_next (list);
gimp_layer_translate (layer, -x1, -y1, TRUE);
gimp_item_translate (GIMP_ITEM (layer), -x1, -y1, TRUE);
gimp_item_offsets (GIMP_ITEM (layer), &off_x, &off_y);

View File

@ -126,7 +126,7 @@ gimp_image_resize (GimpImage *gimage,
{
GimpLayer *layer = list->data;
gimp_layer_translate (layer, offset_x, offset_y, TRUE);
gimp_item_translate (GIMP_ITEM (layer), offset_x, offset_y, TRUE);
}
/* Make sure the projection matches the gimage size */

View File

@ -1082,6 +1082,93 @@ undo_free_item_rename (GimpUndo *undo,
}
/****************************/
/* Item displacement Undo */
/****************************/
typedef struct _ItemDisplaceUndo ItemDisplaceUndo;
struct _ItemDisplaceUndo
{
gint old_offset_x;
gint old_offset_y;
};
static gboolean undo_pop_item_displace (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum);
static void undo_free_item_displace (GimpUndo *undo,
GimpUndoMode undo_mode);
gboolean
gimp_image_undo_push_item_displace (GimpImage *gimage,
const gchar *undo_desc,
GimpItem *item)
{
GimpUndo *new;
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE);
if ((new = gimp_image_undo_push_item (gimage, item,
sizeof (ItemDisplaceUndo),
sizeof (ItemDisplaceUndo),
GIMP_UNDO_ITEM_DISPLACE, undo_desc,
TRUE,
undo_pop_item_displace,
undo_free_item_displace)))
{
ItemDisplaceUndo *idu;
idu = new->data;
gimp_item_offsets (item, &idu->old_offset_x, &idu->old_offset_y);
return TRUE;
}
return FALSE;
}
static gboolean
undo_pop_item_displace (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum)
{
ItemDisplaceUndo *idu;
GimpItem *item;
gint offset_x;
gint offset_y;
idu = (ItemDisplaceUndo *) undo->data;
item = GIMP_ITEM_UNDO (undo)->item;
gimp_item_offsets (item, &offset_x, &offset_y);
gimp_item_translate (item,
idu->old_offset_x - offset_x,
idu->old_offset_y - offset_y,
FALSE);
idu->old_offset_x = offset_x;
idu->old_offset_y = offset_y;
return TRUE;
}
static void
undo_free_item_displace (GimpUndo *undo,
GimpUndoMode undo_mode)
{
ItemDisplaceUndo *idu;
idu = (ItemDisplaceUndo *) undo->data;
g_free (idu);
}
/******************************/
/* Drawable Visibility Undo */
/******************************/
@ -1696,94 +1783,6 @@ undo_free_layer_reposition (GimpUndo *undo,
}
/*****************************/
/* Layer displacement Undo */
/*****************************/
typedef struct _LayerDisplaceUndo LayerDisplaceUndo;
struct _LayerDisplaceUndo
{
gint old_offset_x;
gint old_offset_y;
};
static gboolean undo_pop_layer_displace (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum);
static void undo_free_layer_displace (GimpUndo *undo,
GimpUndoMode undo_mode);
gboolean
gimp_image_undo_push_layer_displace (GimpImage *gimage,
const gchar *undo_desc,
GimpLayer *layer)
{
GimpUndo *new;
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
g_return_val_if_fail (GIMP_IS_LAYER (layer), FALSE);
if ((new = gimp_image_undo_push_item (gimage, GIMP_ITEM (layer),
sizeof (LayerDisplaceUndo),
sizeof (LayerDisplaceUndo),
GIMP_UNDO_LAYER_DISPLACE, undo_desc,
TRUE,
undo_pop_layer_displace,
undo_free_layer_displace)))
{
LayerDisplaceUndo *ldu;
ldu = new->data;
ldu->old_offset_x = GIMP_ITEM (layer)->offset_x;
ldu->old_offset_y = GIMP_ITEM (layer)->offset_y;
return TRUE;
}
return FALSE;
}
static gboolean
undo_pop_layer_displace (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum)
{
LayerDisplaceUndo *ldu;
GimpItem *item;
gint offset_x;
gint offset_y;
ldu = (LayerDisplaceUndo *) undo->data;
item = GIMP_ITEM_UNDO (undo)->item;
gimp_item_offsets (item, &offset_x, &offset_y);
gimp_layer_translate (GIMP_LAYER (item),
ldu->old_offset_x - offset_x,
ldu->old_offset_y - offset_y,
FALSE);
ldu->old_offset_x = offset_x;
ldu->old_offset_y = offset_y;
return TRUE;
}
static void
undo_free_layer_displace (GimpUndo *undo,
GimpUndoMode undo_mode)
{
LayerDisplaceUndo *ldu;
ldu = (LayerDisplaceUndo *) undo->data;
g_free (ldu);
}
/***************************/
/* Layer properties Undo */
/***************************/

View File

@ -65,6 +65,9 @@ gboolean gimp_image_undo_push_mask (GimpImage *gimage,
gboolean gimp_image_undo_push_item_rename (GimpImage *gimage,
const gchar *undo_desc,
GimpItem *item);
gboolean gimp_image_undo_push_item_displace (GimpImage *gimage,
const gchar *undo_desc,
GimpItem *item);
/* drawable undos */
@ -100,9 +103,6 @@ gboolean gimp_image_undo_push_layer_mask_remove (GimpImage *gimage,
gboolean gimp_image_undo_push_layer_reposition (GimpImage *gimage,
const gchar *undo_desc,
GimpLayer *layer);
gboolean gimp_image_undo_push_layer_displace (GimpImage *gimage,
const gchar *undo_desc,
GimpLayer *layer);
gboolean gimp_image_undo_push_layer_mode (GimpImage *gimage,
const gchar *undo_desc,
GimpLayer *layer);

View File

@ -68,6 +68,9 @@ static GimpItem * gimp_item_real_duplicate (GimpItem *item,
static void gimp_item_real_rename (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc);
static void gimp_item_real_translate (GimpItem *item,
gint offset_x,
gint offset_y);
/* private variables */
@ -133,6 +136,7 @@ gimp_item_class_init (GimpItemClass *klass)
klass->removed = NULL;
klass->duplicate = gimp_item_real_duplicate;
klass->rename = gimp_item_real_rename;
klass->translate = gimp_item_real_translate;
klass->scale = NULL;
klass->resize = NULL;
}
@ -273,6 +277,15 @@ gimp_item_real_rename (GimpItem *item,
gimp_object_set_name (GIMP_OBJECT (item), new_name);
}
static void
gimp_item_real_translate (GimpItem *item,
gint offset_x,
gint offset_y)
{
item->offset_x += offset_x;
item->offset_y += offset_y;
}
void
gimp_item_removed (GimpItem *item)
{
@ -368,6 +381,26 @@ gimp_item_offsets (const GimpItem *item,
if (off_y) *off_y = item->offset_y;
}
void
gimp_item_translate (GimpItem *item,
gint off_x,
gint off_y,
gboolean push_undo)
{
GimpItemClass *item_class;
g_return_if_fail (GIMP_IS_ITEM (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);
}
/**
* gimp_item_check_scaling:
* @item: Item to check

View File

@ -62,6 +62,9 @@ struct _GimpItemClass
void (* rename) (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc);
void (* translate) (GimpItem *item,
gint offset_x,
gint offset_y);
void (* scale) (GimpItem *item,
gint new_width,
gint new_height,
@ -76,6 +79,7 @@ struct _GimpItemClass
const gchar *default_name;
const gchar *rename_desc;
const gchar *translate_desc;
const gchar *scale_desc;
};
@ -104,6 +108,11 @@ void gimp_item_offsets (const GimpItem *item,
gint *offset_x,
gint *offset_y);
void gimp_item_translate (GimpItem *item,
gint offset_x,
gint offset_y,
gboolean push_undo);
gboolean gimp_item_check_scaling (const GimpItem *layer,
gint new_width,
gint new_height);

View File

@ -75,6 +75,9 @@ static GimpItem * gimp_layer_duplicate (GimpItem *item,
static void gimp_layer_rename (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc);
static void gimp_layer_translate (GimpItem *item,
gint offset_x,
gint offset_y);
static void gimp_layer_scale (GimpItem *item,
gint new_width,
gint new_height,
@ -196,10 +199,12 @@ gimp_layer_class_init (GimpLayerClass *klass)
item_class->duplicate = gimp_layer_duplicate;
item_class->rename = gimp_layer_rename;
item_class->translate = gimp_layer_translate;
item_class->scale = gimp_layer_scale;
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;
@ -357,6 +362,36 @@ gimp_layer_rename (GimpItem *item,
gimp_image_undo_group_end (gimage);
}
static void
gimp_layer_translate (GimpItem *item,
gint off_x,
gint off_y)
{
GimpLayer *layer;
layer = GIMP_LAYER (item);
/* update the old region */
gimp_drawable_update (GIMP_DRAWABLE (layer), 0, 0, item->width, item->height);
/* invalidate the selection boundary because of a layer modification */
gimp_layer_invalidate_boundary (layer);
GIMP_ITEM_CLASS (parent_class)->translate (item, off_x, off_y);
/* update the new region */
gimp_drawable_update (GIMP_DRAWABLE (layer), 0, 0, item->width, item->height);
if (layer->mask)
{
GIMP_ITEM (layer->mask)->offset_x = item->offset_x;
GIMP_ITEM (layer->mask)->offset_y = item->offset_y;
/* invalidate the mask preview */
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (layer->mask));
}
}
static void
gimp_layer_scale (GimpItem *item,
gint new_width,
@ -1018,48 +1053,6 @@ gimp_layer_apply_mask (GimpLayer *layer,
g_signal_emit (layer, layer_signals[MASK_CHANGED], 0);
}
void
gimp_layer_translate (GimpLayer *layer,
gint off_x,
gint off_y,
gboolean push_undo)
{
g_return_if_fail (GIMP_IS_LAYER (layer));
if (push_undo)
gimp_image_undo_push_layer_displace (gimp_item_get_image (GIMP_ITEM (layer)),
_("Move Layer"),
layer);
/* update the affected region */
gimp_drawable_update (GIMP_DRAWABLE (layer),
0, 0,
GIMP_ITEM (layer)->width,
GIMP_ITEM (layer)->height);
/* invalidate the selection boundary because of a layer modification */
gimp_layer_invalidate_boundary (layer);
/* update the layer offsets */
GIMP_ITEM (layer)->offset_x += off_x;
GIMP_ITEM (layer)->offset_y += off_y;
/* update the affected region */
gimp_drawable_update (GIMP_DRAWABLE (layer),
0, 0,
GIMP_ITEM (layer)->width,
GIMP_ITEM (layer)->height);
if (layer->mask)
{
GIMP_ITEM (layer->mask)->offset_x += off_x;
GIMP_ITEM (layer->mask)->offset_y += off_y;
/* invalidate the mask preview */
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (layer->mask));
}
}
void
gimp_layer_add_alpha (GimpLayer *layer)
{

View File

@ -99,10 +99,6 @@ GimpLayerMask * gimp_layer_add_mask (GimpLayer *layer,
void gimp_layer_apply_mask (GimpLayer *layer,
GimpMaskApplyMode mode,
gboolean push_undo);
void gimp_layer_translate (GimpLayer *layer,
gint off_x,
gint off_y,
gboolean push_undo);
void gimp_layer_add_alpha (GimpLayer *layer);
void gimp_layer_resize_to_image (GimpLayer *layer);

View File

@ -67,7 +67,7 @@ gimp_display_shell_drop_drawable (GtkWidget *widget,
off_x = (gdisp->gimage->width - gimp_item_width (GIMP_ITEM (drawable))) / 2;
off_y = (gdisp->gimage->height - gimp_item_height (GIMP_ITEM (drawable))) / 2;
gimp_layer_translate (new_layer, off_x, off_y, FALSE);
gimp_item_translate (GIMP_ITEM (new_layer), off_x, off_y, FALSE);
gimp_image_add_layer (gdisp->gimage, new_layer, -1);

View File

@ -557,7 +557,7 @@ layers_new_layer_query (GimpImage *gimage,
gimp_drawable_fill_by_type (GIMP_DRAWABLE (new_layer),
gimp_get_user_context (gimage->gimp),
GIMP_TRANSPARENT_FILL);
gimp_layer_translate (new_layer, off_x, off_y, FALSE);
gimp_item_translate (GIMP_ITEM (new_layer), off_x, off_y, FALSE);
}
gimp_image_add_layer (gimage, new_layer, -1);

View File

@ -649,7 +649,7 @@ layer_translate_invoker (Gimp *gimp,
tmp_layer = (GimpLayer *) layer_list->data;
if ((tmp_layer == layer) || gimp_layer_get_linked (tmp_layer))
gimp_layer_translate (tmp_layer, offx, offy, TRUE);
gimp_item_translate (GIMP_ITEM (tmp_layer), offx, offy, TRUE);
}
if (floating_layer)
@ -781,7 +781,7 @@ layer_set_offsets_invoker (Gimp *gimp,
tmp_layer = (GimpLayer *) layer_list->data;
if ((tmp_layer == layer) || gimp_layer_get_linked (tmp_layer))
gimp_layer_translate (tmp_layer,
gimp_item_translate (GIMP_ITEM (tmp_layer),
(offx - GIMP_ITEM (layer)->offset_x),
(offy - GIMP_ITEM (layer)->offset_y), TRUE);
}

View File

@ -892,7 +892,7 @@ toolbox_drop_drawable (GtkWidget *widget,
gimp_object_get_name (GIMP_OBJECT (drawable)));
gimp_item_offsets (GIMP_ITEM (new_layer), &off_x, &off_y);
gimp_layer_translate (new_layer, -off_x, -off_y, FALSE);
gimp_item_translate (GIMP_ITEM (new_layer), -off_x, -off_y, FALSE);
gimp_image_add_layer (new_gimage, new_layer, 0);

View File

@ -409,7 +409,7 @@ HELP
tmp_layer = (GimpLayer *) layer_list->data;
if ((tmp_layer == layer) || gimp_layer_get_linked (tmp_layer))
gimp_layer_translate (tmp_layer, offx, offy, TRUE);
gimp_item_translate (GIMP_ITEM (tmp_layer), offx, offy, TRUE);
}
}
CODE