2007-01-30 20:32:14 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2007-01-30 20:32:14 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2007-01-30 20:32:14 +08:00
|
|
|
* (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
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2007-01-30 20:32:14 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2013-10-15 07:58:39 +08:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2007-01-30 20:32:14 +08:00
|
|
|
|
|
|
|
#include "core-types.h"
|
|
|
|
|
|
|
|
#include "gimpimage.h"
|
|
|
|
#include "gimpimage-sample-points.h"
|
|
|
|
#include "gimpsamplepoint.h"
|
|
|
|
#include "gimpsamplepointundo.h"
|
|
|
|
|
|
|
|
|
2011-01-13 05:53:58 +08:00
|
|
|
static void gimp_sample_point_undo_constructed (GObject *object);
|
|
|
|
|
|
|
|
static void gimp_sample_point_undo_pop (GimpUndo *undo,
|
|
|
|
GimpUndoMode undo_mode,
|
|
|
|
GimpUndoAccumulator *accum);
|
2007-01-30 20:32:14 +08:00
|
|
|
|
|
|
|
|
2018-07-15 23:02:56 +08:00
|
|
|
G_DEFINE_TYPE (GimpSamplePointUndo, gimp_sample_point_undo,
|
|
|
|
GIMP_TYPE_AUX_ITEM_UNDO)
|
2007-01-30 20:32:14 +08:00
|
|
|
|
|
|
|
#define parent_class gimp_sample_point_undo_parent_class
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_sample_point_undo_class_init (GimpSamplePointUndoClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpUndoClass *undo_class = GIMP_UNDO_CLASS (klass);
|
|
|
|
|
2018-07-15 23:02:56 +08:00
|
|
|
object_class->constructed = gimp_sample_point_undo_constructed;
|
2007-01-30 20:32:14 +08:00
|
|
|
|
2018-07-15 23:02:56 +08:00
|
|
|
undo_class->pop = gimp_sample_point_undo_pop;
|
2007-01-30 20:32:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_sample_point_undo_init (GimpSamplePointUndo *undo)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-01-13 05:53:58 +08:00
|
|
|
static void
|
|
|
|
gimp_sample_point_undo_constructed (GObject *object)
|
2007-01-30 20:32:14 +08:00
|
|
|
{
|
2011-01-13 05:53:58 +08:00
|
|
|
GimpSamplePointUndo *sample_point_undo = GIMP_SAMPLE_POINT_UNDO (object);
|
2018-07-15 23:02:56 +08:00
|
|
|
GimpSamplePoint *sample_point;
|
2007-01-30 20:32:14 +08:00
|
|
|
|
2012-11-13 04:51:22 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->constructed (object);
|
2007-01-30 20:32:14 +08:00
|
|
|
|
2018-07-15 23:02:56 +08:00
|
|
|
sample_point = GIMP_SAMPLE_POINT (GIMP_AUX_ITEM_UNDO (object)->aux_item);
|
2007-01-30 20:32:14 +08:00
|
|
|
|
2018-07-15 23:02:56 +08:00
|
|
|
gimp_assert (GIMP_IS_SAMPLE_POINT (sample_point));
|
|
|
|
|
|
|
|
gimp_sample_point_get_position (sample_point,
|
2016-01-05 04:13:48 +08:00
|
|
|
&sample_point_undo->x,
|
|
|
|
&sample_point_undo->y);
|
2018-07-16 06:35:33 +08:00
|
|
|
sample_point_undo->pick_mode = gimp_sample_point_get_pick_mode (sample_point);
|
2007-01-30 20:32:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_sample_point_undo_pop (GimpUndo *undo,
|
|
|
|
GimpUndoMode undo_mode,
|
|
|
|
GimpUndoAccumulator *accum)
|
|
|
|
{
|
|
|
|
GimpSamplePointUndo *sample_point_undo = GIMP_SAMPLE_POINT_UNDO (undo);
|
2018-07-15 23:02:56 +08:00
|
|
|
GimpSamplePoint *sample_point;
|
2007-01-30 20:32:14 +08:00
|
|
|
gint x;
|
|
|
|
gint y;
|
2018-07-16 06:35:33 +08:00
|
|
|
GimpColorPickMode pick_mode;
|
2007-01-30 20:32:14 +08:00
|
|
|
|
|
|
|
GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
|
|
|
|
|
2018-07-15 23:02:56 +08:00
|
|
|
sample_point = GIMP_SAMPLE_POINT (GIMP_AUX_ITEM_UNDO (undo)->aux_item);
|
|
|
|
|
|
|
|
gimp_sample_point_get_position (sample_point, &x, &y);
|
2018-07-16 06:35:33 +08:00
|
|
|
pick_mode = gimp_sample_point_get_pick_mode (sample_point);
|
2007-01-30 20:32:14 +08:00
|
|
|
|
2018-07-15 21:58:24 +08:00
|
|
|
if (x == GIMP_SAMPLE_POINT_POSITION_UNDEFINED)
|
2007-01-30 20:32:14 +08:00
|
|
|
{
|
2010-02-05 23:14:04 +08:00
|
|
|
gimp_image_add_sample_point (undo->image,
|
2018-07-15 23:02:56 +08:00
|
|
|
sample_point,
|
2010-02-05 23:14:04 +08:00
|
|
|
sample_point_undo->x,
|
|
|
|
sample_point_undo->y);
|
2007-01-30 20:32:14 +08:00
|
|
|
}
|
2018-07-15 21:58:24 +08:00
|
|
|
else if (sample_point_undo->x == GIMP_SAMPLE_POINT_POSITION_UNDEFINED)
|
2007-01-30 20:32:14 +08:00
|
|
|
{
|
2018-07-15 23:02:56 +08:00
|
|
|
gimp_image_remove_sample_point (undo->image, sample_point, FALSE);
|
2007-01-30 20:32:14 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-15 23:02:56 +08:00
|
|
|
gimp_sample_point_set_position (sample_point,
|
2016-01-05 04:13:48 +08:00
|
|
|
sample_point_undo->x,
|
|
|
|
sample_point_undo->y);
|
2018-07-16 06:35:33 +08:00
|
|
|
gimp_sample_point_set_pick_mode (sample_point,
|
|
|
|
sample_point_undo->pick_mode);
|
2010-10-01 15:15:52 +08:00
|
|
|
|
2018-07-15 23:02:56 +08:00
|
|
|
gimp_image_sample_point_moved (undo->image, sample_point);
|
2007-01-30 20:32:14 +08:00
|
|
|
}
|
|
|
|
|
2018-07-16 06:35:33 +08:00
|
|
|
sample_point_undo->x = x;
|
|
|
|
sample_point_undo->y = y;
|
|
|
|
sample_point_undo->pick_mode = pick_mode;
|
2007-01-30 20:32:14 +08:00
|
|
|
}
|