1
/* The GIMP -- an 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.
23
#include <glib-object.h>
25
#include "paint-types.h"
27
#include "core/gimpimage-undo.h"
28
#include "core/gimpimage.h"
29
#include "core/gimpundo.h"
32
#include "gimpink-blob.h"
33
#include "gimpink-undo.h"
40
typedef struct _InkUndo InkUndo;
48
gdouble dt_buffer[DIST_SMOOTHER_BUFFER];
51
guint32 ts_buffer[TIME_SMOOTHER_BUFFER];
56
gboolean init_velocity;
60
static gboolean undo_pop_ink (GimpUndo *undo,
61
GimpUndoMode undo_mode,
62
GimpUndoAccumulator *accum);
63
static void undo_free_ink (GimpUndo *undo,
64
GimpUndoMode undo_mode);
68
gimp_ink_push_undo (GimpPaintCore *core,
70
const gchar *undo_desc)
74
g_return_val_if_fail (GIMP_IS_INK (core), FALSE);
75
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
77
if (! GIMP_PAINT_CORE_CLASS (g_type_class_peek_parent (GIMP_INK_GET_CLASS (core)))->push_undo (core, gimage, undo_desc))
80
if ((new = gimp_image_undo_push (gimage, GIMP_TYPE_UNDO,
83
GIMP_UNDO_INK, undo_desc,
89
GimpInk *ink = GIMP_INK (core);
90
InkUndo *ink_undo = new->data;
95
ink_undo->last_blob = blob_duplicate (ink->start_blob);
97
memcpy (ink_undo->dt_buffer, ink->dt_buffer,
98
sizeof (ink_undo->dt_buffer));
100
ink_undo->dt_index = ink->dt_index;
102
memcpy (ink_undo->ts_buffer, ink->ts_buffer,
103
sizeof (ink_undo->ts_buffer));
105
ink_undo->ts_index = ink->ts_index;
107
ink_undo->last_time = ink->last_time;
109
ink_undo->init_velocity = ink->init_velocity;
111
g_object_add_weak_pointer (G_OBJECT (ink), (gpointer) &ink_undo->ink);
120
undo_pop_ink (GimpUndo *undo,
121
GimpUndoMode undo_mode,
122
GimpUndoAccumulator *accum)
124
InkUndo *ink_undo = undo->data;
126
/* only pop if the core still exists */
132
guint32 tmp_int_buf[DIST_SMOOTHER_BUFFER];
133
gdouble tmp_double_buf[DIST_SMOOTHER_BUFFER];
135
tmp_blob = ink_undo->ink->last_blob;
136
ink_undo->ink->last_blob = ink_undo->last_blob;
137
ink_undo->last_blob = tmp_blob;
139
memcpy (tmp_double_buf, ink_undo->ink->dt_buffer,
140
sizeof (tmp_double_buf));
141
memcpy (ink_undo->ink->dt_buffer, ink_undo->dt_buffer,
142
sizeof (tmp_double_buf));
143
memcpy (ink_undo->dt_buffer, tmp_double_buf,
144
sizeof (tmp_double_buf));
146
tmp_int = ink_undo->ink->dt_index;
147
ink_undo->ink->dt_index = ink_undo->dt_index;
148
ink_undo->dt_index = tmp_int;
150
memcpy (tmp_int_buf, ink_undo->ink->ts_buffer,
151
sizeof (tmp_int_buf));
152
memcpy (ink_undo->ink->ts_buffer, ink_undo->ts_buffer,
153
sizeof (tmp_int_buf));
154
memcpy (ink_undo->ts_buffer, tmp_int_buf,
155
sizeof (tmp_int_buf));
157
tmp_int = ink_undo->ink->ts_index;
158
ink_undo->ink->ts_index = ink_undo->ts_index;
159
ink_undo->ts_index = tmp_int;
161
tmp_double = ink_undo->ink->last_time;
162
ink_undo->ink->last_time = ink_undo->last_time;
163
ink_undo->last_time = tmp_double;
165
tmp_int = ink_undo->ink->init_velocity;
166
ink_undo->ink->init_velocity = ink_undo->init_velocity;
167
ink_undo->init_velocity = tmp_int;
174
undo_free_ink (GimpUndo *undo,
175
GimpUndoMode undo_mode)
177
InkUndo *ink_undo = undo->data;
180
g_object_remove_weak_pointer (G_OBJECT (ink_undo->ink),
181
(gpointer) &ink_undo->ink);
183
if (ink_undo->last_blob)
184
g_free (ink_undo->last_blob);