Bill Skaggs <weskaggs@primate.ucdavis.edu>

* app/core/gimpguide.c
	* app/core/gimpguide.h: new files, implementing GuideGimp as a GimpObject

	* app/core/Makefile.am: add new files as sources

	* app/core/gimpimage-guides.h
	* app/core/gimpimage-guides.c: use the new object instead of defining
	GimpGuide here as a struct.

	* app/core/gimpimage-crop.c
	* app/core/gimpimage-duplicate.c
	* app/core/gimpimage-flip.c
	* app/core/gimpimage-resize.c
	* app/core/gimpimage-rotate.c
	* app/core/gimpimage-scale.c
	* app/core/gimpimage-snap.c
	* app/core/gimpimage-undo-push.c
	* app/core/gimpimage.c
	* app/display/gimpdisplayshell-draw.c
	* app/display/gimpdisplayshell.c
	* app/pdb/guides_cmds.c
	* app/tools/gimpmovetool.c
	* app/xcf/xcf-save.c
	* tools/pdbgen/pdb/guides.pdb: include "core/gimpguide.h", and use
	g_object_ref/unref instead of gimp_image_guide_ref/unref.
This commit is contained in:
William Skaggs 2006-06-06 22:48:57 +00:00
parent 09c605e28f
commit a49cc445b8
21 changed files with 288 additions and 49 deletions

View File

@ -1,3 +1,31 @@
2006-06-07 Bill Skaggs <weskaggs@primate.ucdavis.edu>
* app/core/gimpguide.c
* app/core/gimpguide.h: new files, implementing GuideGimp as a GimpObject
* app/core/Makefile.am: add new files as sources
* app/core/gimpimage-guides.h
* app/core/gimpimage-guides.c: use the new object instead of defining
GimpGuide here as a struct.
* app/core/gimpimage-crop.c
* app/core/gimpimage-duplicate.c
* app/core/gimpimage-flip.c
* app/core/gimpimage-resize.c
* app/core/gimpimage-rotate.c
* app/core/gimpimage-scale.c
* app/core/gimpimage-snap.c
* app/core/gimpimage-undo-push.c
* app/core/gimpimage.c
* app/display/gimpdisplayshell-draw.c
* app/display/gimpdisplayshell.c
* app/pdb/guides_cmds.c
* app/tools/gimpmovetool.c
* app/xcf/xcf-save.c
* tools/pdbgen/pdb/guides.pdb: include "core/gimpguide.h", and use
g_object_ref/unref instead of gimp_image_guide_ref/unref.
2006-06-07 Sven Neumann <sven@gimp.org>
* app/tools/gimprectangletool.c (gimp_rectangle_tool_initialize):

View File

@ -120,6 +120,8 @@ libappcore_a_sources = \
gimpgradient-save.h \
gimpgrid.c \
gimpgrid.h \
gimpguide.c \
gimpguide.h \
gimpimage.c \
gimpimage.h \
gimpimage-colorhash.c \

167
app/core/gimpguide.c Normal file
View File

