Fixed evil<tm> double casting of enum to glong to gpointer for layer_mod

* app/undo.c: Fixed evil<tm> double casting of enum to glong to
	gpointer for layer_mod undo by using a struct instead of an array
	of gpointer (!!!) for storing layer_mod undo data.  Also moved
	layer offset undo information out of the undo tile manager.
	* app/image_map.c: Moved layer offset undo information out of the
	undo tile manager.

	Above changes may break image_map and layer_mod undos, please test
	as I haven't. :)
This commit is contained in:
Kelly Martin 2001-11-28 16:54:11 +00:00
parent 9bac8fafec
commit 36efb12be7
5 changed files with 128 additions and 80 deletions

View File

@ -1,3 +1,15 @@
2001-11-28 Kelly Martin <kmartin@pyrzqxgl.org>
* app/undo.c: Fixed evil<tm> double casting of enum to glong to
gpointer for layer_mod undo by using a struct instead of an array
of gpointer (!!!) for storing layer_mod undo data. Also moved
layer offset undo information out of the undo tile manager.
* app/image_map.c: Moved layer offset undo information out of the
undo tile manager.
Above changes may break image_map and layer_mod undos, please test
as I haven't. :)
2001-11-28 Michael Natterer <mitch@gimp.org>
* app/core/Makefile.am

View File

