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 "gimpimage.h"
26
#include "gimpimage-sample-points.h"
27
#include "gimpsamplepoint.h"
28
#include "gimpsamplepointundo.h"
38
static GObject * gimp_sample_point_undo_constructor (GType type,
40
GObjectConstructParam *params);
41
static void gimp_sample_point_undo_set_property (GObject *object,
45
static void gimp_sample_point_undo_get_property (GObject *object,
50
static void gimp_sample_point_undo_pop (GimpUndo *undo,
51
GimpUndoMode undo_mode,
52
GimpUndoAccumulator *accum);
53
static void gimp_sample_point_undo_free (GimpUndo *undo,
54
GimpUndoMode undo_mode);
57
G_DEFINE_TYPE (GimpSamplePointUndo, gimp_sample_point_undo, GIMP_TYPE_UNDO)
59
#define parent_class gimp_sample_point_undo_parent_class
63
gimp_sample_point_undo_class_init (GimpSamplePointUndoClass *klass)
65
GObjectClass *object_class = G_OBJECT_CLASS (klass);
66
GimpUndoClass *undo_class = GIMP_UNDO_CLASS (klass);
68
object_class->constructor = gimp_sample_point_undo_constructor;
69
object_class->set_property = gimp_sample_point_undo_set_property;
70
object_class->get_property = gimp_sample_point_undo_get_property;
72
undo_class->pop = gimp_sample_point_undo_pop;
73
undo_class->free = gimp_sample_point_undo_free;
75
g_object_class_install_property (object_class, PROP_SAMPLE_POINT,
76
g_param_spec_boxed ("sample-point", NULL, NULL,
77
GIMP_TYPE_SAMPLE_POINT,
78
GIMP_PARAM_READWRITE |
79
G_PARAM_CONSTRUCT_ONLY));
83
gimp_sample_point_undo_init (GimpSamplePointUndo *undo)
88
gimp_sample_point_undo_constructor (GType type,
90
GObjectConstructParam *params)
93
GimpSamplePointUndo *sample_point_undo;
95
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
97
sample_point_undo = GIMP_SAMPLE_POINT_UNDO (object);
99
g_assert (sample_point_undo->sample_point != NULL);
101
sample_point_undo->x = sample_point_undo->sample_point->x;
102
sample_point_undo->y = sample_point_undo->sample_point->y;
108
gimp_sample_point_undo_set_property (GObject *object,
113
GimpSamplePointUndo *sample_point_undo = GIMP_SAMPLE_POINT_UNDO (object);
117
case PROP_SAMPLE_POINT:
118
sample_point_undo->sample_point = g_value_dup_boxed (value);
122
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
128
gimp_sample_point_undo_get_property (GObject *object,
133
GimpSamplePointUndo *sample_point_undo = GIMP_SAMPLE_POINT_UNDO (object);
137
case PROP_SAMPLE_POINT:
138
g_value_set_boxed (value, sample_point_undo->sample_point);
142
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
148
gimp_sample_point_undo_pop (GimpUndo *undo,
149
GimpUndoMode undo_mode,
150
GimpUndoAccumulator *accum)
152
GimpSamplePointUndo *sample_point_undo = GIMP_SAMPLE_POINT_UNDO (undo);
156
GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
158
x = sample_point_undo->sample_point->x;
159
y = sample_point_undo->sample_point->y;
161
/* add and move sample points manually (nor using the
162
* gimp_image_sample_point API), because we might be in the middle
163
* of an image resizing undo group and the sample point's position
164
* might be temporarily out of image.
169
undo->image->sample_points =
170
g_list_append (undo->image->sample_points,
171
sample_point_undo->sample_point);
173
sample_point_undo->sample_point->x = sample_point_undo->x;
174
sample_point_undo->sample_point->y = sample_point_undo->y;
175
gimp_sample_point_ref (sample_point_undo->sample_point);
177
gimp_image_sample_point_added (undo->image,
178
sample_point_undo->sample_point);
179
gimp_image_update_sample_point (undo->image,
180
sample_point_undo->sample_point);
182
else if (sample_point_undo->x == -1)
184
gimp_image_remove_sample_point (undo->image,
185
sample_point_undo->sample_point, FALSE);
189
gimp_image_update_sample_point (undo->image,
190
sample_point_undo->sample_point);
191
sample_point_undo->sample_point->x = sample_point_undo->x;
192
sample_point_undo->sample_point->y = sample_point_undo->y;
193
gimp_image_update_sample_point (undo->image,
194
sample_point_undo->sample_point);
197
sample_point_undo->x = x;
198
sample_point_undo->y = y;
202
gimp_sample_point_undo_free (GimpUndo *undo,
203
GimpUndoMode undo_mode)
205
GimpSamplePointUndo *sample_point_undo = GIMP_SAMPLE_POINT_UNDO (undo);
207
if (sample_point_undo->sample_point)
209
gimp_sample_point_unref (sample_point_undo->sample_point);
210
sample_point_undo->sample_point = NULL;
213
GIMP_UNDO_CLASS (parent_class)->free (undo, undo_mode);