1
/* GIMP - The GNU Image Manipulation Program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
#include <glib-object.h>
23
#include "core-types.h"
25
#include "base/tile-manager.h"
27
#include "gimpimage.h"
28
#include "gimpdrawable.h"
29
#include "gimpdrawablemodundo.h"
32
static GObject * gimp_drawable_mod_undo_constructor (GType type,
34
GObjectConstructParam *params);
36
static gint64 gimp_drawable_mod_undo_get_memsize (GimpObject *object,
39
static void gimp_drawable_mod_undo_pop (GimpUndo *undo,
40
GimpUndoMode undo_mode,
41
GimpUndoAccumulator *accum);
42
static void gimp_drawable_mod_undo_free (GimpUndo *undo,
43
GimpUndoMode undo_mode);
46
G_DEFINE_TYPE (GimpDrawableModUndo, gimp_drawable_mod_undo, GIMP_TYPE_ITEM_UNDO)
48
#define parent_class gimp_drawable_mod_undo_parent_class
52
gimp_drawable_mod_undo_class_init (GimpDrawableModUndoClass *klass)
54
GObjectClass *object_class = G_OBJECT_CLASS (klass);
55
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
56
GimpUndoClass *undo_class = GIMP_UNDO_CLASS (klass);
58
object_class->constructor = gimp_drawable_mod_undo_constructor;
60
gimp_object_class->get_memsize = gimp_drawable_mod_undo_get_memsize;
62
undo_class->pop = gimp_drawable_mod_undo_pop;
63
undo_class->free = gimp_drawable_mod_undo_free;
67
gimp_drawable_mod_undo_init (GimpDrawableModUndo *undo)
72
gimp_drawable_mod_undo_constructor (GType type,
74
GObjectConstructParam *params)
77
GimpDrawableModUndo *drawable_mod_undo;
78
GimpDrawable *drawable;
80
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
82
drawable_mod_undo = GIMP_DRAWABLE_MOD_UNDO (object);
84
g_assert (GIMP_IS_DRAWABLE (GIMP_ITEM_UNDO (object)->item));
86
drawable = GIMP_DRAWABLE (GIMP_ITEM_UNDO (object)->item);
88
drawable_mod_undo->tiles = tile_manager_ref (drawable->tiles);
89
drawable_mod_undo->type = drawable->type;
90
drawable_mod_undo->offset_x = GIMP_ITEM (drawable)->offset_x;
91
drawable_mod_undo->offset_y = GIMP_ITEM (drawable)->offset_y;
97
gimp_drawable_mod_undo_get_memsize (GimpObject *object,
100
GimpDrawableModUndo *drawable_mod_undo = GIMP_DRAWABLE_MOD_UNDO (object);
103
if (drawable_mod_undo->tiles)
104
memsize += tile_manager_get_memsize (drawable_mod_undo->tiles, FALSE);
106
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
111
gimp_drawable_mod_undo_pop (GimpUndo *undo,
112
GimpUndoMode undo_mode,
113
GimpUndoAccumulator *accum)
115
GimpDrawableModUndo *drawable_mod_undo = GIMP_DRAWABLE_MOD_UNDO (undo);
116
GimpDrawable *drawable = GIMP_DRAWABLE (GIMP_ITEM_UNDO (undo)->item);
119
gint offset_x, offset_y;
121
GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
123
tiles = drawable_mod_undo->tiles;
124
type = drawable_mod_undo->type;
125
offset_x = drawable_mod_undo->offset_x;
126
offset_y = drawable_mod_undo->offset_y;
128
drawable_mod_undo->tiles = tile_manager_ref (drawable->tiles);
129
drawable_mod_undo->type = drawable->type;
130
drawable_mod_undo->offset_x = GIMP_ITEM (drawable)->offset_x;
131
drawable_mod_undo->offset_y = GIMP_ITEM (drawable)->offset_y;
133
gimp_drawable_set_tiles_full (drawable, FALSE, NULL,
134
tiles, type, offset_x, offset_y);
135
tile_manager_unref (tiles);
139
gimp_drawable_mod_undo_free (GimpUndo *undo,
140
GimpUndoMode undo_mode)
142
GimpDrawableModUndo *drawable_mod_undo = GIMP_DRAWABLE_MOD_UNDO (undo);
144
if (drawable_mod_undo->tiles)
146
tile_manager_unref (drawable_mod_undo->tiles);
147
drawable_mod_undo->tiles = NULL;
150
GIMP_UNDO_CLASS (parent_class)->free (undo, undo_mode);