Commit 89ee6f4d authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

app/core/Makefile.am app/core/core-types.h new undo class for

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

	* app/core/Makefile.am
	* app/core/core-types.h
	* app/core/gimpfloatingselundo.[ch]: new undo class for
	GIMP_UNDO_FS_RIGOR and GIMP_UNDO_FS_RELAX.

	* app/core/gimpimage-undo-push.c: use it here.

	* app/core/gimpimageundo.c
	* app/core/gimpdrawableundo.c: implement GimpObject::get_memsize()
	instead of fiddling with undo->size.


svn path=/trunk/; revision=21826
parent 6c01c0db
2007-01-31 Michael Natterer <mitch@gimp.org>
* app/core/Makefile.am
* app/core/core-types.h
* app/core/gimpfloatingselundo.[ch]: new undo class for
GIMP_UNDO_FS_RIGOR and GIMP_UNDO_FS_RELAX.
* app/core/gimpimage-undo-push.c: use it here.
* app/core/gimpimageundo.c
* app/core/gimpdrawableundo.c: implement GimpObject::get_memsize()
instead of fiddling with undo->size.
2007-01-31 Michael Natterer <mitch@gimp.org>
 
* app/vectors/Makefile.am
......@@ -130,6 +130,8 @@ libappcore_a_sources = \
gimpdrawablemodundo.h \
gimpdrawableundo.c \
gimpdrawableundo.h \
gimpfloatingselundo.c \
gimpfloatingselundo.h \
gimpgradient.c \
gimpgradient.h \
gimpgradient-load.c \
......
......@@ -124,6 +124,7 @@ typedef struct _GimpLayerPropUndo GimpLayerPropUndo;
typedef struct _GimpMaskUndo GimpMaskUndo;
typedef struct _GimpGuideUndo GimpGuideUndo;
typedef struct _GimpSamplePointUndo GimpSamplePointUndo;
typedef struct _GimpFloatingSelUndo GimpFloatingSelUndo;
typedef struct _GimpUndoStack GimpUndoStack;
typedef struct _GimpUndoAccumulator GimpUndoAccumulator;
......
......@@ -55,6 +55,9 @@ static void gimp_drawable_undo_get_property (GObject *object,
GValue *value,
GParamSpec *pspec);
static gint64 gimp_drawable_undo_get_memsize (GimpObject *object,
gint64 *gui_size);
static void gimp_drawable_undo_pop (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum);
......@@ -70,15 +73,18 @@ G_DEFINE_TYPE (GimpDrawableUndo, gimp_drawable_undo, GIMP_TYPE_ITEM_UNDO)
static void
gimp_drawable_undo_class_init (GimpDrawableUndoClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpUndoClass *undo_class = GIMP_UNDO_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
GimpUndoClass *undo_class = GIMP_UNDO_CLASS (klass);
object_class->constructor = gimp_drawable_undo_constructor;
object_class->set_property = gimp_drawable_undo_set_property;
object_class->get_property = gimp_drawable_undo_get_property;
object_class->constructor = gimp_drawable_undo_constructor;
object_class->set_property = gimp_drawable_undo_set_property;
object_class->get_property = gimp_drawable_undo_get_property;
gimp_object_class->get_memsize = gimp_drawable_undo_get_memsize;
undo_class->pop = gimp_drawable_undo_pop;
undo_class->free = gimp_drawable_undo_free;
undo_class->pop = gimp_drawable_undo_pop;
undo_class->free = gimp_drawable_undo_free;
g_object_class_install_property (object_class, PROP_TILES,
g_param_spec_pointer ("tiles", NULL, NULL,
......@@ -136,9 +142,6 @@ gimp_drawable_undo_constructor (GType type,
g_assert (GIMP_IS_DRAWABLE (GIMP_ITEM_UNDO (object)->item));
g_assert (drawable_undo->tiles != NULL);
GIMP_UNDO (object)->size += tile_manager_get_memsize (drawable_undo->tiles,
drawable_undo->sparse);
return object;
}
......@@ -212,6 +215,21 @@ gimp_drawable_undo_get_property (GObject *object,
}
}
static gint64
gimp_drawable_undo_get_memsize (GimpObject *object,
gint64 *gui_size)
{
GimpDrawableUndo *drawable_undo = GIMP_DRAWABLE_UNDO (object);
gint64 memsize = 0;
if (drawable_undo->tiles)
memsize += tile_manager_get_memsize (drawable_undo->tiles,
drawable_undo->sparse);
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);
}
static void
gimp_drawable_undo_pop (GimpUndo *undo,
GimpUndoMode undo_mode,
......@@ -221,9 +239,6 @@ gimp_drawable_undo_pop (GimpUndo *undo,
GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
undo->size -= tile_manager_get_memsize (drawable_undo->tiles,
drawable_undo->sparse);
gimp_drawable_swap_pixels (GIMP_DRAWABLE (GIMP_ITEM_UNDO (undo)->item),
drawable_undo->tiles,
drawable_undo->sparse,
......@@ -231,9 +246,6 @@ gimp_drawable_undo_pop (GimpUndo *undo,
drawable_undo->y,
drawable_undo->width,
drawable_undo->height);
undo->size += tile_manager_get_memsize (drawable_undo->tiles,
drawable_undo->sparse);
}
static void
......
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <glib-object.h>
#include "core-types.h"
#include "gimpfloatingselundo.h"
#include "gimplayer.h"
#include "gimplayer-floating-sel.h"
static GObject * gimp_floating_sel_undo_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_floating_sel_undo_pop (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum);
G_DEFINE_TYPE (GimpFloatingSelUndo, gimp_floating_sel_undo, GIMP_TYPE_ITEM_UNDO)
#define parent_class gimp_floating_sel_undo_parent_class
static void
gimp_floating_sel_undo_class_init (GimpFloatingSelUndoClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpUndoClass *undo_class = GIMP_UNDO_CLASS (klass);
object_class->constructor = gimp_floating_sel_undo_constructor;
undo_class->pop = gimp_floating_sel_undo_pop;
}
static void
gimp_floating_sel_undo_init (GimpFloatingSelUndo *undo)
{
}
static GObject *
gimp_floating_sel_undo_constructor (GType type,
guint n_params,
GObjectConstructParam *params)
{
GObject *object;
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
g_assert (GIMP_IS_LAYER (GIMP_ITEM_UNDO (object)->item));
return object;
}
static void
gimp_floating_sel_undo_pop (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum)
{
GimpFloatingSelUndo *floating_sel_undo = GIMP_FLOATING_SEL_UNDO (undo);
GimpLayer *floating_layer = GIMP_LAYER (GIMP_ITEM_UNDO (undo)->item);
if (! gimp_layer_is_floating_sel (floating_layer))
return;
GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
if ((undo_mode == GIMP_UNDO_MODE_UNDO &&
undo->undo_type == GIMP_UNDO_FS_RIGOR) ||
(undo_mode == GIMP_UNDO_MODE_REDO &&
undo->undo_type == GIMP_UNDO_FS_RELAX))
{
floating_sel_relax (floating_layer, FALSE);
}
else
{
floating_sel_rigor (floating_layer, FALSE);
}
}
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_FLOATING_SEL_UNDO_H__
#define __GIMP_FLOATING_SEL_UNDO_H__
#include "gimpitemundo.h"
#define GIMP_TYPE_FLOATING_SEL_UNDO (gimp_floating_sel_undo_get_type ())
#define GIMP_FLOATING_SEL_UNDO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_FLOATING_SEL_UNDO, GimpFloatingSelUndo))
#define GIMP_FLOATING_SEL_UNDO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_FLOATING_SEL_UNDO, GimpFloatingSelUndoClass))
#define GIMP_IS_FLOATING_SEL_UNDO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_FLOATING_SEL_UNDO))
#define GIMP_IS_FLOATING_SEL_UNDO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_FLOATING_SEL_UNDO))
#define GIMP_FLOATING_SEL_UNDO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_FLOATING_SEL_UNDO, GimpFloatingSelUndoClass))
typedef struct _GimpFloatingSelUndoClass GimpFloatingSelUndoClass;
struct _GimpFloatingSelUndo
{
GimpItemUndo parent_instance;
};
struct _GimpFloatingSelUndoClass
{
GimpItemUndoClass parent_class;
};
GType gimp_floating_sel_undo_get_type (void) G_GNUC_CONST;
#endif /* __GIMP_FLOATING_SEL_UNDO_H__ */
......@@ -33,6 +33,7 @@
#include "gimpchannelundo.h"
#include "gimpdrawablemodundo.h"
#include "gimpdrawableundo.h"
#include "gimpfloatingselundo.h"
#include "gimpgrid.h"
#include "gimpguide.h"
#include "gimpguideundo.h"
......@@ -937,123 +938,42 @@ undo_free_fs_to_layer (GimpUndo *undo,
}
/***********************************/
/* Floating Selection Rigor Undo */
/***********************************/
static gboolean undo_pop_fs_rigor (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum);
/******************************************/
/* Floating Selection Rigor/Relax Undos */
/******************************************/
GimpUndo *
gimp_image_undo_push_fs_rigor (GimpImage *image,
const gchar *undo_desc,
GimpLayer *floating_layer)
{
GimpUndo *new;
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
g_return_val_if_fail (GIMP_IS_LAYER (floating_layer), NULL);
if ((new = gimp_image_undo_push (image, GIMP_TYPE_ITEM_UNDO,
0, 0,
GIMP_UNDO_FS_RIGOR, undo_desc,
GIMP_DIRTY_NONE,
undo_pop_fs_rigor,
NULL,
"item", floating_layer,
NULL)))
{
return new;
}
return NULL;
}
static gboolean
undo_pop_fs_rigor (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum)
{
GimpLayer *floating_layer;
floating_layer = GIMP_LAYER (GIMP_ITEM_UNDO (undo)->item);
if (! gimp_layer_is_floating_sel (floating_layer))
return FALSE;
switch (undo_mode)
{
case GIMP_UNDO_MODE_UNDO:
floating_sel_relax (floating_layer, FALSE);
break;
case GIMP_UNDO_MODE_REDO:
floating_sel_rigor (floating_layer, FALSE);
break;
}
return TRUE;
return gimp_image_undo_push (image, GIMP_TYPE_FLOATING_SEL_UNDO,
0, 0,
GIMP_UNDO_FS_RIGOR, undo_desc,
GIMP_DIRTY_NONE,
NULL, NULL,
"item", floating_layer,
NULL);
}
/***********************************/
/* Floating Selection Relax Undo */
/***********************************/
static gboolean undo_pop_fs_relax (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum);
GimpUndo *
gimp_image_undo_push_fs_relax (GimpImage *image,
const gchar *undo_desc,
GimpLayer *floating_layer)
{
GimpUndo *new;
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
g_return_val_if_fail (GIMP_IS_LAYER (floating_layer), NULL);
if ((new = gimp_image_undo_push (image, GIMP_TYPE_ITEM_UNDO,
0, 0,
GIMP_UNDO_FS_RELAX, undo_desc,
GIMP_DIRTY_NONE,
undo_pop_fs_relax,
NULL,
"item", floating_layer,
NULL)))
{
return new;
}
return NULL;
}
static gboolean
undo_pop_fs_relax (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum)
{
GimpLayer *floating_layer;
floating_layer = GIMP_LAYER (GIMP_ITEM_UNDO (undo)->item);
if (! gimp_layer_is_floating_sel (floating_layer))
return FALSE;
switch (undo_mode)
{
case GIMP_UNDO_MODE_UNDO:
floating_sel_rigor (floating_layer, FALSE);
break;
case GIMP_UNDO_MODE_REDO:
floating_sel_relax (floating_layer, FALSE);
break;
}
return TRUE;
return gimp_image_undo_push (image, GIMP_TYPE_FLOATING_SEL_UNDO,
0, 0,
GIMP_UNDO_FS_RELAX, undo_desc,
GIMP_DIRTY_NONE,
NULL, NULL,
"item", floating_layer,
NULL);
}
......
......@@ -20,7 +20,6 @@
#include <glib-object.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpconfig/gimpconfig.h"
#include "core-types.h"
......@@ -52,6 +51,9 @@ static void gimp_image_undo_get_property (GObject *object,
GValue *value,
GParamSpec *pspec);
static gint64 gimp_image_undo_get_memsize (GimpObject *object,
gint64 *gui_size);
static void gimp_image_undo_pop (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum);
......@@ -67,15 +69,18 @@ G_DEFINE_TYPE (GimpImageUndo, gimp_image_undo, GIMP_TYPE_UNDO)
static void
gimp_image_undo_class_init (GimpImageUndoClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpUndoClass *undo_class = GIMP_UNDO_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
GimpUndoClass *undo_class = GIMP_UNDO_CLASS (klass);
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;
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;
gimp_object_class->get_memsize = gimp_image_undo_get_memsize;
undo_class->pop = gimp_image_undo_pop;
undo_class->free = gimp_image_undo_free;
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,
......@@ -123,17 +128,12 @@ gimp_image_undo_constructor (GType type,
case 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);
break;
case 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;
break;
default:
......@@ -188,6 +188,24 @@ gimp_image_undo_get_property (GObject *object,
}
}
static gint64
gimp_image_undo_get_memsize (GimpObject *object,
gint64 *gui_size)
{
GimpImageUndo *image_undo = GIMP_IMAGE_UNDO (object);
gint64 memsize = 0;
if (image_undo->colormap)
memsize += image_undo->num_colors * 3;
if (image_undo->grid)
memsize += gimp_object_get_memsize (GIMP_OBJECT (image_undo->grid),
gui_size);
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);
}
static void
gimp_image_undo_pop (GimpUndo *undo,
GimpUndoMode undo_mode,
......@@ -230,7 +248,8 @@ gimp_image_undo_pop (GimpUndo *undo,
"height", height,
NULL);
gimp_drawable_invalidate_boundary (GIMP_DRAWABLE (gimp_image_get_mask (undo->image)));
gimp_drawable_invalidate_boundary
(GIMP_DRAWABLE (gimp_image_get_mask (undo->image)));
if (undo->image->width != image_undo->width ||
undo->image->height != image_undo->height)
......@@ -273,18 +292,12 @@ gimp_image_undo_pop (GimpUndo *undo,
{
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);
}
break;
......@@ -293,8 +306,6 @@ gimp_image_undo_pop (GimpUndo *undo,
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);
......@@ -308,8 +319,6 @@ gimp_image_undo_pop (GimpUndo *undo,
image_undo->num_colors = num_colors;
image_undo->colormap = colormap;
undo->size += image_undo->num_colors * 3;
}
break;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment