Commit 1329e016 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

app/core/gimpimage-mask.[ch] (gimp_image_mask_translate) added "gboolean

2003-03-18  Michael Natterer  <mitch@gimp.org>

	* app/core/gimpimage-mask.[ch] (gimp_image_mask_translate)
	* app/core/gimplayer.[ch] (gimp_layer_translate): added
	"gboolean push_undo" parameters.

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

	* app/pdb/layer_cmds.c
	* app/pdb/selection_cmds.c: regenerated.

	* app/core/gimpimage-undo-push.c (undo_pop_layer_displace): call
	gimp_layer_translate() with "push_undo == FALSE" instead of
	duplicating gimp_layer_translate()'s code. Use GimpItemUndo for
	GIMP_UNDO_MASK.

	* app/tools/gimpeditselectiontool.c
	(gimp_edit_selection_tool_cursor_key): check if the top undo on
	the stack is of exactly the same type as the undo we would push
	and just don't push it then (compresses layer translate undos and
	fixes bug #86362). Changed stuff work with CAPS_LOCK or other
	modifiers pressed.
parent 269f5c21
2003-03-18 Michael Natterer <mitch@gimp.org>
* app/core/gimpimage-mask.[ch] (gimp_image_mask_translate)
* app/core/gimplayer.[ch] (gimp_layer_translate): added
"gboolean push_undo" parameters.
* app/core/gimpimage-crop.c
* app/core/gimpimage-resize.c
* app/display/gimpdisplayshell-dnd.c
* app/gui/layers-commands.c
* app/widgets/gimptoolbox.c
* tools/pdbgen/pdb/layer.pdb
* tools/pdbgen/pdb/selection.pdb: changed accordingly.
* app/pdb/layer_cmds.c
* app/pdb/selection_cmds.c: regenerated.
* app/core/gimpimage-undo-push.c (undo_pop_layer_displace): call
gimp_layer_translate() with "push_undo == FALSE" instead of
duplicating gimp_layer_translate()'s code. Use GimpItemUndo for
GIMP_UNDO_MASK.
* app/tools/gimpeditselectiontool.c
(gimp_edit_selection_tool_cursor_key): check if the top undo on
the stack is of exactly the same type as the undo we would push
and just don't push it then (compresses layer translate undos and
fixes bug #86362). Changed stuff work with CAPS_LOCK or other
modifiers pressed.
2003-03-18 Michael Natterer <mitch@gimp.org> 2003-03-18 Michael Natterer <mitch@gimp.org>
Added an API for image colormap manupulation and made colormap Added an API for image colormap manupulation and made colormap
...@@ -572,7 +572,7 @@ layers_new_layer_query (GimpImage *gimage, ...@@ -572,7 +572,7 @@ layers_new_layer_query (GimpImage *gimage,
gimp_drawable_fill_by_type (GIMP_DRAWABLE (new_layer), gimp_drawable_fill_by_type (GIMP_DRAWABLE (new_layer),
gimp_get_user_context (gimage->gimp), gimp_get_user_context (gimage->gimp),
GIMP_TRANSPARENT_FILL); GIMP_TRANSPARENT_FILL);
gimp_layer_translate (new_layer, off_x, off_y); gimp_layer_translate (new_layer, off_x, off_y, FALSE);
} }
gimp_image_add_layer (gimage, new_layer, -1); gimp_image_add_layer (gimage, new_layer, -1);
......
...@@ -180,7 +180,7 @@ gimp_image_crop (GimpImage *gimage, ...@@ -180,7 +180,7 @@ gimp_image_crop (GimpImage *gimage,
next = g_list_next (list); next = g_list_next (list);
gimp_layer_translate (layer, -x1, -y1); gimp_layer_translate (layer, -x1, -y1, TRUE);
gimp_drawable_offsets (GIMP_DRAWABLE (layer), &off_x, &off_y); gimp_drawable_offsets (GIMP_DRAWABLE (layer), &off_x, &off_y);
......
...@@ -568,11 +568,15 @@ gimp_image_mask_load (GimpImage *gimage, ...@@ -568,11 +568,15 @@ gimp_image_mask_load (GimpImage *gimage,
void void
gimp_image_mask_translate (GimpImage *gimage, gimp_image_mask_translate (GimpImage *gimage,
gint off_x, gint off_x,
gint off_y) gint off_y,
gboolean push_undo)
{ {
g_return_if_fail (GIMP_IS_IMAGE (gimage)); g_return_if_fail (GIMP_IS_IMAGE (gimage));
gimp_image_mask_push_undo (gimage, _("Translate Selection")); if (push_undo)
gimp_image_mask_push_undo (gimage, _("Translate Selection"));
else
gimp_image_mask_invalidate (gimage);
gimp_channel_translate (gimp_image_get_mask (gimage), off_x, off_y, FALSE); gimp_channel_translate (gimp_image_get_mask (gimage), off_x, off_y, FALSE);
......
...@@ -79,7 +79,8 @@ void gimp_image_mask_shrink (GimpImage *gimage, ...@@ -79,7 +79,8 @@ void gimp_image_mask_shrink (GimpImage *gimage,
void gimp_image_mask_translate (GimpImage *gimage, void gimp_image_mask_translate (GimpImage *gimage,
gint off_x, gint off_x,
gint off_y); gint off_y,
gboolean push_undo);
void gimp_image_mask_load (GimpImage *gimage, void gimp_image_mask_load (GimpImage *gimage,
GimpChannel *channel); GimpChannel *channel);
......
...@@ -125,7 +125,7 @@ gimp_image_resize (GimpImage *gimage, ...@@ -125,7 +125,7 @@ gimp_image_resize (GimpImage *gimage,
{ {
layer = (GimpLayer *) list->data; layer = (GimpLayer *) list->data;
gimp_layer_translate (layer, offset_x, offset_y); gimp_layer_translate (layer, offset_x, offset_y, TRUE);
} }
/* Make sure the projection matches the gimage size */ /* Make sure the projection matches the gimage size */
......
...@@ -802,9 +802,8 @@ typedef struct _MaskUndo MaskUndo; ...@@ -802,9 +802,8 @@ typedef struct _MaskUndo MaskUndo;
struct _MaskUndo struct _MaskUndo
{ {
GimpChannel *channel; /* the channel this undo is for */ TileManager *tiles; /* the actual mask */
TileManager *tiles; /* the actual mask */ gint x, y; /* offsets */
gint x, y; /* offsets */
}; };
static gboolean undo_pop_mask (GimpUndo *undo, static gboolean undo_pop_mask (GimpUndo *undo,
...@@ -847,21 +846,20 @@ gimp_image_undo_push_mask (GimpImage *gimage, ...@@ -847,21 +846,20 @@ gimp_image_undo_push_mask (GimpImage *gimage,
if (undo_tiles) if (undo_tiles)
size += tile_manager_get_memsize (undo_tiles); size += tile_manager_get_memsize (undo_tiles);
if ((new = gimp_image_undo_push (gimage, if ((new = gimp_image_undo_push_item (gimage, GIMP_ITEM (mask),
size, sizeof (MaskUndo), size, sizeof (MaskUndo),
GIMP_UNDO_MASK, undo_desc, GIMP_UNDO_MASK, undo_desc,
FALSE, FALSE,
undo_pop_mask, undo_pop_mask,
undo_free_mask))) undo_free_mask)))
{ {
MaskUndo *mu; MaskUndo *mu;
mu = new->data; mu = new->data;
mu->channel = mask; mu->tiles = undo_tiles;
mu->tiles = undo_tiles; mu->x = x1;
mu->x = x1; mu->y = y1;
mu->y = y1;
return TRUE; return TRUE;
} }
...@@ -878,34 +876,38 @@ undo_pop_mask (GimpUndo *undo, ...@@ -878,34 +876,38 @@ undo_pop_mask (GimpUndo *undo,
GimpUndoAccumulator *accum) GimpUndoAccumulator *accum)
{ {
MaskUndo *mu; MaskUndo *mu;
GimpChannel *channel;
TileManager *new_tiles; TileManager *new_tiles;
PixelRegion srcPR, destPR; PixelRegion srcPR, destPR;
gint x1, y1, x2, y2; gint x1, y1, x2, y2;
gint width, height; gint width = 0;
guchar empty = 0; gint height = 0;
guchar empty = 0;
width = height = 0;
mu = (MaskUndo *) undo->data; mu = (MaskUndo *) undo->data;
if (gimp_channel_bounds (mu->channel, &x1, &y1, &x2, &y2)) channel = GIMP_CHANNEL (GIMP_ITEM_UNDO (undo)->item);
if (gimp_channel_bounds (channel, &x1, &y1, &x2, &y2))
{ {
new_tiles = tile_manager_new ((x2 - x1), (y2 - y1), 1); new_tiles = tile_manager_new ((x2 - x1), (y2 - y1), 1);
pixel_region_init (&srcPR, GIMP_DRAWABLE (mu->channel)->tiles, pixel_region_init (&srcPR, GIMP_DRAWABLE (channel)->tiles,
x1, y1, (x2 - x1), (y2 - y1), FALSE); x1, y1, (x2 - x1), (y2 - y1), FALSE);
pixel_region_init (&destPR, new_tiles, pixel_region_init (&destPR, new_tiles,
0, 0, (x2 - x1), (y2 - y1), TRUE); 0, 0, (x2 - x1), (y2 - y1), TRUE);
copy_region (&srcPR, &destPR); copy_region (&srcPR, &destPR);
pixel_region_init (&srcPR, GIMP_DRAWABLE (mu->channel)->tiles, pixel_region_init (&srcPR, GIMP_DRAWABLE (channel)->tiles,
x1, y1, (x2 - x1), (y2 - y1), TRUE); x1, y1, (x2 - x1), (y2 - y1), TRUE);
color_region (&srcPR, &empty); color_region (&srcPR, &empty);
} }
else else
new_tiles = NULL; {
new_tiles = NULL;
}
if (mu->tiles) if (mu->tiles)
{ {
...@@ -914,7 +916,7 @@ undo_pop_mask (GimpUndo *undo, ...@@ -914,7 +916,7 @@ undo_pop_mask (GimpUndo *undo,
pixel_region_init (&srcPR, mu->tiles, pixel_region_init (&srcPR, mu->tiles,
0, 0, width, height, FALSE); 0, 0, width, height, FALSE);
pixel_region_init (&destPR, GIMP_DRAWABLE (mu->channel)->tiles, pixel_region_init (&destPR, GIMP_DRAWABLE (channel)->tiles,
mu->x, mu->y, width, height, TRUE); mu->x, mu->y, width, height, TRUE);
copy_region (&srcPR, &destPR); copy_region (&srcPR, &destPR);
...@@ -922,52 +924,52 @@ undo_pop_mask (GimpUndo *undo, ...@@ -922,52 +924,52 @@ undo_pop_mask (GimpUndo *undo,
tile_manager_destroy (mu->tiles); tile_manager_destroy (mu->tiles);
} }
if (mu->channel == gimp_image_get_mask (undo->gimage)) if (channel == gimp_image_get_mask (undo->gimage))
{ {
/* invalidate the current bounds and boundary of the mask */ /* invalidate the current bounds and boundary of the mask */
gimp_image_mask_invalidate (undo->gimage); gimp_image_mask_invalidate (undo->gimage);
} }
else else
{ {
mu->channel->boundary_known = FALSE; channel->boundary_known = FALSE;
GIMP_DRAWABLE (mu->channel)->preview_valid = FALSE; GIMP_DRAWABLE (channel)->preview_valid = FALSE;
} }
if (mu->tiles) if (mu->tiles)
{ {
mu->channel->empty = FALSE; channel->empty = FALSE;
mu->channel->x1 = mu->x; channel->x1 = mu->x;
mu->channel->y1 = mu->y; channel->y1 = mu->y;
mu->channel->x2 = mu->x + width; channel->x2 = mu->x + width;
mu->channel->y2 = mu->y + height; channel->y2 = mu->y + height;
} }
else else
{ {
mu->channel->empty = TRUE; channel->empty = TRUE;
mu->channel->x1 = 0; channel->x1 = 0;
mu->channel->y1 = 0; channel->y1 = 0;
mu->channel->x2 = GIMP_DRAWABLE (mu->channel)->width; channel->x2 = GIMP_DRAWABLE (channel)->width;
mu->channel->y2 = GIMP_DRAWABLE (mu->channel)->height; channel->y2 = GIMP_DRAWABLE (channel)->height;
} }
/* we know the bounds */ /* we know the bounds */
mu->channel->bounds_known = TRUE; channel->bounds_known = TRUE;
/* set the new mask undo parameters */ /* set the new mask undo parameters */
mu->tiles = new_tiles; mu->tiles = new_tiles;
mu->x = x1; mu->x = x1;
mu->y = y1; mu->y = y1;
if (mu->channel == gimp_image_get_mask (undo->gimage)) if (channel == gimp_image_get_mask (undo->gimage))
{ {
accum->mask_changed = TRUE; accum->mask_changed = TRUE;
} }
else else
{ {
gimp_drawable_update (GIMP_DRAWABLE (mu->channel), gimp_drawable_update (GIMP_DRAWABLE (channel),
0, 0, 0, 0,
GIMP_DRAWABLE (mu->channel)->width, GIMP_DRAWABLE (channel)->width,
GIMP_DRAWABLE (mu->channel)->height); GIMP_DRAWABLE (channel)->height);
} }
return TRUE; return TRUE;
...@@ -1679,8 +1681,8 @@ typedef struct _LayerDisplaceUndo LayerDisplaceUndo; ...@@ -1679,8 +1681,8 @@ typedef struct _LayerDisplaceUndo LayerDisplaceUndo;
struct _LayerDisplaceUndo struct _LayerDisplaceUndo
{ {
gint offset_x; gint old_offset_x;
gint offset_y; gint old_offset_y;
GSList *path_undo; GSList *path_undo;
}; };
...@@ -1712,9 +1714,9 @@ gimp_image_undo_push_layer_displace (GimpImage *gimage, ...@@ -1712,9 +1714,9 @@ gimp_image_undo_push_layer_displace (GimpImage *gimage,
ldu = new->data; ldu = new->data;
ldu->offset_x = GIMP_DRAWABLE (layer)->offset_x; ldu->old_offset_x = GIMP_DRAWABLE (layer)->offset_x;
ldu->offset_y = GIMP_DRAWABLE (layer)->offset_y; ldu->old_offset_y = GIMP_DRAWABLE (layer)->offset_y;
ldu->path_undo = path_transform_start_undo (gimage); ldu->path_undo = path_transform_start_undo (gimage);
return TRUE; return TRUE;
} }
...@@ -1729,42 +1731,22 @@ undo_pop_layer_displace (GimpUndo *undo, ...@@ -1729,42 +1731,22 @@ undo_pop_layer_displace (GimpUndo *undo,
{ {
LayerDisplaceUndo *ldu; LayerDisplaceUndo *ldu;
GimpLayer *layer; GimpLayer *layer;
gint old_offset_x; gint offset_x;
gint old_offset_y; gint offset_y;
ldu = (LayerDisplaceUndo *) undo->data; ldu = (LayerDisplaceUndo *) undo->data;
layer = GIMP_LAYER (GIMP_ITEM_UNDO (undo)->item); layer = GIMP_LAYER (GIMP_ITEM_UNDO (undo)->item);
old_offset_x = GIMP_DRAWABLE (layer)->offset_x; gimp_drawable_offsets (GIMP_DRAWABLE (layer), &offset_x, &offset_y);
old_offset_y = GIMP_DRAWABLE (layer)->offset_y;
gimp_drawable_update (GIMP_DRAWABLE (layer),
0, 0,
GIMP_DRAWABLE (layer)->width,
GIMP_DRAWABLE (layer)->height);
GIMP_DRAWABLE (layer)->offset_x = ldu->offset_x;
GIMP_DRAWABLE (layer)->offset_y = ldu->offset_y;
gimp_drawable_update (GIMP_DRAWABLE (layer),
0, 0,
GIMP_DRAWABLE (layer)->width,
GIMP_DRAWABLE (layer)->height);
if (layer->mask)
{
GIMP_DRAWABLE (layer->mask)->offset_x = ldu->offset_x;
GIMP_DRAWABLE (layer->mask)->offset_y = ldu->offset_y;
gimp_drawable_update (GIMP_DRAWABLE (layer->mask),
0, 0,
GIMP_DRAWABLE (layer->mask)->width,
GIMP_DRAWABLE (layer->mask)->height);
}
/* invalidate the selection boundary because of a layer modification */ gimp_layer_translate (layer,
gimp_layer_invalidate_boundary (layer); ldu->old_offset_x - offset_x,
ldu->old_offset_y - offset_y,
FALSE);
ldu->offset_x = old_offset_x; ldu->old_offset_x = offset_x;
ldu->offset_y = old_offset_y; ldu->old_offset_y = offset_y;
/* Now undo paths bits */ /* Now undo paths bits */
if (ldu->path_undo) if (ldu->path_undo)
......
...@@ -884,14 +884,15 @@ gimp_layer_apply_mask (GimpLayer *layer, ...@@ -884,14 +884,15 @@ gimp_layer_apply_mask (GimpLayer *layer,
void void
gimp_layer_translate (GimpLayer *layer, gimp_layer_translate (GimpLayer *layer,
gint off_x, gint off_x,
gint off_y) gint off_y,
gboolean push_undo)
{ {
g_return_if_fail (GIMP_IS_LAYER (layer)); g_return_if_fail (GIMP_IS_LAYER (layer));
/* the undo call goes here */ if (push_undo)
gimp_image_undo_push_layer_displace (gimp_item_get_image (GIMP_ITEM (layer)), gimp_image_undo_push_layer_displace (gimp_item_get_image (GIMP_ITEM (layer)),
_("Move Layer"), _("Move Layer"),
layer); layer);
/* update the affected region */ /* update the affected region */
gimp_drawable_update (GIMP_DRAWABLE (layer), gimp_drawable_update (GIMP_DRAWABLE (layer),
......
...@@ -104,7 +104,8 @@ void gimp_layer_apply_mask (GimpLayer *layer, ...@@ -104,7 +104,8 @@ void gimp_layer_apply_mask (GimpLayer *layer,
gboolean push_undo); gboolean push_undo);
void gimp_layer_translate (GimpLayer *layer, void gimp_layer_translate (GimpLayer *layer,
gint off_x, gint off_x,
gint off_y); gint off_y,
gboolean push_undo);
void gimp_layer_add_alpha (GimpLayer *layer); void gimp_layer_add_alpha (GimpLayer *layer);
gboolean gimp_layer_scale_by_factors (GimpLayer *layer, gboolean gimp_layer_scale_by_factors (GimpLayer *layer,
gdouble w_factor, gdouble w_factor,
......
...@@ -67,7 +67,7 @@ gimp_display_shell_drop_drawable (GtkWidget *widget, ...@@ -67,7 +67,7 @@ gimp_display_shell_drop_drawable (GtkWidget *widget,
off_x = (gdisp->gimage->width - gimp_drawable_width (drawable)) / 2; off_x = (gdisp->gimage->width - gimp_drawable_width (drawable)) / 2;
off_y = (gdisp->gimage->height - gimp_drawable_height (drawable)) / 2; off_y = (gdisp->gimage->height - gimp_drawable_height (drawable)) / 2;
gimp_layer_translate (new_layer, off_x, off_y); gimp_layer_translate (new_layer, off_x, off_y, FALSE);
gimp_image_add_layer (gdisp->gimage, new_layer, -1); gimp_image_add_layer (gdisp->gimage, new_layer, -1);
......
...@@ -572,7 +572,7 @@ layers_new_layer_query (GimpImage *gimage, ...@@ -572,7 +572,7 @@ layers_new_layer_query (GimpImage *gimage,
gimp_drawable_fill_by_type (GIMP_DRAWABLE (new_layer), gimp_drawable_fill_by_type (GIMP_DRAWABLE (new_layer),
gimp_get_user_context (gimage->gimp), gimp_get_user_context (gimage->gimp),
GIMP_TRANSPARENT_FILL); GIMP_TRANSPARENT_FILL);
gimp_layer_translate (new_layer, off_x, off_y); gimp_layer_translate (new_layer, off_x, off_y, FALSE);
} }
gimp_image_add_layer (gimage, new_layer, -1); gimp_image_add_layer (gimage, new_layer, -1);
......
...@@ -650,7 +650,7 @@ layer_translate_invoker (Gimp *gimp, ...@@ -650,7 +650,7 @@ layer_translate_invoker (Gimp *gimp,
tmp_layer = (GimpLayer *) layer_list->data; tmp_layer = (GimpLayer *) layer_list->data;
if ((tmp_layer == layer) || gimp_layer_get_linked (tmp_layer)) if ((tmp_layer == layer) || gimp_layer_get_linked (tmp_layer))
gimp_layer_translate (tmp_layer, offx, offy); gimp_layer_translate (tmp_layer, offx, offy, TRUE);
} }
if (floating_layer) if (floating_layer)
...@@ -784,7 +784,7 @@ layer_set_offsets_invoker (Gimp *gimp, ...@@ -784,7 +784,7 @@ layer_set_offsets_invoker (Gimp *gimp,
if ((tmp_layer == layer) || gimp_layer_get_linked (tmp_layer)) if ((tmp_layer == layer) || gimp_layer_get_linked (tmp_layer))
gimp_layer_translate (tmp_layer, gimp_layer_translate (tmp_layer,
(offx - GIMP_DRAWABLE (layer)->offset_x), (offx - GIMP_DRAWABLE (layer)->offset_x),
(offy - GIMP_DRAWABLE (layer)->offset_y)); (offy - GIMP_DRAWABLE (layer)->offset_y), TRUE);
} }
if (floating_layer) if (floating_layer)
......
...@@ -307,7 +307,7 @@ selection_translate_invoker (Gimp *gimp, ...@@ -307,7 +307,7 @@ selection_translate_invoker (Gimp *gimp,
offy = args[2].value.pdb_int; offy = args[2].value.pdb_int;
if (success) if (success)
gimp_image_mask_translate (gimage, offx, offy); gimp_image_mask_translate (gimage, offx, offy, TRUE);
return procedural_db_return_args (&selection_translate_proc, success); return procedural_db_return_args (&selection_translate_proc, success);
} }
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include "core/gimplayer.h" #include "core/gimplayer.h"
#include "core/gimplayer-floating-sel.h" #include "core/gimplayer-floating-sel.h"
#include "core/gimplist.h" #include "core/gimplist.h"
#include "core/gimpundostack.h"
#include "display/gimpdisplay.h" #include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h" #include "display/gimpdisplayshell.h"
...@@ -346,7 +347,8 @@ gimp_edit_selection_tool_button_release (GimpTool *tool, ...@@ -346,7 +347,8 @@ gimp_edit_selection_tool_button_release (GimpTool *tool,
*/ */
gimp_image_mask_translate (gdisp->gimage, gimp_image_mask_translate (gdisp->gimage,
edit_select->cumlx, edit_select->cumlx,
edit_select->cumly); edit_select->cumly,
TRUE);
if (edit_select->first_move) if (edit_select->first_move)
{ {
...@@ -483,7 +485,7 @@ gimp_edit_selection_tool_motion (GimpTool *tool, ...@@ -483,7 +485,7 @@ gimp_edit_selection_tool_motion (GimpTool *tool,
if (layer == gdisp->gimage->active_layer || if (layer == gdisp->gimage->active_layer ||
gimp_layer_get_linked (layer)) gimp_layer_get_linked (layer))
{ {
gimp_layer_translate (layer, xoffset, yoffset); gimp_layer_translate (layer, xoffset, yoffset, TRUE);
} }
} }
...@@ -527,7 +529,7 @@ gimp_edit_selection_tool_motion (GimpTool *tool, ...@@ -527,7 +529,7 @@ gimp_edit_selection_tool_motion (GimpTool *tool,
layer = gimp_image_get_active_layer (gdisp->gimage); layer = gimp_image_get_active_layer (gdisp->gimage);
floating_sel_relax (layer, TRUE); floating_sel_relax (layer, TRUE);
gimp_layer_translate (layer, xoffset, yoffset); gimp_layer_translate (layer, xoffset, yoffset, TRUE);
floating_sel_rigor (layer, TRUE); floating_sel_rigor (layer, TRUE);