PIKApp/app/core/pikaguide.c

247 lines
6.9 KiB
C
Raw Normal View History

2023-09-26 00:35:21 +02:00
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* PikaGuide
* Copyright (C) 2003 Henrik Brix Andersen <brix@gimp.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (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
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gio/gio.h>
#include "libpikabase/pikabase.h"
#include "libpikaconfig/pikaconfig.h"
#include "core-types.h"
#include "pikaguide.h"
enum
{
PROP_0,
PROP_ORIENTATION,
PROP_POSITION,
PROP_STYLE
};
struct _PikaGuidePrivate
{
PikaOrientationType orientation;
gint position;
PikaGuideStyle style;
};
static void pika_guide_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void pika_guide_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
G_DEFINE_TYPE_WITH_PRIVATE (PikaGuide, pika_guide, PIKA_TYPE_AUX_ITEM)
static void
pika_guide_class_init (PikaGuideClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->get_property = pika_guide_get_property;
object_class->set_property = pika_guide_set_property;
PIKA_CONFIG_PROP_ENUM (object_class, PROP_ORIENTATION,
"orientation",
NULL, NULL,
PIKA_TYPE_ORIENTATION_TYPE,
PIKA_ORIENTATION_UNKNOWN,
0);
PIKA_CONFIG_PROP_INT (object_class, PROP_POSITION,
"position",
NULL, NULL,
PIKA_GUIDE_POSITION_UNDEFINED,
PIKA_MAX_IMAGE_SIZE,
PIKA_GUIDE_POSITION_UNDEFINED,
0);
PIKA_CONFIG_PROP_ENUM (object_class, PROP_STYLE,
"style",
NULL, NULL,
PIKA_TYPE_GUIDE_STYLE,
PIKA_GUIDE_STYLE_NONE,
0);
}
static void
pika_guide_init (PikaGuide *guide)
{
guide->priv = pika_guide_get_instance_private (guide);
}
static void
pika_guide_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
PikaGuide *guide = PIKA_GUIDE (object);
switch (property_id)
{
case PROP_ORIENTATION:
g_value_set_enum (value, guide->priv->orientation);
break;
case PROP_POSITION:
g_value_set_int (value, guide->priv->position);
break;
case PROP_STYLE:
g_value_set_enum (value, guide->priv->style);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
pika_guide_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
PikaGuide *guide = PIKA_GUIDE (object);
switch (property_id)
{
case PROP_ORIENTATION:
guide->priv->orientation = g_value_get_enum (value);
break;
case PROP_POSITION:
guide->priv->position = g_value_get_int (value);
break;
case PROP_STYLE:
guide->priv->style = g_value_get_enum (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
PikaGuide *
pika_guide_new (PikaOrientationType orientation,
guint32 guide_ID)
{
return g_object_new (PIKA_TYPE_GUIDE,
"id", guide_ID,
"orientation", orientation,
"style", PIKA_GUIDE_STYLE_NORMAL,
NULL);
}
/**
* pika_guide_custom_new:
* @orientation: the #PikaOrientationType
* @guide_ID: the unique guide ID
* @guide_style: the #PikaGuideStyle
*
* 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.
* Moreover they don't follow guide snapping settings and never snap.
*
* Returns: the custom #PikaGuide.
**/
PikaGuide *
pika_guide_custom_new (PikaOrientationType orientation,
guint32 guide_ID,
PikaGuideStyle guide_style)
{
return g_object_new (PIKA_TYPE_GUIDE,
"id", guide_ID,
"orientation", orientation,
"style", guide_style,
NULL);
}
PikaOrientationType
pika_guide_get_orientation (PikaGuide *guide)
{
g_return_val_if_fail (PIKA_IS_GUIDE (guide), PIKA_ORIENTATION_UNKNOWN);
return guide->priv->orientation;
}
void
pika_guide_set_orientation (PikaGuide *guide,
PikaOrientationType orientation)
{
g_return_if_fail (PIKA_IS_GUIDE (guide));
guide->priv->orientation = orientation;
g_object_notify (G_OBJECT (guide), "orientation");
}
gint
pika_guide_get_position (PikaGuide *guide)
{
g_return_val_if_fail (PIKA_IS_GUIDE (guide), PIKA_GUIDE_POSITION_UNDEFINED);
return guide->priv->position;
}
void
pika_guide_set_position (PikaGuide *guide,
gint position)
{
g_return_if_fail (PIKA_IS_GUIDE (guide));
guide->priv->position = position;
g_object_notify (G_OBJECT (guide), "position");
}
PikaGuideStyle
pika_guide_get_style (PikaGuide *guide)
{
g_return_val_if_fail (PIKA_IS_GUIDE (guide), PIKA_GUIDE_STYLE_NONE);
return guide->priv->style;
}
gboolean
pika_guide_is_custom (PikaGuide *guide)
{
g_return_val_if_fail (PIKA_IS_GUIDE (guide), FALSE);
return guide->priv->style != PIKA_GUIDE_STYLE_NORMAL;
}