@ -0,0 +1,167 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* GimpGuide
* 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 2 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <string.h> /* strcmp */
#include <glib-object.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpbase/gimplimits.h"
#include "libgimpconfig/gimpconfig.h"
#include "core-types.h"
#include "gimpguide.h"
#include "gimp-intl.h"
enum
{
PROP_0,
PROP_POSITION,
PROP_ORIENTATION,
PROP_ID
};
static void gimp_guide_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_guide_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
G_DEFINE_TYPE (GimpGuide, gimp_guide, GIMP_TYPE_OBJECT)
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;
GIMP_CONFIG_INSTALL_PROP_INT (object_class, PROP_POSITION,
"position",
N_("Offset of the guide."),
-1,
GIMP_MAX_IMAGE_SIZE, -1,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_ORIENTATION,
"orientation",
N_("Orientation of the guide."),
GIMP_TYPE_ORIENTATION_TYPE,
GIMP_ORIENTATION_VERTICAL,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_INSTALL_PROP_INT (object_class, PROP_ID,
"guide-id",
N_("Identifying number for the guide."),
0,
G_MAXINT, 0,
GIMP_PARAM_STATIC_STRINGS);
}
static void
gimp_guide_init (GimpGuide *guide)
{
}
static void
gimp_guide_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpGuide *guide = GIMP_GUIDE (object);
switch (property_id)
{
case PROP_POSITION:
g_value_set_int (value, guide->position);
break;
case PROP_ORIENTATION:
g_value_set_enum (value, guide->orientation);
break;
case PROP_ID:
g_value_set_int (value, guide->guide_ID);
break;
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_POSITION:
guide->position = g_value_get_int (value);
break;
case PROP_ORIENTATION:
guide->orientation = g_value_get_enum (value);
break;
case PROP_ID:
guide->guide_ID = g_value_get_int (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
gint
gimp_guide_get_position (GimpGuide *guide)
{
g_return_val_if_fail (GIMP_IS_GUIDE (guide), 0);
return guide->position;
}
void
gimp_guide_set_position (GimpGuide *guide,
gint position)
{
g_return_if_fail (GIMP_IS_GUIDE (guide));
guide->position = position;
}
GimpOrientationType
gimp_guide_get_orientation (GimpGuide *guide)
{
g_return_val_if_fail (GIMP_IS_GUIDE (guide), 0);
return guide->orientation;
}

62
app/core/gimpguide.h Normal file
View File

@ -0,0 +1,62 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* GimpGuide
* 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 2 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_GUIDE_H__
#define __GIMP_GUIDE_H__
#include "gimpobject.h"
#define GIMP_TYPE_GUIDE (gimp_guide_get_type ())
#define GIMP_GUIDE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_GUIDE, GimpGuide))
#define GIMP_GUIDE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_GUIDE, GimpGuideClass))
#define GIMP_IS_GUIDE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_GUIDE))
#define GIMP_IS_GUIDE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_GUIDE))
#define GIMP_GUIDE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_GUIDE, GimpGuideClass))
typedef struct _GimpGuideClass GimpGuideClass;
struct _GimpGuide
{
GimpObject parent_instance;
gint position;
GimpOrientationType orientation;
guint32 guide_ID;
};
struct _GimpGuideClass
{
GimpObjectClass parent_class;
};
GType gimp_guide_get_type (void) G_GNUC_CONST;
gint gimp_guide_get_position (GimpGuide *guide);
void gimp_guide_set_position (GimpGuide *guide,
gint position);
GimpOrientationType gimp_guide_get_orientation (GimpGuide *guide);
#endif /* __GIMP_GUIDE_H__ */

View File

@ -28,6 +28,7 @@
#include "gimp.h"
#include "gimpcontext.h"
#include "gimpguide.h"
#include "gimpimage.h"
#include "gimpimage-crop.h"
#include "gimpimage-guides.h"

View File

@ -28,6 +28,7 @@
#include "gimp.h"
#include "gimpchannel.h"
#include "gimpguide.h"
#include "gimpimage.h"
#include "gimpimage-colormap.h"
#include "gimpimage-duplicate.h"

View File

@ -24,6 +24,7 @@
#include "gimp.h"
#include "gimpcontext.h"
#include "gimpguide.h"
#include "gimpimage.h"
#include "gimpimage-flip.h"
#include "gimpimage-guides.h"

View File

@ -24,6 +24,7 @@
#include "gimp.h"
#include "gimpimage.h"
#include "gimpguide.h"
#include "gimpimage-guides.h"
#include "gimpimage-undo-push.h"
@ -42,9 +43,8 @@ gimp_image_add_hguide (GimpImage *image,
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
g_return_val_if_fail (position >= 0 && position <= image->height, NULL);
guide = g_new0 (GimpGuide, 1);
guide = g_object_new (GIMP_TYPE_GUIDE, NULL);
guide->ref_count = 1;
guide->position = -1;
guide->orientation = GIMP_ORIENTATION_HORIZONTAL;
guide->guide_ID = image->gimp->next_guide_ID++;
@ -54,7 +54,7 @@ gimp_image_add_hguide (GimpImage *image,
guide);
gimp_image_add_guide (image, guide, position);
gimp_image_guide_unref (guide);
g_object_unref (G_OBJECT (guide));
return guide;
}
@ -69,9 +69,8 @@ gimp_image_add_vguide (GimpImage *image,
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
g_return_val_if_fail (position >= 0 && position <= image->width, NULL);
guide = g_new0 (GimpGuide, 1);
guide = g_object_new (GIMP_TYPE_GUIDE, NULL);
guide->ref_count = 1;
guide->position = -1;
guide->orientation = GIMP_ORIENTATION_VERTICAL;
guide->guide_ID = image->gimp->next_guide_ID++;
@ -81,39 +80,18 @@ gimp_image_add_vguide (GimpImage *image,
guide);
gimp_image_add_guide (image, guide, position);
gimp_image_guide_unref (guide);
g_object_unref (G_OBJECT (guide));
return guide;
}
GimpGuide *
gimp_image_guide_ref (GimpGuide *guide)
{
g_return_val_if_fail (guide != NULL, NULL);
guide->ref_count++;
return guide;
}
void
gimp_image_guide_unref (GimpGuide *guide)
{
g_return_if_fail (guide != NULL);
guide->ref_count--;
if (guide->ref_count < 1)
g_free (guide);
}
void
gimp_image_add_guide (GimpImage *image,
GimpGuide *guide,
gint position)
{
g_return_if_fail (GIMP_IS_IMAGE (image));
g_return_if_fail (guide != NULL);
g_return_if_fail (GIMP_IS_GUIDE (guide));
g_return_if_fail (position >= 0);
if (guide->orientation == GIMP_ORIENTATION_HORIZONTAL)
@ -124,7 +102,7 @@ gimp_image_add_guide (GimpImage *image,
image->guides = g_list_prepend (image->guides, guide);
guide->position = position;
gimp_image_guide_ref (guide);
g_object_ref (G_OBJECT (guide));
gimp_image_update_guide (image, guide);
}
@ -135,7 +113,7 @@ gimp_image_remove_guide (GimpImage *image,
gboolean push_undo)
{
g_return_if_fail (GIMP_IS_IMAGE (image));
g_return_if_fail (guide != NULL);
g_return_if_fail (GIMP_IS_GUIDE (guide));
gimp_image_update_guide (image, guide);
@ -145,7 +123,7 @@ gimp_image_remove_guide (GimpImage *image,
image->guides = g_list_remove (image->guides, guide);
guide->position = -1;
gimp_image_guide_unref (guide);
g_object_unref (G_OBJECT (guide));
}
void
@ -155,7 +133,7 @@ gimp_image_move_guide (GimpImage *image,
gboolean push_undo)
{
g_return_if_fail (GIMP_IS_IMAGE (image));
g_return_if_fail (guide != NULL);
g_return_if_fail (GIMP_IS_GUIDE (guide));
g_return_if_fail (position >= 0);
if (guide->orientation == GIMP_ORIENTATION_HORIZONTAL)

View File

@ -20,15 +20,6 @@
#define __GIMP_IMAGE_GUIDES_H__
struct _GimpGuide
{
gint ref_count;
gint position;
GimpOrientationType orientation;
guint32 guide_ID;
};
GimpGuide * gimp_image_add_hguide (GimpImage *image,
gint position,
gboolean push_undo);
@ -36,9 +27,6 @@ GimpGuide * gimp_image_add_vguide (GimpImage *image,
gint position,
gboolean push_undo);
GimpGuide * gimp_image_guide_ref (GimpGuide *guide);
void gimp_image_guide_unref (GimpGuide *guide);
void gimp_image_add_guide (GimpImage *image,
GimpGuide *guide,
gint position);

View File

@ -24,6 +24,7 @@
#include "gimp.h"
#include "gimpcontext.h"
#include "gimpguide.h"
#include "gimpimage.h"
#include "gimpimage-guides.h"
#include "gimpimage-item-list.h"

View File

@ -24,6 +24,7 @@
#include "gimp.h"
#include "gimpcontext.h"
#include "gimpguide.h"
#include "gimpimage.h"
#include "gimpimage-rotate.h"
#include "gimpimage-guides.h"

View File

@ -25,6 +25,7 @@
#include "base/tile-manager.h"
#include "gimp.h"
#include "gimpguide.h"
#include "gimpimage.h"
#include "gimpimage-guides.h"
#include "gimpimage-sample-points.h"

View File

@ -23,6 +23,7 @@
#include "core-types.h"
#include "gimp.h"
#include "gimpguide.h"
#include "gimpimage.h"
#include "gimpimage-grid.h"
#include "gimpimage-guides.h"

View File

@ -35,6 +35,7 @@
#include "gimp-parasites.h"
#include "gimp.h"
#include "gimpgrid.h"
#include "gimpguide.h"
#include "gimpimage-colormap.h"
#include "gimpimage-grid.h"
#include "gimpimage-guides.h"
@ -347,7 +348,7 @@ gimp_image_undo_push_image_guide (GimpImage *image,
{
GuideUndo *gu = new->data;
gu->guide = gimp_image_guide_ref (guide);
gu->guide = g_object_ref (guide);
gu->position = guide->position;
gu->orientation = guide->orientation;
@ -379,7 +380,7 @@ undo_pop_image_guide (GimpUndo *undo,
{
undo->image->guides = g_list_prepend (undo->image->guides, gu->guide);
gu->guide->position = gu->position;
gimp_image_guide_ref (gu->guide);
g_object_ref (gu->guide);
gimp_image_update_guide (undo->image, gu->guide);
}
else if (gu->position == -1)
@ -407,7 +408,7 @@ undo_free_image_guide (GimpUndo *undo,
{
GuideUndo *gu = undo->data;
gimp_image_guide_unref (gu->guide);
g_object_unref (gu->guide);
g_free (gu);
}

View File

@ -40,6 +40,7 @@
#include "gimp-utils.h"
#include "gimpcontext.h"
#include "gimpgrid.h"
#include "gimpguide.h"
#include "gimpimage.h"
#include "gimpimage-colorhash.h"
#include "gimpimage-colormap.h"
@ -868,7 +869,7 @@ gimp_image_finalize (GObject *object)
if (image->guides)
{
g_list_foreach (image->guides, (GFunc) gimp_image_guide_unref, NULL);
g_list_foreach (image->guides, (GFunc) g_object_unref, NULL);
g_list_free (image->guides);
image->guides = NULL;
}

View File

@ -25,6 +25,7 @@
#include "core/gimp-utils.h"
#include "core/gimpcontext.h"
#include "core/gimpgrid.h"
#include "core/gimpguide.h"
#include "core/gimpimage.h"
#include "core/gimpimage-guides.h"
#include "core/gimpimage-sample-points.h"

View File

@ -36,6 +36,7 @@
#include "core/gimp.h"
#include "core/gimpchannel.h"
#include "core/gimpcontext.h"
#include "core/gimpguide.h"
#include "core/gimpimage.h"
#include "core/gimpimage-guides.h"
#include "core/gimpimage-sample-points.h"

View File

@ -28,6 +28,7 @@
#include "gimpprocedure.h"
#include "core/gimpparamspecs.h"
#include "core/gimpguide.h"
#include "core/gimpimage-guides.h"
#include "core/gimpimage-undo-push.h"
#include "core/gimpimage.h"

View File

@ -28,6 +28,7 @@
#include "config/gimpguiconfig.h"
#include "core/gimp.h"
#include "core/gimpguide.h"
#include "core/gimpimage.h"
#include "core/gimpimage-guides.h"
#include "core/gimplayer.h"

View File

@ -35,6 +35,7 @@
#include "core/gimpchannel.h"
#include "core/gimpdrawable.h"
#include "core/gimpgrid.h"
#include "core/gimpguide.h"
#include "core/gimpimage.h"
#include "core/gimpimage-grid.h"
#include "core/gimpimage-guides.h"

View File

@ -239,7 +239,7 @@ CODE
}
@headers = qw("core/gimpimage-guides.h" "core/gimpimage-undo-push.h");
@headers = qw("core/gimpguide.h" "core/gimpimage-guides.h" "core/gimpimage-undo-push.h");
@procs = qw(image_add_hguide image_add_vguide image_delete_guide
image_find_next_guide image_get_guide_orientation