mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-07-03 17:33:25 +00:00
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:
parent
9a7de0552d
commit
c757ac1534
4 changed files with 189 additions and 150 deletions
|
@ -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>
|
||||
|
||||
* app/core/gimpimage-undo-push.[ch]: return a GimpUndo* instead
|
||||
|
|
|
@ -35,8 +35,6 @@
|
|||
#include "gimpgrid.h"
|
||||
#include "gimpguide.h"
|
||||
#include "gimpimage.h"
|
||||
#include "gimpimage-colormap.h"
|
||||
#include "gimpimage-grid.h"
|
||||
#include "gimpimage-guides.h"
|
||||
#include "gimpimage-sample-points.h"
|
||||
#include "gimpimage-undo.h"
|
||||
|
@ -225,76 +223,21 @@ undo_free_image_guide (GimpUndo *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 *
|
||||
gimp_image_undo_push_image_grid (GimpImage *image,
|
||||
const gchar *undo_desc,
|
||||
GimpGrid *grid)
|
||||
{
|
||||
GimpUndo *new;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
||||
g_return_val_if_fail (GIMP_IS_GRID (grid), NULL);
|
||||
|
||||
if ((new = gimp_image_undo_push (image, GIMP_TYPE_UNDO,
|
||||
sizeof (GridUndo),
|
||||
sizeof (GridUndo),
|
||||
GIMP_UNDO_IMAGE_GRID, undo_desc,
|
||||
GIMP_DIRTY_IMAGE_META,
|
||||
undo_pop_image_grid,
|
||||
undo_free_image_grid,
|
||||
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);
|
||||
return gimp_image_undo_push (image, GIMP_TYPE_IMAGE_UNDO,
|
||||
0, 0,
|
||||
GIMP_UNDO_IMAGE_GRID, undo_desc,
|
||||
GIMP_DIRTY_IMAGE_META,
|
||||
NULL, NULL,
|
||||
"grid", grid,
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
||||
|
@ -411,83 +354,18 @@ undo_free_image_sample_point (GimpUndo *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 *
|
||||
gimp_image_undo_push_image_colormap (GimpImage *image,
|
||||
const gchar *undo_desc)
|
||||
{
|
||||
GimpUndo *new;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
||||
|
||||
if ((new = gimp_image_undo_push (image, GIMP_TYPE_UNDO,
|
||||
sizeof (ColormapUndo),
|
||||
sizeof (ColormapUndo),
|
||||
GIMP_UNDO_IMAGE_COLORMAP, undo_desc,
|
||||
GIMP_DIRTY_IMAGE,
|
||||
undo_pop_image_colormap,
|
||||
undo_free_image_colormap,
|
||||
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);
|
||||
return gimp_image_undo_push (image, GIMP_TYPE_IMAGE_UNDO,
|
||||
0, 0,
|
||||
GIMP_UNDO_IMAGE_COLORMAP, undo_desc,
|
||||
GIMP_DIRTY_IMAGE,
|
||||
NULL, NULL,
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -21,21 +21,42 @@
|
|||
#include <glib-object.h>
|
||||
|
||||
#include "libgimpbase/gimpbase.h"
|
||||
#include "libgimpconfig/gimpconfig.h"
|
||||
|
||||
#include "core-types.h"
|
||||
|
||||
#include "gimpdrawable.h"
|
||||
#include "gimpgrid.h"
|
||||
#include "gimpimage.h"
|
||||
#include "gimpimage-colormap.h"
|
||||
#include "gimpimage-grid.h"
|
||||
#include "gimpimageundo.h"
|
||||
|
||||
|
||||
static GObject * gimp_image_undo_constructor (GType type,
|
||||
guint n_params,
|
||||
GObjectConstructParam *params);
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_GRID
|
||||
};
|
||||
|
||||
static void gimp_image_undo_pop (GimpUndo *undo,
|
||||
GimpUndoMode undo_mode,
|
||||
GimpUndoAccumulator *accum);
|
||||
|
||||
static GObject * gimp_image_undo_constructor (GType type,
|
||||
guint n_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,
|
||||
GimpUndoMode undo_mode,
|
||||
GimpUndoAccumulator *accum);
|
||||
static void gimp_image_undo_free (GimpUndo *undo,
|
||||
GimpUndoMode undo_mode);
|
||||
|
||||
|
||||
G_DEFINE_TYPE (GimpImageUndo, gimp_image_undo, GIMP_TYPE_UNDO)
|
||||
|
@ -49,9 +70,18 @@ gimp_image_undo_class_init (GimpImageUndoClass *klass)
|
|||
GObjectClass *object_class = G_OBJECT_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
|
||||
|
@ -81,9 +111,70 @@ gimp_image_undo_constructor (GType type,
|
|||
image_undo->yresolution = image->yresolution;
|
||||
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;
|
||||
}
|
||||
|
||||
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
|
||||
gimp_image_undo_pop (GimpUndo *undo,
|
||||
GimpUndoMode undo_mode,
|
||||
|
@ -159,8 +250,67 @@ gimp_image_undo_pop (GimpUndo *undo,
|
|||
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
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,14 +35,17 @@ typedef struct _GimpImageUndoClass GimpImageUndoClass;
|
|||
|
||||
struct _GimpImageUndo
|
||||
{
|
||||
GimpUndo parent_instance;
|
||||
GimpUndo parent_instance;
|
||||
|
||||
GimpImageBaseType base_type;
|
||||
gint width;
|
||||
gint height;
|
||||
gdouble xresolution;
|
||||
gdouble yresolution;
|
||||
GimpUnit resolution_unit;
|
||||
GimpImageBaseType base_type;
|
||||
gint width;
|
||||
gint height;
|
||||
gdouble xresolution;
|
||||
gdouble yresolution;
|
||||
GimpUnit resolution_unit;
|
||||
GimpGrid *grid;
|
||||
gint num_colors;
|
||||
guchar *colormap;
|
||||
};
|
||||
|
||||
struct _GimpImageUndoClass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue