2007-01-30 18:34:59 +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 18:34:59 +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 18:34:59 +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 18:34:59 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2018-07-15 21:58:24 +08:00
|
|
|
#include <gio/gio.h>
|
|
|
|
|
|
|
|
#include "libgimpbase/gimpbase.h"
|
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
2007-01-30 18:34:59 +08:00
|
|
|
|
|
|
|
#include "core-types.h"
|
|
|
|
|
|
|
|
#include "gimpsamplepoint.h"
|
|
|
|
|
|
|
|
|
2018-07-15 21:58:24 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_POSITION_X,
|
2018-07-16 06:35:33 +08:00
|
|
|
PROP_POSITION_Y,
|
|
|
|
PROP_PICK_MODE
|
2018-07-15 21:58:24 +08:00
|
|
|
};
|
2007-01-30 18:34:59 +08:00
|
|
|
|
|
|
|
|
2018-07-15 21:58:24 +08:00
|
|
|
struct _GimpSamplePointPrivate
|
2007-01-30 18:34:59 +08:00
|
|
|
{
|
2018-07-16 06:35:33 +08:00
|
|
|
gint position_x;
|
|
|
|
gint position_y;
|
|
|
|
GimpColorPickMode pick_mode;
|
2018-07-15 21:58:24 +08:00
|
|
|
};
|
2007-01-30 18:34:59 +08:00
|
|
|
|
|
|
|
|
2018-07-15 21:58:24 +08:00
|
|
|
static void gimp_sample_point_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_sample_point_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2007-01-30 18:34:59 +08:00
|
|
|
|
|
|
|
|
app, libgimp*, modules: don't use g_type_class_add_private() ...
... and G_TYPE_INSTANCE_GET_PRIVATE()
g_type_class_add_private() and G_TYPE_INSTANCE_GET_PRIVATE() were
deprecated in GLib 2.58. Instead, use
G_DEFINE_[ABSTRACT_]TYPE_WITH_PRIVATE(), and
G_ADD_PRIVATE[_DYNAMIC](), and the implictly-defined
foo_get_instance_private() functions, all of which are available in
the GLib versions we depend on.
This commit only covers types registered using one of the
G_DEFINE_FOO() macros (i.e., most types), but not types with a
custom registration function, of which we still have a few -- GLib
currently only provides a (non-deprecated) public API for adding a
private struct using the G_DEFINE_FOO() macros.
Note that this commit was 99% auto-generated (because I'm not
*that* crazy :), so if there are any style mismatches... we'll have
to live with them for now.
2018-09-19 00:09:39 +08:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GimpSamplePoint, gimp_sample_point,
|
|
|
|
GIMP_TYPE_AUX_ITEM)
|
2007-01-30 18:34:59 +08:00
|
|
|
|
|
|
|
|
2018-07-15 21:58:24 +08:00
|
|
|
static void
|
|
|
|
gimp_sample_point_class_init (GimpSamplePointClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->get_property = gimp_sample_point_get_property;
|
|
|
|
object_class->set_property = gimp_sample_point_set_property;
|
|
|
|
|
|
|
|
GIMP_CONFIG_PROP_INT (object_class, PROP_POSITION_X,
|
|
|
|
"position-x",
|
|
|
|
NULL, NULL,
|
|
|
|
GIMP_SAMPLE_POINT_POSITION_UNDEFINED,
|
|
|
|
GIMP_MAX_IMAGE_SIZE,
|
|
|
|
GIMP_SAMPLE_POINT_POSITION_UNDEFINED,
|
|
|
|
0);
|
|
|
|
|
|
|
|
GIMP_CONFIG_PROP_INT (object_class, PROP_POSITION_Y,
|
|
|
|
"position-y",
|
|
|
|
NULL, NULL,
|
|
|
|
GIMP_SAMPLE_POINT_POSITION_UNDEFINED,
|
|
|
|
GIMP_MAX_IMAGE_SIZE,
|
|
|
|
GIMP_SAMPLE_POINT_POSITION_UNDEFINED,
|
|
|
|
0);
|
|
|
|
|
2018-07-16 06:35:33 +08:00
|
|
|
GIMP_CONFIG_PROP_ENUM (object_class, PROP_PICK_MODE,
|
|
|
|
"pick-mode",
|
|
|
|
NULL, NULL,
|
|
|
|
GIMP_TYPE_COLOR_PICK_MODE,
|
|
|
|
GIMP_COLOR_PICK_MODE_PIXEL,
|
|
|
|
0);
|
2007-01-30 18:34:59 +08:00
|
|
|
}
|
|
|
|
|
2018-07-15 21:58:24 +08:00
|
|
|
static void
|
|
|
|
gimp_sample_point_init (GimpSamplePoint *sample_point)
|
|
|
|
{
|
app, libgimp*, modules: don't use g_type_class_add_private() ...
... and G_TYPE_INSTANCE_GET_PRIVATE()
g_type_class_add_private() and G_TYPE_INSTANCE_GET_PRIVATE() were
deprecated in GLib 2.58. Instead, use
G_DEFINE_[ABSTRACT_]TYPE_WITH_PRIVATE(), and
G_ADD_PRIVATE[_DYNAMIC](), and the implictly-defined
foo_get_instance_private() functions, all of which are available in
the GLib versions we depend on.
This commit only covers types registered using one of the
G_DEFINE_FOO() macros (i.e., most types), but not types with a
custom registration function, of which we still have a few -- GLib
currently only provides a (non-deprecated) public API for adding a
private struct using the G_DEFINE_FOO() macros.
Note that this commit was 99% auto-generated (because I'm not
*that* crazy :), so if there are any style mismatches... we'll have
to live with them for now.
2018-09-19 00:09:39 +08:00
|
|
|
sample_point->priv = gimp_sample_point_get_instance_private (sample_point);
|
2018-07-15 21:58:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_sample_point_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2007-01-30 18:34:59 +08:00
|
|
|
{
|
2018-07-15 21:58:24 +08:00
|
|
|
GimpSamplePoint *sample_point = GIMP_SAMPLE_POINT (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_POSITION_X:
|
|
|
|
g_value_set_int (value, sample_point->priv->position_x);
|
|
|
|
break;
|
|
|
|
case PROP_POSITION_Y:
|
|
|
|
g_value_set_int (value, sample_point->priv->position_y);
|
|
|
|
break;
|
2018-07-16 06:35:33 +08:00
|
|
|
case PROP_PICK_MODE:
|
|
|
|
g_value_set_enum (value, sample_point->priv->pick_mode);
|
|
|
|
break;
|
2018-07-15 21:58:24 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-01-30 18:34:59 +08:00
|
|
|
|
2018-07-15 21:58:24 +08:00
|
|
|
static void
|
|
|
|
gimp_sample_point_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpSamplePoint *sample_point = GIMP_SAMPLE_POINT (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_POSITION_X:
|
|
|
|
sample_point->priv->position_x = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case PROP_POSITION_Y:
|
|
|
|
sample_point->priv->position_y = g_value_get_int (value);
|
|
|
|
break;
|
2018-07-16 06:35:33 +08:00
|
|
|
case PROP_PICK_MODE:
|
|
|
|
sample_point->priv->pick_mode = g_value_get_enum (value);
|
|
|
|
break;
|
2018-07-15 21:58:24 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-01-30 18:34:59 +08:00
|
|
|
|
2018-07-15 21:58:24 +08:00
|
|
|
GimpSamplePoint *
|
|
|
|
gimp_sample_point_new (guint32 sample_point_ID)
|
|
|
|
{
|
|
|
|
return g_object_new (GIMP_TYPE_SAMPLE_POINT,
|
|
|
|
"id", sample_point_ID,
|
|
|
|
NULL);
|
2007-01-30 18:34:59 +08:00
|
|
|
}
|
2016-01-05 04:13:48 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
gimp_sample_point_get_position (GimpSamplePoint *sample_point,
|
|
|
|
gint *position_x,
|
|
|
|
gint *position_y)
|
|
|
|
{
|
2018-07-15 21:58:24 +08:00
|
|
|
g_return_if_fail (GIMP_IS_SAMPLE_POINT (sample_point));
|
2016-01-05 04:13:48 +08:00
|
|
|
g_return_if_fail (position_x != NULL);
|
|
|
|
g_return_if_fail (position_y != NULL);
|
|
|
|
|
2018-07-15 21:58:24 +08:00
|
|
|
*position_x = sample_point->priv->position_x;
|
|
|
|
*position_y = sample_point->priv->position_y;
|
2016-01-05 04:13:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_sample_point_set_position (GimpSamplePoint *sample_point,
|
|
|
|
gint position_x,
|
|
|
|
gint position_y)
|
|
|
|
{
|
2018-07-15 21:58:24 +08:00
|
|
|
g_return_if_fail (GIMP_IS_SAMPLE_POINT (sample_point));
|
|
|
|
|
2018-07-16 06:35:33 +08:00
|
|
|
if (sample_point->priv->position_x != position_x ||
|
|
|
|
sample_point->priv->position_y != position_y)
|
|
|
|
{
|
|
|
|
sample_point->priv->position_x = position_x;
|
|
|
|
sample_point->priv->position_y = position_y;
|
|
|
|
|
|
|
|
g_object_freeze_notify (G_OBJECT (sample_point));
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (sample_point), "position-x");
|
|
|
|
g_object_notify (G_OBJECT (sample_point), "position-y");
|
|
|
|
|
|
|
|
g_object_thaw_notify (G_OBJECT (sample_point));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GimpColorPickMode
|
|
|
|
gimp_sample_point_get_pick_mode (GimpSamplePoint *sample_point)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_SAMPLE_POINT (sample_point),
|
|
|
|
GIMP_COLOR_PICK_MODE_PIXEL);
|
2018-07-15 21:58:24 +08:00
|
|
|
|
2018-07-16 06:35:33 +08:00
|
|
|
return sample_point->priv->pick_mode;
|
|
|
|
}
|
2018-07-15 21:58:24 +08:00
|
|
|
|
2018-07-16 06:35:33 +08:00
|
|
|
void
|
|
|
|
gimp_sample_point_set_pick_mode (GimpSamplePoint *sample_point,
|
|
|
|
GimpColorPickMode pick_mode)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_SAMPLE_POINT (sample_point));
|
|
|
|
|
|
|
|
if (sample_point->priv->pick_mode != pick_mode)
|
|
|
|
{
|
|
|
|
sample_point->priv->pick_mode = pick_mode;
|
2016-01-05 04:13:48 +08:00
|
|
|
|
2018-07-16 06:35:33 +08:00
|
|
|
g_object_notify (G_OBJECT (sample_point), "pick-mode");
|
|
|
|
}
|
2016-01-05 04:13:48 +08:00
|
|
|
}
|