add support for IMAGE_GRID and IMAGE_COLORMAP undos.

2007-01-28  Michael Natterer  <mitch@gimp.org>

	* app/core/gimpimageundo.[ch]: add support for IMAGE_GRID and
	IMAGE_COLORMAP undos.

	* app/core/gimpimage-undo-push.c: use GimpImageUndo for grid and
	colormap undos.


svn path=/trunk/; revision=21801
This commit is contained in:
Michael Natterer
2007-01-29 19:11:35 +00:00
committed by Michael Natterer
parent 9a7de0552d
commit c757ac1534
4 changed files with 189 additions and 150 deletions

View File

@ -1,3 +1,11 @@
2007-01-28 Michael Natterer <mitch@gimp.org>
* app/core/gimpimageundo.[ch]: add support for IMAGE_GRID and
IMAGE_COLORMAP undos.
* app/core/gimpimage-undo-push.c: use GimpImageUndo for grid and
colormap undos.
2007-01-29 Michael Natterer <mitch@gimp.org> 2007-01-29 Michael Natterer <mitch@gimp.org>
* app/core/gimpimage-undo-push.[ch]: return a GimpUndo* instead * app/core/gimpimage-undo-push.[ch]: return a GimpUndo* instead

View File

@ -35,8 +35,6 @@
#include "gimpgrid.h" #include "gimpgrid.h"
#include "gimpguide.h" #include "gimpguide.h"
#include "gimpimage.h" #include "gimpimage.h"
#include "gimpimage-colormap.h"
#include "gimpimage-grid.h"
#include "gimpimage-guides.h" #include "gimpimage-guides.h"
#include "gimpimage-sample-points.h" #include "gimpimage-sample-points.h"
#include "gimpimage-undo.h" #include "gimpimage-undo.h"
@ -225,76 +223,21 @@ undo_free_image_guide (GimpUndo *undo,
/* Grid Undo */ /* Grid Undo */
/****************/ /****************/
typedef struct _GridUndo GridUndo;
struct _GridUndo
{
GimpGrid *grid;
};
static gboolean undo_pop_image_grid (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum);
static void undo_free_image_grid (GimpUndo *undo,
GimpUndoMode undo_mode);
GimpUndo * GimpUndo *
gimp_image_undo_push_image_grid (GimpImage *image, gimp_image_undo_push_image_grid (GimpImage *image,
const gchar *undo_desc, const gchar *undo_desc,
GimpGrid *grid) GimpGrid *grid)
{ {
GimpUndo *new;
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL); g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
g_return_val_if_fail (GIMP_IS_GRID (grid), NULL); g_return_val_if_fail (GIMP_IS_GRID (grid), NULL);
if ((new = gimp_image_undo_push (image, GIMP_TYPE_UNDO, return gimp_image_undo_push (image, GIMP_TYPE_IMAGE_UNDO,
sizeof (GridUndo), 0, 0,
sizeof (GridUndo),
GIMP_UNDO_IMAGE_GRID, undo_desc, GIMP_UNDO_IMAGE_GRID, undo_desc,
GIMP_DIRTY_IMAGE_META, GIMP_DIRTY_IMAGE_META,
undo_pop_image_grid, NULL, NULL,
undo_free_image_grid, "grid", grid,
NULL))) NULL);
{
GridUndo *gu = new->data;
gu->grid = gimp_config_duplicate (GIMP_CONFIG (grid));
return new;
}
return NULL;
}
static gboolean
undo_pop_image_grid (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum)
{
GridUndo *gu = undo->data;
GimpGrid *grid;
grid = gimp_config_duplicate (GIMP_CONFIG (undo->image->grid));
gimp_image_set_grid (undo->image, gu->grid, FALSE);
g_object_unref (gu->grid);
gu->grid = grid;
return TRUE;
}
static void
undo_free_image_grid (GimpUndo *undo,
GimpUndoMode undo_mode)
{
GridUndo *gu = undo->data;
if (gu->grid)
g_object_unref (gu->grid);
g_free (gu);
} }
@ -411,83 +354,18 @@ undo_free_image_sample_point (GimpUndo *undo,
/* Colormap Undo */ /* Colormap Undo */
/*******************/ /*******************/
typedef struct _ColormapUndo ColormapUndo;
struct _ColormapUndo
{
gint num_colors;
guchar *cmap;
};
static gboolean undo_pop_image_colormap (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum);
static void undo_free_image_colormap (GimpUndo *undo,
GimpUndoMode undo_mode);
GimpUndo * GimpUndo *
gimp_image_undo_push_image_colormap (GimpImage *image, gimp_image_undo_push_image_colormap (GimpImage *image,
const gchar *undo_desc) const gchar *undo_desc)
{ {
GimpUndo *new;
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL); g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
if ((new = gimp_image_undo_push (image, GIMP_TYPE_UNDO, return gimp_image_undo_push (image, GIMP_TYPE_IMAGE_UNDO,
sizeof (ColormapUndo), 0, 0,
sizeof (ColormapUndo),
GIMP_UNDO_IMAGE_COLORMAP, undo_desc, GIMP_UNDO_IMAGE_COLORMAP, undo_desc,
GIMP_DIRTY_IMAGE, GIMP_DIRTY_IMAGE,
undo_pop_image_colormap, NULL, NULL,
undo_free_image_colormap, NULL);
NULL)))
{
ColormapUndo *cu = new->data;
cu->num_colors = gimp_image_get_colormap_size (image);
cu->cmap = g_memdup (gimp_image_get_colormap (image),
cu->num_colors * 3);
return new;
}
return NULL;
}
static gboolean
undo_pop_image_colormap (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum)
{
ColormapUndo *cu = undo->data;
guchar *cmap;
gint num_colors;
num_colors = gimp_image_get_colormap_size (undo->image);
cmap = g_memdup (gimp_image_get_colormap (undo->image),
num_colors * 3);
gimp_image_set_colormap (undo->image, cu->cmap, cu->num_colors, FALSE);
if (cu->cmap)
g_free (cu->cmap);
cu->num_colors = num_colors;
cu->cmap = cmap;
return TRUE;
}
static void
undo_free_image_colormap (GimpUndo *undo,
GimpUndoMode undo_mode)
{
ColormapUndo *cu = undo->data;
if (cu->cmap)
g_free (cu->cmap);
g_free (cu);
} }