@ -1573,36 +1573,46 @@ undo_free_layer (UndoState state,
/*********************************/
/* Layer Mod Undo */
typedef struct _LayerModUndo LayerModUndo;
struct _LayerModUndo
{
GimpLayer *layer;
TileManager *tiles;
GimpImageType type;
gint offset_x;
gint offset_y;
};
gboolean
undo_push_layer_mod (GimpImage *gimage,
gpointer layer_ptr)
{
GimpLayer *layer;
Undo *new;
TileManager *tiles;
gpointer *data;
gint size;
GimpLayer *layer;
Undo *new;
TileManager *tiles;
LayerModUndo *data;
gint size;
layer = (GimpLayer *) layer_ptr;
tiles = GIMP_DRAWABLE (layer)->tiles;
tile_manager_set_offsets (tiles,
GIMP_DRAWABLE (layer)->offset_x,
GIMP_DRAWABLE (layer)->offset_y);
size = (GIMP_DRAWABLE (layer)->width * GIMP_DRAWABLE (layer)->height *
GIMP_DRAWABLE (layer)->bytes + sizeof (gpointer) * 3);
GIMP_DRAWABLE (layer)->bytes + sizeof (LayerModUndo));
if ((new = undo_push (gimage, size, LAYER_MOD, TRUE)))
{
data = g_new (gpointer, 3);
data = g_new (LayerModUndo, 1);
new->data = data;
new->pop_func = undo_pop_layer_mod;
new->free_func = undo_free_layer_mod;
data[0] = layer_ptr;
data[1] = (gpointer) tiles;
data[2] = (gpointer) ((glong) GIMP_DRAWABLE (layer)->type);
data->layer = layer;
data->tiles = tiles;
data->type = GIMP_DRAWABLE (layer)->type;
data->offset_x = GIMP_DRAWABLE (layer)->offset_x;
data->offset_y = GIMP_DRAWABLE (layer)->offset_y;
return TRUE;
}
@ -1620,17 +1630,19 @@ undo_pop_layer_mod (GimpImage *gimage,
UndoType type,
gpointer data_ptr)
{
gpointer *data;
gint layer_type;
TileManager *tiles;
TileManager *temp;
GimpLayer *layer;
gboolean old_has_alpha;
LayerModUndo *data;
gint layer_type;
gint offset_x, offset_y;
TileManager *tiles;
TileManager *temp;
GimpLayer *layer;
gboolean old_has_alpha;
data = (gpointer *) data_ptr;
layer = (GimpLayer *) data[0];
tiles = (TileManager *) data[1];
data = (LayerModUndo *) data_ptr;
layer = data->layer;
tiles = data->tiles;
offset_x = data->offset_x;
offset_y = data->offset_y;
/* Issue the first update */
gimp_image_update (gimage,
@ -1641,11 +1653,12 @@ undo_pop_layer_mod (GimpImage *gimage,
/* Create a tile manager to store the current layer contents */
temp = GIMP_DRAWABLE (layer)->tiles;
tile_manager_set_offsets (temp,
GIMP_DRAWABLE (layer)->offset_x,
GIMP_DRAWABLE (layer)->offset_y);
layer_type = (glong) data[2];
data[2] = (gpointer) ((glong) GIMP_DRAWABLE (layer)->type);
data->offset_x = GIMP_DRAWABLE (layer)->offset_x;
data->offset_y = GIMP_DRAWABLE (layer)->offset_y;
layer_type = data->type;
data->type = GIMP_DRAWABLE (layer)->type;
old_has_alpha = GIMP_DRAWABLE (layer)->has_alpha;
@ -1656,15 +1669,12 @@ undo_pop_layer_mod (GimpImage *gimage,
GIMP_DRAWABLE (layer)->bytes = tile_manager_bpp (tiles);
GIMP_DRAWABLE (layer)->type = layer_type;
GIMP_DRAWABLE (layer)->has_alpha = GIMP_IMAGE_TYPE_HAS_ALPHA (layer_type);
tile_manager_get_offsets (tiles,
&(GIMP_DRAWABLE (layer)->offset_x),
&(GIMP_DRAWABLE (layer)->offset_y));
GIMP_DRAWABLE (layer)->offset_x = offset_x;
GIMP_DRAWABLE (layer)->offset_y = offset_y;
if (layer->mask)
{
tile_manager_get_offsets (tiles,
&(GIMP_DRAWABLE (layer->mask)->offset_x),
&(GIMP_DRAWABLE (layer->mask)->offset_y));
GIMP_DRAWABLE(layer->mask)->offset_x = offset_x;
GIMP_DRAWABLE(layer->mask)->offset_y = offset_y;
}
if (GIMP_DRAWABLE (layer)->has_alpha != old_has_alpha &&
@ -1674,7 +1684,7 @@ undo_pop_layer_mod (GimpImage *gimage,
}
/* Set the new tile manager */
data[1] = temp;
data->tiles = temp;
/* Issue the second update */
gimp_drawable_update (GIMP_DRAWABLE (layer),

View File

@ -50,6 +50,8 @@ struct _ImageMap
GimpDisplay *gdisp;
GimpDrawable *drawable;
TileManager *undo_tiles;
gint undo_offset_x;
gint undo_offset_y;
ImageMapApplyFunc apply_func;
gpointer user_data;
PixelRegion srcPR;
@ -81,6 +83,8 @@ image_map_create (GimpDisplay *gdisp,
image_map->gdisp = gdisp;
image_map->drawable = drawable;
image_map->undo_tiles = NULL;
image_map->undo_offset_x = 0;
image_map->undo_offset_y = 0;
image_map->apply_func = NULL;
image_map->user_data = NULL;
image_map->state = IMAGE_MAP_WAITING;
@ -131,7 +135,8 @@ image_map_apply (ImageMap *image_map,
/* If undo tiles don't exist, or change size, (re)allocate */
if (image_map->undo_tiles)
{
tile_manager_get_offsets (image_map->undo_tiles, &offset_x, &offset_y);
offset_x = image_map->undo_offset_x;
offset_y = image_map->undo_offset_y;
width = tile_manager_width (image_map->undo_tiles);
height = tile_manager_height (image_map->undo_tiles);
}
@ -170,7 +175,8 @@ image_map_apply (ImageMap *image_map,
copy_region (&image_map->srcPR, &image_map->destPR);
/* Set the offsets */
tile_manager_set_offsets (image_map->undo_tiles, x1, y1);
image_map->undo_offset_x = x1;
image_map->undo_offset_y = y1;
}
else /* image_map->undo_tiles exist AND drawable dimensions have not changed... */
{
@ -230,7 +236,8 @@ image_map_commit (ImageMap *image_map)
/* Register an undo step */
if (image_map->undo_tiles)
{
tile_manager_get_offsets (image_map->undo_tiles, &x1, &y1);
x1 = image_map->undo_offset_x;
y1 = image_map->undo_offset_y;
x2 = x1 + tile_manager_width (image_map->undo_tiles);
y2 = y1 + tile_manager_height (image_map->undo_tiles);
@ -272,7 +279,8 @@ image_map_clear (ImageMap *image_map)
gint width;
gint height;
tile_manager_get_offsets (image_map->undo_tiles, &offset_x, &offset_y);
offset_x = image_map->undo_offset_x;
offset_y = image_map->undo_offset_y;
width = tile_manager_width (image_map->undo_tiles);
height = tile_manager_height (image_map->undo_tiles),

View File

@ -50,6 +50,8 @@ struct _ImageMap
GimpDisplay *gdisp;
GimpDrawable *drawable;
TileManager *undo_tiles;
gint undo_offset_x;
gint undo_offset_y;
ImageMapApplyFunc apply_func;
gpointer user_data;
PixelRegion srcPR;
@ -81,6 +83,8 @@ image_map_create (GimpDisplay *gdisp,
image_map->gdisp = gdisp;
image_map->drawable = drawable;
image_map->undo_tiles = NULL;
image_map->undo_offset_x = 0;
image_map->undo_offset_y = 0;
image_map->apply_func = NULL;
image_map->user_data = NULL;
image_map->state = IMAGE_MAP_WAITING;
@ -131,7 +135,8 @@ image_map_apply (ImageMap *image_map,
/* If undo tiles don't exist, or change size, (re)allocate */
if (image_map->undo_tiles)
{
tile_manager_get_offsets (image_map->undo_tiles, &offset_x, &offset_y);
offset_x = image_map->undo_offset_x;
offset_y = image_map->undo_offset_y;
width = tile_manager_width (image_map->undo_tiles);
height = tile_manager_height (image_map->undo_tiles);
}
@ -170,7 +175,8 @@ image_map_apply (ImageMap *image_map,
copy_region (&image_map->srcPR, &image_map->destPR);
/* Set the offsets */
tile_manager_set_offsets (image_map->undo_tiles, x1, y1);
image_map->undo_offset_x = x1;
image_map->undo_offset_y = y1;
}
else /* image_map->undo_tiles exist AND drawable dimensions have not changed... */
{
@ -230,7 +236,8 @@ image_map_commit (ImageMap *image_map)
/* Register an undo step */
if (image_map->undo_tiles)
{
tile_manager_get_offsets (image_map->undo_tiles, &x1, &y1);
x1 = image_map->undo_offset_x;
y1 = image_map->undo_offset_y;
x2 = x1 + tile_manager_width (image_map->undo_tiles);
y2 = y1 + tile_manager_height (image_map->undo_tiles);
@ -272,7 +279,8 @@ image_map_clear (ImageMap *image_map)
gint width;
gint height;
tile_manager_get_offsets (image_map->undo_tiles, &offset_x, &offset_y);
offset_x = image_map->undo_offset_x;
offset_y = image_map->undo_offset_y;
width = tile_manager_width (image_map->undo_tiles);
height = tile_manager_height (image_map->undo_tiles),

View File

@ -1573,36 +1573,46 @@ undo_free_layer (UndoState state,
/*********************************/
/* Layer Mod Undo */
typedef struct _LayerModUndo LayerModUndo;
struct _LayerModUndo
{
GimpLayer *layer;
TileManager *tiles;
GimpImageType type;
gint offset_x;
gint offset_y;
};
gboolean
undo_push_layer_mod (GimpImage *gimage,
gpointer layer_ptr)
{
GimpLayer *layer;
Undo *new;
TileManager *tiles;
gpointer *data;
gint size;
GimpLayer *layer;
Undo *new;
TileManager *tiles;
LayerModUndo *data;
gint size;
layer = (GimpLayer *) layer_ptr;
tiles = GIMP_DRAWABLE (layer)->tiles;
tile_manager_set_offsets (tiles,
GIMP_DRAWABLE (layer)->offset_x,
GIMP_DRAWABLE (layer)->offset_y);
size = (GIMP_DRAWABLE (layer)->width * GIMP_DRAWABLE (layer)->height *
GIMP_DRAWABLE (layer)->bytes + sizeof (gpointer) * 3);
GIMP_DRAWABLE (layer)->bytes + sizeof (LayerModUndo));
if ((new = undo_push (gimage, size, LAYER_MOD, TRUE)))
{
data = g_new (gpointer, 3);
data = g_new (LayerModUndo, 1);
new->data = data;
new->pop_func = undo_pop_layer_mod;
new->free_func = undo_free_layer_mod;
data[0] = layer_ptr;
data[1] = (gpointer) tiles;
data[2] = (gpointer) ((glong) GIMP_DRAWABLE (layer)->type);
data->layer = layer;
data->tiles = tiles;
data->type = GIMP_DRAWABLE (layer)->type;
data->offset_x = GIMP_DRAWABLE (layer)->offset_x;
data->offset_y = GIMP_DRAWABLE (layer)->offset_y;
return TRUE;
}
@ -1620,17 +1630,19 @@ undo_pop_layer_mod (GimpImage *gimage,
UndoType type,
gpointer data_ptr)
{
gpointer *data;
gint layer_type;
TileManager *tiles;
TileManager *temp;
GimpLayer *layer;
gboolean old_has_alpha;
LayerModUndo *data;
gint layer_type;
gint offset_x, offset_y;
TileManager *tiles;
TileManager *temp;
GimpLayer *layer;
gboolean old_has_alpha;
data = (gpointer *) data_ptr;
layer = (GimpLayer *) data[0];
tiles = (TileManager *) data[1];
data = (LayerModUndo *) data_ptr;
layer = data->layer;
tiles = data->tiles;
offset_x = data->offset_x;
offset_y = data->offset_y;
/* Issue the first update */
gimp_image_update (gimage,
@ -1641,11 +1653,12 @@ undo_pop_layer_mod (GimpImage *gimage,
/* Create a tile manager to store the current layer contents */
temp = GIMP_DRAWABLE (layer)->tiles;
tile_manager_set_offsets (temp,
GIMP_DRAWABLE (layer)->offset_x,
GIMP_DRAWABLE (layer)->offset_y);
layer_type = (glong) data[2];
data[2] = (gpointer) ((glong) GIMP_DRAWABLE (layer)->type);
data->offset_x = GIMP_DRAWABLE (layer)->offset_x;
data->offset_y = GIMP_DRAWABLE (layer)->offset_y;
layer_type = data->type;
data->type = GIMP_DRAWABLE (layer)->type;
old_has_alpha = GIMP_DRAWABLE (layer)->has_alpha;
@ -1656,15 +1669,12 @@ undo_pop_layer_mod (GimpImage *gimage,
GIMP_DRAWABLE (layer)->bytes = tile_manager_bpp (tiles);
GIMP_DRAWABLE (layer)->type = layer_type;
GIMP_DRAWABLE (layer)->has_alpha = GIMP_IMAGE_TYPE_HAS_ALPHA (layer_type);
tile_manager_get_offsets (tiles,
&(GIMP_DRAWABLE (layer)->offset_x),
&(GIMP_DRAWABLE (layer)->offset_y));
GIMP_DRAWABLE (layer)->offset_x = offset_x;
GIMP_DRAWABLE (layer)->offset_y = offset_y;
if (layer->mask)
{
tile_manager_get_offsets (tiles,
&(GIMP_DRAWABLE (layer->mask)->offset_x),
&(GIMP_DRAWABLE (layer->mask)->offset_y));
GIMP_DRAWABLE(layer->mask)->offset_x = offset_x;
GIMP_DRAWABLE(layer->mask)->offset_y = offset_y;
}
if (GIMP_DRAWABLE (layer)->has_alpha != old_has_alpha &&
@ -1674,7 +1684,7 @@ undo_pop_layer_mod (GimpImage *gimage,
}
/* Set the new tile manager */
data[1] = temp;
data->tiles = temp;
/* Issue the second update */
gimp_drawable_update (GIMP_DRAWABLE (layer),