2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2006-06-07 06:48:57 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* GimpGuide
|
|
|
|
* Copyright (C) 2003 Henrik Brix Andersen <brix@gimp.org>
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2006-06-07 06:48:57 +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
|
2006-06-07 06:48:57 +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/>.
|
2006-06-07 06:48:57 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2013-10-15 07:58:39 +08:00
|
|
|
#include <gio/gio.h>
|
2006-06-07 06:48:57 +08:00
|
|
|
|
|
|
|
#include "libgimpbase/gimpbase.h"
|
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
|
|
|
|
|
|
|
#include "core-types.h"
|
|
|
|
|
|
|
|
#include "gimpguide.h"
|
|
|
|
|
2016-02-03 21:29:23 +08:00
|
|
|
|
2006-06-07 06:48:57 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_ORIENTATION,
|
2015-12-15 09:54:04 +08:00
|
|
|
PROP_POSITION,
|
2016-02-04 02:38:32 +08:00
|
|
|
PROP_STYLE
|
2006-06-07 06:48:57 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-07-10 06:20:57 +08:00
|
|
|
struct _GimpGuidePrivate
|
|
|
|
{
|
|
|
|
GimpOrientationType orientation;
|
|
|
|
gint position;
|
2015-12-15 09:54:04 +08:00
|
|
|
|
2016-02-04 02:38:32 +08:00
|
|
|
GimpGuideStyle style;
|
2014-07-10 06:20:57 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-06-07 06:48:57 +08:00
|
|
|
static void gimp_guide_get_property (GObject *object,
|
2006-06-07 23:49:59 +08:00
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2006-06-07 06:48:57 +08:00
|
|
|
static void gimp_guide_set_property (GObject *object,
|
2006-06-07 23:49:59 +08:00
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2006-06-07 06:48:57 +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 (GimpGuide, gimp_guide, GIMP_TYPE_AUX_ITEM)
|
2006-06-08 04:13:51 +08:00
|
|
|
|
2006-06-07 06:48:57 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_guide_class_init (GimpGuideClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->get_property = gimp_guide_get_property;
|
|
|
|
object_class->set_property = gimp_guide_set_property;
|
|
|
|
|
2016-02-12 06:44:07 +08:00
|
|
|
GIMP_CONFIG_PROP_ENUM (object_class, PROP_ORIENTATION,
|
|
|
|
"orientation",
|
|
|
|
NULL, NULL,
|
|
|
|
GIMP_TYPE_ORIENTATION_TYPE,
|
|
|
|
GIMP_ORIENTATION_UNKNOWN,
|
|
|
|
0);
|
|
|
|
|
|
|
|
GIMP_CONFIG_PROP_INT (object_class, PROP_POSITION,
|
|
|
|
"position",
|
|
|
|
NULL, NULL,
|
|
|
|
GIMP_GUIDE_POSITION_UNDEFINED,
|
|
|
|
GIMP_MAX_IMAGE_SIZE,
|
|
|
|
GIMP_GUIDE_POSITION_UNDEFINED,
|
|
|
|
0);
|
|
|
|
|
|
|
|
GIMP_CONFIG_PROP_ENUM (object_class, PROP_STYLE,
|
|
|
|
"style",
|
|
|
|
NULL, NULL,
|
|
|
|
GIMP_TYPE_GUIDE_STYLE,
|
|
|
|
GIMP_GUIDE_STYLE_NONE,
|
|
|
|
0);
|
2006-06-07 06:48:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_guide_init (GimpGuide *guide)
|
|
|
|
{
|
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
|
|
|
guide->priv = gimp_guide_get_instance_private (guide);
|
2006-06-07 06:48:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-07-15 21:51:40 +08:00
|
|
|
gimp_guide_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2006-06-07 06:48:57 +08:00
|
|
|
{
|
|
|
|
GimpGuide *guide = GIMP_GUIDE (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_ORIENTATION:
|
2014-07-10 06:20:57 +08:00
|
|
|
g_value_set_enum (value, guide->priv->orientation);
|
2006-06-07 06:48:57 +08:00
|
|
|
break;
|
2006-06-07 15:57:24 +08:00
|
|
|
case PROP_POSITION:
|
2014-07-10 06:20:57 +08:00
|
|
|
g_value_set_int (value, guide->priv->position);
|
2006-06-07 06:48:57 +08:00
|
|
|
break;
|
2016-02-04 02:38:32 +08:00
|
|
|
case PROP_STYLE:
|
|
|
|
g_value_set_enum (value, guide->priv->style);
|
2015-12-15 09:54:04 +08:00
|
|
|
break;
|
2006-06-07 06:48:57 +08:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_guide_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpGuide *guide = GIMP_GUIDE (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_ORIENTATION:
|
2014-07-10 06:20:57 +08:00
|
|
|
guide->priv->orientation = g_value_get_enum (value);
|
2006-06-07 06:48:57 +08:00
|
|
|
break;
|
2006-06-07 15:57:24 +08:00
|
|
|
case PROP_POSITION:
|
2014-07-10 06:20:57 +08:00
|
|
|
guide->priv->position = g_value_get_int (value);
|
2006-06-07 06:48:57 +08:00
|
|
|
break;
|
2016-02-04 02:38:32 +08:00
|
|
|
case PROP_STYLE:
|
|
|
|
guide->priv->style = g_value_get_enum (value);
|
2015-12-15 09:54:04 +08:00
|
|
|
break;
|
2006-06-07 06:48:57 +08:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-07 15:45:16 +08:00
|
|
|
GimpGuide *
|
|
|
|
gimp_guide_new (GimpOrientationType orientation,
|
|
|
|
guint32 guide_ID)
|
|
|
|
{
|
|
|
|
return g_object_new (GIMP_TYPE_GUIDE,
|
2016-02-04 02:38:32 +08:00
|
|
|
"id", guide_ID,
|
|
|
|
"orientation", orientation,
|
|
|
|
"style", GIMP_GUIDE_STYLE_NORMAL,
|
2006-06-07 15:45:16 +08:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2015-12-15 09:54:04 +08:00
|
|
|
/**
|
|
|
|
* gimp_guide_custom_new:
|
|
|
|
* @orientation: the #GimpOrientationType
|
|
|
|
* @guide_ID: the unique guide ID
|
2016-02-04 02:38:32 +08:00
|
|
|
* @guide_style: the #GimpGuideStyle
|
2015-12-15 09:54:04 +08:00
|
|
|
*
|
|
|
|
* This function returns a new guide and will flag it as "custom".
|
|
|
|
* Custom guides are used for purpose "other" than the basic guides
|
|
|
|
* a user can create oneself, for instance as symmetry guides, to
|
|
|
|
* drive GEGL ops, etc.
|
|
|
|
* They are not saved in the XCF file. If an op, a symmetry or a plugin
|
|
|
|
* wishes to save its state, it has to do it internally.
|
2016-02-12 00:40:45 +08:00
|
|
|
* Moreover they don't follow guide snapping settings and never snap.
|
2015-12-15 09:54:04 +08:00
|
|
|
*
|
|
|
|
* Returns: the custom #GimpGuide.
|
|
|
|
**/
|
|
|
|
GimpGuide *
|
|
|
|
gimp_guide_custom_new (GimpOrientationType orientation,
|
|
|
|
guint32 guide_ID,
|
2016-02-04 02:38:32 +08:00
|
|
|
GimpGuideStyle guide_style)
|
2015-12-15 09:54:04 +08:00
|
|
|
{
|
2018-07-16 04:25:03 +08:00
|
|
|
return g_object_new (GIMP_TYPE_GUIDE,
|
|
|
|
"id", guide_ID,
|
|
|
|
"orientation", orientation,
|
|
|
|
"style", guide_style,
|
|
|
|
NULL);
|
2015-12-15 09:54:04 +08:00
|
|
|
}
|
|
|
|
|
2006-06-07 15:57:24 +08:00
|
|
|
GimpOrientationType
|
|
|
|
gimp_guide_get_orientation (GimpGuide *guide)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_GUIDE (guide), GIMP_ORIENTATION_UNKNOWN);
|
|
|
|
|
2014-07-10 06:20:57 +08:00
|
|
|
return guide->priv->orientation;
|
2006-06-07 15:57:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_guide_set_orientation (GimpGuide *guide,
|
|
|
|
GimpOrientationType orientation)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_GUIDE (guide));
|
|
|
|
|
2014-07-10 06:20:57 +08:00
|
|
|
guide->priv->orientation = orientation;
|
2006-06-07 15:57:24 +08:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (guide), "orientation");
|
|
|
|
}
|
|
|
|
|
2006-06-07 06:48:57 +08:00
|
|
|
gint
|
|
|
|
gimp_guide_get_position (GimpGuide *guide)
|
|
|
|
{
|
2014-07-10 06:20:57 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_GUIDE (guide), GIMP_GUIDE_POSITION_UNDEFINED);
|
2006-06-07 06:48:57 +08:00
|
|
|
|
2014-07-10 06:20:57 +08:00
|
|
|
return guide->priv->position;
|
2006-06-07 06:48:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_guide_set_position (GimpGuide *guide,
|
|
|
|
gint position)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_GUIDE (guide));
|
|
|
|
|
2014-07-10 06:20:57 +08:00
|
|
|
guide->priv->position = position;
|
2006-06-07 15:45:16 +08:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (guide), "position");
|
2006-06-07 06:48:57 +08:00
|
|
|
}
|
2006-06-08 04:13:51 +08:00
|
|
|
|
2016-02-04 02:38:32 +08:00
|
|
|
GimpGuideStyle
|
|
|
|
gimp_guide_get_style (GimpGuide *guide)
|
2015-12-15 09:54:04 +08:00
|
|
|
{
|
2016-04-04 02:31:10 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_GUIDE (guide), GIMP_GUIDE_STYLE_NONE);
|
|
|
|
|
2016-02-04 02:38:32 +08:00
|
|
|
return guide->priv->style;
|
2015-12-15 09:54:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gimp_guide_is_custom (GimpGuide *guide)
|
|
|
|
{
|
2016-04-04 02:31:10 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_GUIDE (guide), FALSE);
|
|
|
|
|
|
|
|
return guide->priv->style != GIMP_GUIDE_STYLE_NORMAL;
|
2015-12-15 09:54:04 +08:00
|
|
|
}
|