View File

@ -21,21 +21,42 @@
#include <glib-object.h> #include <glib-object.h>
#include "libgimpbase/gimpbase.h" #include "libgimpbase/gimpbase.h"
#include "libgimpconfig/gimpconfig.h"
#include "core-types.h" #include "core-types.h"
#include "gimpdrawable.h" #include "gimpdrawable.h"
#include "gimpgrid.h"
#include "gimpimage.h" #include "gimpimage.h"
#include "gimpimage-colormap.h"
#include "gimpimage-grid.h"
#include "gimpimageundo.h" #include "gimpimageundo.h"
enum
{
PROP_0,
PROP_GRID
};
static GObject * gimp_image_undo_constructor (GType type, static GObject * gimp_image_undo_constructor (GType type,
guint n_params, guint n_params,
GObjectConstructParam *params); GObjectConstructParam *params);
static void gimp_image_undo_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_image_undo_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_image_undo_pop (GimpUndo *undo, static void gimp_image_undo_pop (GimpUndo *undo,
GimpUndoMode undo_mode, GimpUndoMode undo_mode,
GimpUndoAccumulator *accum); GimpUndoAccumulator *accum);
static void gimp_image_undo_free (GimpUndo *undo,
GimpUndoMode undo_mode);
G_DEFINE_TYPE (GimpImageUndo, gimp_image_undo, GIMP_TYPE_UNDO) G_DEFINE_TYPE (GimpImageUndo, gimp_image_undo, GIMP_TYPE_UNDO)
@ -50,8 +71,17 @@ gimp_image_undo_class_init (GimpImageUndoClass *klass)
GimpUndoClass *undo_class = GIMP_UNDO_CLASS (klass); GimpUndoClass *undo_class = GIMP_UNDO_CLASS (klass);
object_class->constructor = gimp_image_undo_constructor; object_class->constructor = gimp_image_undo_constructor;
object_class->set_property = gimp_image_undo_set_property;
object_class->get_property = gimp_image_undo_get_property;
undo_class->pop = gimp_image_undo_pop; undo_class->pop = gimp_image_undo_pop;
undo_class->free = gimp_image_undo_free;
g_object_class_install_property (object_class, PROP_GRID,
g_param_spec_object ("grid", NULL, NULL,
GIMP_TYPE_GRID,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
} }
static void static void
@ -81,9 +111,70 @@ gimp_image_undo_constructor (GType type,
image_undo->yresolution = image->yresolution; image_undo->yresolution = image->yresolution;
image_undo->resolution_unit = image->resolution_unit; image_undo->resolution_unit = image->resolution_unit;
if (GIMP_UNDO (object)->undo_type == GIMP_UNDO_IMAGE_GRID)
{
g_assert (GIMP_IS_GRID (image_undo->grid));
GIMP_UNDO (object)->size +=
gimp_object_get_memsize (GIMP_OBJECT (image_undo->grid), NULL);
}
else if (GIMP_UNDO (object)->undo_type == GIMP_UNDO_IMAGE_COLORMAP)
{
image_undo->num_colors = gimp_image_get_colormap_size (image);
image_undo->colormap = g_memdup (gimp_image_get_colormap (image),
image_undo->num_colors * 3);
GIMP_UNDO (object)->size += image_undo->num_colors * 3;
}
return object; return object;
} }
static void
gimp_image_undo_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpImageUndo *image_undo = GIMP_IMAGE_UNDO (object);
switch (property_id)
{
case PROP_GRID:
{
GimpGrid *grid = g_value_get_object (value);
if (grid)
image_undo->grid = gimp_config_duplicate (GIMP_CONFIG (grid));
}
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_image_undo_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpImageUndo *image_undo = GIMP_IMAGE_UNDO (object);
switch (property_id)
{
case PROP_GRID:
g_value_set_object (value, image_undo->grid);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void static void
gimp_image_undo_pop (GimpUndo *undo, gimp_image_undo_pop (GimpUndo *undo,
GimpUndoMode undo_mode, GimpUndoMode undo_mode,
@ -159,8 +250,67 @@ gimp_image_undo_pop (GimpUndo *undo,
accum->unit_changed = TRUE; accum->unit_changed = TRUE;
} }
} }
else if (undo->undo_type == GIMP_UNDO_IMAGE_GRID)
{
GimpGrid *grid;
undo->size -= gimp_object_get_memsize (GIMP_OBJECT (image_undo->grid),
NULL);
grid = gimp_config_duplicate (GIMP_CONFIG (undo->image->grid));
gimp_image_set_grid (undo->image, image_undo->grid, FALSE);
g_object_unref (image_undo->grid);
image_undo->grid = grid;
undo->size += gimp_object_get_memsize (GIMP_OBJECT (image_undo->grid),
NULL);
}
else if (undo->undo_type == GIMP_UNDO_IMAGE_COLORMAP)
{
guchar *colormap;
gint num_colors;
undo->size -= image_undo->num_colors * 3;
num_colors = gimp_image_get_colormap_size (undo->image);
colormap = g_memdup (gimp_image_get_colormap (undo->image),
num_colors * 3);
gimp_image_set_colormap (undo->image,
image_undo->colormap, image_undo->num_colors,
FALSE);
if (image_undo->colormap)
g_free (image_undo->colormap);
image_undo->num_colors = num_colors;
image_undo->colormap = colormap;
undo->size += image_undo->num_colors * 3;
}
else else
{ {
g_assert_not_reached (); g_assert_not_reached ();
} }
} }
static void
gimp_image_undo_free (GimpUndo *undo,
GimpUndoMode undo_mode)
{
GimpImageUndo *image_undo = GIMP_IMAGE_UNDO (undo);
if (image_undo->grid)
{
g_object_unref (image_undo->grid);
image_undo->grid = NULL;
}
if (image_undo->colormap)
{
g_free (image_undo->colormap);
image_undo->colormap = NULL;
}
}

View File

@ -43,6 +43,9 @@ struct _GimpImageUndo
gdouble xresolution; gdouble xresolution;
gdouble yresolution; gdouble yresolution;
GimpUnit resolution_unit; GimpUnit resolution_unit;
GimpGrid *grid;
gint num_colors;
guchar *colormap;
}; };
struct _GimpImageUndoClass struct _GimpImageUndoClass