Commit 2cd829eb authored by Michael Natterer's avatar Michael Natterer 😴

app: add GimpAuxItem as base class for GimpGuide and GimpSamplePoint

and GimpAuxItemUndo for their respective undo classes.
parent b4c244b8
......@@ -91,6 +91,10 @@ libappcore_a_sources = \
gimpasync.h \
gimpasyncset.c \
gimpasyncset.h \
gimpauxitem.c \
gimpauxitem.h \
gimpauxitemundo.c \
gimpauxitemundo.h \
gimpbezierdesc.h \
gimpbezierdesc.c \
gimpboundary.c \
......
......@@ -91,6 +91,7 @@ typedef struct _GimpObject GimpObject;
typedef struct _GimpViewable GimpViewable;
typedef struct _GimpFilter GimpFilter;
typedef struct _GimpItem GimpItem;
typedef struct _GimpAuxItem GimpAuxItem;
typedef struct _Gimp Gimp;
typedef struct _GimpImage GimpImage;
......@@ -161,6 +162,12 @@ typedef struct _GimpLayer GimpLayer;
typedef struct _GimpGroupLayer GimpGroupLayer;
/* auxillary image items */
typedef struct _GimpGuide GimpGuide;
typedef struct _GimpSamplePoint GimpSamplePoint;
/* undo objects */
typedef struct _GimpUndo GimpUndo;
......@@ -185,7 +192,6 @@ typedef struct _GimpDrawableFilter GimpDrawableFilter;
typedef struct _GimpEnvironTable GimpEnvironTable;
typedef struct _GimpExtension GimpExtension;
typedef struct _GimpExtensionManager GimpExtensionManager;
typedef struct _GimpGuide GimpGuide;
typedef struct _GimpHistogram GimpHistogram;
typedef struct _GimpIdTable GimpIdTable;
typedef struct _GimpImagefile GimpImagefile;
......@@ -194,7 +200,6 @@ typedef struct _GimpObjectQueue GimpObjectQueue;
typedef struct _GimpParasiteList GimpParasiteList;
typedef struct _GimpPdbProgress GimpPdbProgress;
typedef struct _GimpProjection GimpProjection;
typedef struct _GimpSamplePoint GimpSamplePoint;
typedef struct _GimpSettings GimpSettings;
typedef struct _GimpSubProgress GimpSubProgress;
typedef struct _GimpTag GimpTag;
......
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 <glib-object.h>
#include "core-types.h"
#include "gimpauxitem.h"
enum
{
REMOVED,
LAST_SIGNAL
};
enum
{
PROP_0,
PROP_ID
};
struct _GimpAuxItemPrivate
{
guint32 aux_item_ID;
};
static void gimp_aux_item_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_aux_item_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
G_DEFINE_ABSTRACT_TYPE (GimpAuxItem, gimp_aux_item, G_TYPE_OBJECT)
static guint gimp_aux_item_signals[LAST_SIGNAL] = { 0 };
static void
gimp_aux_item_class_init (GimpAuxItemClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
gimp_aux_item_signals[REMOVED] =
g_signal_new ("removed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpAuxItemClass, removed),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
object_class->get_property = gimp_aux_item_get_property;
object_class->set_property = gimp_aux_item_set_property;
klass->removed = NULL;
g_object_class_install_property (object_class, PROP_ID,
g_param_spec_uint ("id", NULL, NULL,
0, G_MAXUINT32, 0,
G_PARAM_CONSTRUCT_ONLY |
GIMP_PARAM_READWRITE));
g_type_class_add_private (klass, sizeof (GimpAuxItemPrivate));
}
static void
gimp_aux_item_init (GimpAuxItem *aux_item)
{
aux_item->priv = G_TYPE_INSTANCE_GET_PRIVATE (aux_item,
GIMP_TYPE_AUX_ITEM,
GimpAuxItemPrivate);
}
static void
gimp_aux_item_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpAuxItem *aux_item = GIMP_AUX_ITEM (object);
switch (property_id)
{
case PROP_ID:
g_value_set_uint (value, aux_item->priv->aux_item_ID);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_aux_item_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpAuxItem *aux_item = GIMP_AUX_ITEM (object);
switch (property_id)
{
case PROP_ID:
aux_item->priv->aux_item_ID = g_value_get_uint (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
guint32
gimp_aux_item_get_ID (GimpAuxItem *aux_item)
{
g_return_val_if_fail (GIMP_IS_AUX_ITEM (aux_item), 0);
return aux_item->priv->aux_item_ID;
}
void
gimp_aux_item_removed (GimpAuxItem *aux_item)
{
g_return_if_fail (GIMP_IS_AUX_ITEM (aux_item));
g_signal_emit (aux_item, gimp_aux_item_signals[REMOVED], 0);
}
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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/>.
*/
#ifndef __GIMP_AUX_ITEM_H__
#define __GIMP_AUX_ITEM_H__
#define GIMP_TYPE_AUX_ITEM (gimp_aux_item_get_type ())
#define GIMP_AUX_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_AUX_ITEM, GimpAuxItem))
#define GIMP_AUX_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_AUX_ITEM, GimpAuxItemClass))
#define GIMP_IS_AUX_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_AUX_ITEM))
#define GIMP_IS_AUX_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_AUX_ITEM))
#define GIMP_AUX_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_AUX_ITEM, GimpAuxItemClass))
typedef struct _GimpAuxItemPrivate GimpAuxItemPrivate;
typedef struct _GimpAuxItemClass GimpAuxItemClass;
struct _GimpAuxItem
{
GObject parent_instance;
GimpAuxItemPrivate *priv;
};
struct _GimpAuxItemClass
{
GObjectClass parent_class;
/* signals */
void (* removed) (GimpAuxItem *aux_item);
};
GType gimp_aux_item_get_type (void) G_GNUC_CONST;
guint32 gimp_aux_item_get_ID (GimpAuxItem *aux_item);
void gimp_aux_item_removed (GimpAuxItem *aux_item);
#endif /* __GIMP_AUX_ITEM_H__ */
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 <gdk-pixbuf/gdk-pixbuf.h>
#include <gegl.h>
#include "core-types.h"
#include "gimpauxitem.h"
#include "gimpauxitemundo.h"
enum
{
PROP_0,
PROP_AUX_ITEM
};
static void gimp_aux_item_undo_constructed (GObject *object);
static void gimp_aux_item_undo_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_aux_item_undo_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_aux_item_undo_free (GimpUndo *undo,
GimpUndoMode undo_mode);
G_DEFINE_ABSTRACT_TYPE (GimpAuxItemUndo, gimp_aux_item_undo, GIMP_TYPE_UNDO)
#define parent_class gimp_aux_item_undo_parent_class
static void
gimp_aux_item_undo_class_init (GimpAuxItemUndoClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpUndoClass *undo_class = GIMP_UNDO_CLASS (klass);
object_class->constructed = gimp_aux_item_undo_constructed;
object_class->set_property = gimp_aux_item_undo_set_property;
object_class->get_property = gimp_aux_item_undo_get_property;
undo_class->free = gimp_aux_item_undo_free;
g_object_class_install_property (object_class, PROP_AUX_ITEM,
g_param_spec_object ("aux-item", NULL, NULL,
GIMP_TYPE_AUX_ITEM,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
}
static void
gimp_aux_item_undo_init (GimpAuxItemUndo *undo)
{
}
static void
gimp_aux_item_undo_constructed (GObject *object)
{
GimpAuxItemUndo *aux_item_undo = GIMP_AUX_ITEM_UNDO (object);
G_OBJECT_CLASS (parent_class)->constructed (object);
gimp_assert (GIMP_IS_AUX_ITEM (aux_item_undo->aux_item));
}
static void
gimp_aux_item_undo_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpAuxItemUndo *aux_item_undo = GIMP_AUX_ITEM_UNDO (object);
switch (property_id)
{
case PROP_AUX_ITEM:
aux_item_undo->aux_item = g_value_dup_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_aux_item_undo_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpAuxItemUndo *aux_item_undo = GIMP_AUX_ITEM_UNDO (object);
switch (property_id)
{
case PROP_AUX_ITEM:
g_value_set_object (value, aux_item_undo->aux_item);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_aux_item_undo_free (GimpUndo *undo,
GimpUndoMode undo_mode)
{
GimpAuxItemUndo *aux_item_undo = GIMP_AUX_ITEM_UNDO (undo);
g_clear_object (&aux_item_undo->aux_item);
GIMP_UNDO_CLASS (parent_class)->free (undo, undo_mode);
}
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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/>.
*/
#ifndef __GIMP_AUX_ITEM_UNDO_H__
#define __GIMP_AUX_ITEM_UNDO_H__
#include "gimpundo.h"
#define GIMP_TYPE_AUX_ITEM_UNDO (gimp_aux_item_undo_get_type ())
#define GIMP_AUX_ITEM_UNDO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_AUX_ITEM_UNDO, GimpAuxItemUndo))
#define GIMP_AUX_ITEM_UNDO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_AUX_ITEM_UNDO, GimpAuxItemUndoClass))
#define GIMP_IS_AUX_ITEM_UNDO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_AUX_ITEM_UNDO))
#define GIMP_IS_AUX_ITEM_UNDO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_AUX_ITEM_UNDO))
#define GIMP_AUX_ITEM_UNDO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_AUX_ITEM_UNDO, GimpAuxItemUndoClass))
typedef struct _GimpAuxItemUndo GimpAuxItemUndo;
typedef struct _GimpAuxItemUndoClass GimpAuxItemUndoClass;
struct _GimpAuxItemUndo
{
GimpUndo parent_instance;
GimpAuxItem *aux_item;
};
struct _GimpAuxItemUndoClass
{
GimpUndoClass parent_class;
};
GType gimp_aux_item_undo_get_type (void) G_GNUC_CONST;
#endif /* __GIMP_AUX_ITEM_UNDO_H__ */
......@@ -20,31 +20,19 @@
#include "config.h"
#include <cairo.h>
#include <gegl.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gio/gio.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpcolor/gimpcolor.h"
#include "libgimpconfig/gimpconfig.h"
#include "core-types.h"
#include "gimpguide.h"
#include "gimpmarshal.h"
enum
{
REMOVED,
LAST_SIGNAL
};
enum
{
PROP_0,
PROP_ID,
PROP_ORIENTATION,
PROP_POSITION,
PROP_STYLE
......@@ -53,7 +41,6 @@ enum
struct _GimpGuidePrivate
{
guint32 guide_ID;
GimpOrientationType orientation;
gint position;
......@@ -71,9 +58,7 @@ static void gimp_guide_set_property (GObject *object,
GParamSpec *pspec);
G_DEFINE_TYPE (GimpGuide, gimp_guide, G_TYPE_OBJECT)
static guint gimp_guide_signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE (GimpGuide, gimp_guide, GIMP_TYPE_AUX_ITEM)
static void
......@@ -81,26 +66,9 @@ gimp_guide_class_init (GimpGuideClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
gimp_guide_signals[REMOVED] =
g_signal_new ("removed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpGuideClass, removed),
NULL, NULL,
gimp_marshal_VOID__VOID,
G_TYPE_NONE, 0);
object_class->get_property = gimp_guide_get_property;
object_class->set_property = gimp_guide_set_property;
klass->removed = NULL;
g_object_class_install_property (object_class, PROP_ID,
g_param_spec_uint ("id", NULL, NULL,
0, G_MAXUINT32, 0,
G_PARAM_CONSTRUCT_ONLY |
GIMP_PARAM_READWRITE));
GIMP_CONFIG_PROP_ENUM (object_class, PROP_ORIENTATION,
"orientation",
NULL, NULL,
......@@ -143,9 +111,6 @@ gimp_guide_get_property (GObject *object,
switch (property_id)
{
case PROP_ID:
g_value_set_uint (value, guide->priv->guide_ID);
break;
case PROP_ORIENTATION:
g_value_set_enum (value, guide->priv->orientation);
break;
......@@ -171,9 +136,6 @@ gimp_guide_set_property (GObject *object,
switch (property_id)
{
case PROP_ID:
guide->priv->guide_ID = g_value_get_uint (value);
break;
case PROP_ORIENTATION:
guide->priv->orientation = g_value_get_enum (value);
break;
......@@ -232,22 +194,6 @@ gimp_guide_custom_new (GimpOrientationType orientation,
return guide;
}
guint32
gimp_guide_get_ID (GimpGuide *guide)
{
g_return_val_if_fail (GIMP_IS_GUIDE (guide), 0);
return guide->priv->guide_ID;
}
void
gimp_guide_removed (GimpGuide *guide)
{
g_return_if_fail (GIMP_IS_GUIDE (guide));
g_signal_emit (guide, gimp_guide_signals[REMOVED], 0);
}
GimpOrientationType
gimp_guide_get_orientation (GimpGuide *guide)
{
......
......@@ -22,6 +22,9 @@
#define __GIMP_GUIDE_H__
#include "gimpauxitem.h"
#define GIMP_GUIDE_POSITION_UNDEFINED G_MININT
......@@ -38,17 +41,14 @@ typedef struct _GimpGuideClass GimpGuideClass;
struct _GimpGuide
{
GObject parent_instance;
GimpAuxItem parent_instance;
GimpGuidePrivate *priv;
};
struct _GimpGuideClass
{
GObjectClass parent_class;
/* signals */
void (* removed) (GimpGuide *guide);
GimpAuxItemClass parent_class;
};
......@@ -60,10 +60,6 @@ GimpGuide * gimp_guide_custom_new (GimpOrientationType orientatio
guint32 guide_ID,
GimpGuideStyle guide_style);
guint32 gimp_guide_get_ID (GimpGuide *guide);
void gimp_guide_removed (GimpGuide *guide);
GimpOrientationType gimp_guide_get_orientation (GimpGuide *guide);
void gimp_guide_set_orientation (GimpGuide *guide,
GimpOrientationType orientation);
......
......@@ -28,31 +28,15 @@
#include "gimpguideundo.h"
enum
{
PROP_0,
PROP_GUIDE
};
static void gimp_guide_undo_constructed (GObject *object);
static void gimp_guide_undo_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_guide_undo_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_guide_undo_pop (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum);
static void gimp_guide_undo_free (GimpUndo *undo,
GimpUndoMode undo_mode);
G_DEFINE_TYPE (GimpGuideUndo, gimp_guide_undo, GIMP_TYPE_UNDO)
G_DEFINE_TYPE (GimpGuideUndo, gimp_guide_undo,
GIMP_TYPE_AUX_ITEM_UNDO)
#define parent_class gimp_guide_undo_parent_class
......@@ -63,18 +47,9 @@ gimp_guide_undo_class_init (GimpGuideUndoClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpUndoClass *undo_class = GIMP_UNDO_CLASS (klass);
object_class->constructed = gimp_guide_undo_constructed;
object_class->set_property = gimp_guide_undo_set_property;
object_class->get_property = gimp_guide_undo_get_property;
undo_class->pop = gimp_guide_undo_pop;
undo_class->free = gimp_guide_undo_free;
object_class->constructed = gimp_guide_undo_constructed;
g_object_class_install_property (object_class, PROP_GUIDE,
g_param_spec_object ("guide", NULL, NULL,
GIMP_TYPE_GUIDE,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
undo_class->pop = gimp_guide_undo_pop;
}
static void
......@@ -86,53 +61,16 @@ static void
gimp_guide_undo_constructed (GObject *object)
{
GimpGuideUndo *guide_undo = GIMP_GUIDE_UNDO (object);
GimpGuide *guide;
G_OBJECT_CLASS (parent_class)->constructed (object);
gimp_assert (GIMP_IS_GUIDE (guide_undo->guide));
guide_undo->orientation = gimp_guide_get_orientation (guide_undo->guide);
guide_undo->position = gimp_guide_get_position (guide_undo->guide);
}
static void
gimp_guide_undo_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpGuideUndo *guide_undo = GIMP_GUIDE_UNDO (object);
switch (property_id)
{
case PROP_GUIDE:
guide_undo->guide = g_value_dup_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_guide_undo_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpGuideUndo *guide_undo = GIMP_GUIDE_UNDO (object);
guide = GIMP_GUIDE (GIMP_AUX_ITEM_UNDO (object)->aux_item);
switch (property_id)
{
case PROP_GUIDE:
g_value_set_object (value, guide_undo->guide);
break;
gimp_assert (GIMP_IS_GUIDE (guide));
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
guide_undo->orientation = gimp_guide_get_orientation (guide);
guide_undo->position = gimp_guide_get_position (guide);
}
static void
......@@ -141,47 +79,38 @@ gimp_guide_undo_pop (GimpUndo *undo,
GimpUndoAccumulator *accum)
{
GimpGuideUndo *guide_undo = GIMP_GUIDE_UNDO (undo);
GimpGuide *guide;
GimpOrientationType orientation;
gint position;
gboolean moved = FALSE;
GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
orientation = gimp_guide_get_orientation (guide_undo->guide);
position = gimp_guide_get_position (guide_undo->guide);
guide = GIMP_GUIDE (GIMP_AUX_ITEM_UNDO (undo)->aux_item);
orientation = gimp_guide_get_orientation (guide);
position = gimp_guide_get_position (guide);
if (position == GIMP_GUIDE_POSITION_UNDEFINED)
{
gimp_image_add_guide (undo->image,
guide_undo->guide, guide_undo->position);
gimp_image_add_guide (undo->image, guide, guide_undo->position);
}
else if (guide_undo->position == GIMP_GUIDE_POSITION_UNDEFINED)
{
gimp_image_remove_guide (undo->image, guide_undo->guide, FALSE);
gimp_image_remove_guide (undo->image, guide, FALSE);
}
else
{
gimp_guide_set_position (guide_undo->guide, guide_undo->position);
gimp_guide_set_position (guide, guide_undo->position);
moved = TRUE;
}