[gimp] app: guide cleanup
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: guide cleanup
- Date: Wed, 9 Jul 2014 22:27:04 +0000 (UTC)
commit ad9fd33915375510a5a8a0ec9a5715e55b8c37b5
Author: Michael Natterer <mitch gimp org>
Date: Thu Jul 10 00:20:57 2014 +0200
app: guide cleanup
- Move all GimpGuide members to a private struct
- Remove cruft checks for position < 0, we don't keep removed guides
around in the image's guide list since a long time ago
- Add #define GIMP_GUIDE_POSITION_UNDEFINED G_MININT and use that
instead of -1 (this is also a prerequisite for having guides
outside of the image)
app/core/gimpguide.c | 40 +++++++++++++++++++++++++++-------------
app/core/gimpguide.h | 17 ++++++++++-------
app/core/gimpguideundo.c | 4 ++--
app/core/gimpimage-guides.c | 11 ++---------
app/core/gimpimage-snap.c | 9 ---------
app/tools/gimpmovetool.c | 23 +++++++++++------------
libgimp/gimpguides_pdb.c | 2 +-
tools/pdbgen/pdb/guides.pdb | 13 +++++++++----
8 files changed, 62 insertions(+), 57 deletions(-)
---
diff --git a/app/core/gimpguide.c b/app/core/gimpguide.c
index e6090d0..eaa8b74 100644
--- a/app/core/gimpguide.c
+++ b/app/core/gimpguide.c
@@ -45,6 +45,14 @@ enum
};
+struct _GimpGuidePrivate
+{
+ guint32 guide_ID;
+ GimpOrientationType orientation;
+ gint position;
+};
+
+
static void gimp_guide_get_property (GObject *object,
guint property_id,
GValue *value,
@@ -93,13 +101,19 @@ gimp_guide_class_init (GimpGuideClass *klass)
0);
GIMP_CONFIG_INSTALL_PROP_INT (object_class, PROP_POSITION,
"position", NULL,
- -1, GIMP_MAX_IMAGE_SIZE, -1,
+ GIMP_GUIDE_POSITION_UNDEFINED,
+ GIMP_MAX_IMAGE_SIZE,
+ GIMP_GUIDE_POSITION_UNDEFINED,
0);
+
+ g_type_class_add_private (klass, sizeof (GimpGuidePrivate));
}
static void
gimp_guide_init (GimpGuide *guide)
{
+ guide->priv = G_TYPE_INSTANCE_GET_PRIVATE (guide, GIMP_TYPE_GUIDE,
+ GimpGuidePrivate);
}
static void
@@ -113,13 +127,13 @@ gimp_guide_get_property (GObject *object,
switch (property_id)
{
case PROP_ID:
- g_value_set_uint (value, guide->guide_ID);
+ g_value_set_uint (value, guide->priv->guide_ID);
break;
case PROP_ORIENTATION:
- g_value_set_enum (value, guide->orientation);
+ g_value_set_enum (value, guide->priv->orientation);
break;
case PROP_POSITION:
- g_value_set_int (value, guide->position);
+ g_value_set_int (value, guide->priv->position);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -138,13 +152,13 @@ gimp_guide_set_property (GObject *object,
switch (property_id)
{
case PROP_ID:
- guide->guide_ID = g_value_get_uint (value);
+ guide->priv->guide_ID = g_value_get_uint (value);
break;
case PROP_ORIENTATION:
- guide->orientation = g_value_get_enum (value);
+ guide->priv->orientation = g_value_get_enum (value);
break;
case PROP_POSITION:
- guide->position = g_value_get_int (value);
+ guide->priv->position = g_value_get_int (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -167,7 +181,7 @@ gimp_guide_get_ID (GimpGuide *guide)
{
g_return_val_if_fail (GIMP_IS_GUIDE (guide), 0);
- return guide->guide_ID;
+ return guide->priv->guide_ID;
}
GimpOrientationType
@@ -175,7 +189,7 @@ gimp_guide_get_orientation (GimpGuide *guide)
{
g_return_val_if_fail (GIMP_IS_GUIDE (guide), GIMP_ORIENTATION_UNKNOWN);
- return guide->orientation;
+ return guide->priv->orientation;
}
void
@@ -184,7 +198,7 @@ gimp_guide_set_orientation (GimpGuide *guide,
{
g_return_if_fail (GIMP_IS_GUIDE (guide));
- guide->orientation = orientation;
+ guide->priv->orientation = orientation;
g_object_notify (G_OBJECT (guide), "orientation");
}
@@ -192,9 +206,9 @@ gimp_guide_set_orientation (GimpGuide *guide,
gint
gimp_guide_get_position (GimpGuide *guide)
{
- g_return_val_if_fail (GIMP_IS_GUIDE (guide), -1);
+ g_return_val_if_fail (GIMP_IS_GUIDE (guide), GIMP_GUIDE_POSITION_UNDEFINED);
- return guide->position;
+ return guide->priv->position;
}
void
@@ -203,7 +217,7 @@ gimp_guide_set_position (GimpGuide *guide,
{
g_return_if_fail (GIMP_IS_GUIDE (guide));
- guide->position = position;
+ guide->priv->position = position;
g_object_notify (G_OBJECT (guide), "position");
}
diff --git a/app/core/gimpguide.h b/app/core/gimpguide.h
index 1a0f003..20cc34e 100644
--- a/app/core/gimpguide.h
+++ b/app/core/gimpguide.h
@@ -25,6 +25,9 @@
#include "gimpobject.h"
+#define GIMP_GUIDE_POSITION_UNDEFINED G_MININT
+
+
#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))
@@ -33,23 +36,22 @@
#define GIMP_GUIDE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_GUIDE, GimpGuideClass))
-typedef struct _GimpGuideClass GimpGuideClass;
+typedef struct _GimpGuidePrivate GimpGuidePrivate;
+typedef struct _GimpGuideClass GimpGuideClass;
struct _GimpGuide
{
- GObject parent_instance;
+ GObject parent_instance;
- guint32 guide_ID;
- GimpOrientationType orientation;
- gint position;
+ GimpGuidePrivate *priv;
};
struct _GimpGuideClass
{
- GObjectClass parent_class;
+ GObjectClass parent_class;
/* signals */
- void (* removed) (GimpGuide *guide);
+ void (* removed) (GimpGuide *guide);
};
@@ -69,4 +71,5 @@ void gimp_guide_set_position (GimpGuide *guide,
gint position);
void gimp_guide_removed (GimpGuide *guide);
+
#endif /* __GIMP_GUIDE_H__ */
diff --git a/app/core/gimpguideundo.c b/app/core/gimpguideundo.c
index 06099cb..37b83d3 100644
--- a/app/core/gimpguideundo.c
+++ b/app/core/gimpguideundo.c
@@ -150,12 +150,12 @@ gimp_guide_undo_pop (GimpUndo *undo,
orientation = gimp_guide_get_orientation (guide_undo->guide);
position = gimp_guide_get_position (guide_undo->guide);
- if (position == -1)
+ if (position == GIMP_GUIDE_POSITION_UNDEFINED)
{
gimp_image_add_guide (undo->image,
guide_undo->guide, guide_undo->position);
}
- else if (guide_undo->position == -1)
+ else if (guide_undo->position == GIMP_GUIDE_POSITION_UNDEFINED)
{
gimp_image_remove_guide (undo->image, guide_undo->guide, FALSE);
}
diff --git a/app/core/gimpimage-guides.c b/app/core/gimpimage-guides.c
index e882466..4eafcb3 100644
--- a/app/core/gimpimage-guides.c
+++ b/app/core/gimpimage-guides.c
@@ -122,7 +122,7 @@ gimp_image_remove_guide (GimpImage *image,
gimp_image_guide_removed (image, guide);
- gimp_guide_set_position (guide, -1);
+ gimp_guide_set_position (guide, GIMP_GUIDE_POSITION_UNDEFINED);
g_object_unref (G_OBJECT (guide));
}
@@ -171,8 +171,7 @@ gimp_image_get_guide (GimpImage *image,
{
GimpGuide *guide = guides->data;
- if (gimp_guide_get_ID (guide) == id &&
- gimp_guide_get_position (guide) >= 0)
+ if (gimp_guide_get_ID (guide) == id)
return guide;
}
@@ -200,9 +199,6 @@ gimp_image_get_next_guide (GimpImage *image,
{
GimpGuide *guide = guides->data;
- if (gimp_guide_get_position (guide) < 0)
- continue;
-
if (*guide_found) /* this is the first guide after the found one */
return guide;
@@ -235,9 +231,6 @@ gimp_image_find_guide (GimpImage *image,
gint position = gimp_guide_get_position (guide);
gdouble dist;
- if (position < 0)
- continue;
-
switch (gimp_guide_get_orientation (guide))
{
case GIMP_ORIENTATION_HORIZONTAL:
diff --git a/app/core/gimpimage-snap.c b/app/core/gimpimage-snap.c
index 71b4a98..ee78a49 100644
--- a/app/core/gimpimage-snap.c
+++ b/app/core/gimpimage-snap.c
@@ -83,9 +83,6 @@ gimp_image_snap_x (GimpImage *image,
GimpGuide *guide = list->data;
gint position = gimp_guide_get_position (guide);
- if (position < 0)
- continue;
-
if (gimp_guide_get_orientation (guide) == GIMP_ORIENTATION_VERTICAL)
{
snapped |= gimp_image_snap_distance (x, position,
@@ -168,9 +165,6 @@ gimp_image_snap_y (GimpImage *image,
GimpGuide *guide = list->data;
gint position = gimp_guide_get_position (guide);
- if (position < 0)
- continue;
-
if (gimp_guide_get_orientation (guide) == GIMP_ORIENTATION_HORIZONTAL)
{
snapped |= gimp_image_snap_distance (y, position,
@@ -263,9 +257,6 @@ gimp_image_snap_point (GimpImage *image,
GimpGuide *guide = list->data;
gint position = gimp_guide_get_position (guide);
- if (position < 0)
- continue;
-
switch (gimp_guide_get_orientation (guide))
{
case GIMP_ORIENTATION_HORIZONTAL:
diff --git a/app/tools/gimpmovetool.c b/app/tools/gimpmovetool.c
index ccb9ee7..6acce25 100644
--- a/app/tools/gimpmovetool.c
+++ b/app/tools/gimpmovetool.c
@@ -59,8 +59,6 @@
#include "gimp-intl.h"
-#define GUIDE_POSITION_INVALID G_MININT
-
#define SWAP_ORIENT(orient) ((orient) == GIMP_ORIENTATION_HORIZONTAL ? \
GIMP_ORIENTATION_VERTICAL : \
GIMP_ORIENTATION_HORIZONTAL)
@@ -163,7 +161,7 @@ gimp_move_tool_init (GimpMoveTool *move_tool)
move_tool->guide = NULL;
move_tool->moving_guide = FALSE;
- move_tool->guide_position = GUIDE_POSITION_INVALID;
+ move_tool->guide_position = GIMP_GUIDE_POSITION_UNDEFINED;
move_tool->guide_orientation = GIMP_ORIENTATION_UNKNOWN;
move_tool->saved_type = GIMP_TRANSFORM_TYPE_LAYER;
@@ -421,7 +419,7 @@ gimp_move_tool_button_release (GimpTool *tool,
if (release_type == GIMP_BUTTON_RELEASE_CANCEL)
{
move->moving_guide = FALSE;
- move->guide_position = GUIDE_POSITION_INVALID;
+ move->guide_position = GIMP_GUIDE_POSITION_UNDEFINED;
move->guide_orientation = GIMP_ORIENTATION_UNKNOWN;
gimp_display_shell_selection_resume (shell);
@@ -431,15 +429,15 @@ gimp_move_tool_button_release (GimpTool *tool,
switch (move->guide_orientation)
{
case GIMP_ORIENTATION_HORIZONTAL:
- if (move->guide_position == GUIDE_POSITION_INVALID ||
- move->guide_position < 0 ||
+ if (move->guide_position == GIMP_GUIDE_POSITION_UNDEFINED ||
+ move->guide_position < 0 ||
move->guide_position >= height)
delete_guide = TRUE;
break;
case GIMP_ORIENTATION_VERTICAL:
- if (move->guide_position == GUIDE_POSITION_INVALID ||
- move->guide_position < 0 ||
+ if (move->guide_position == GIMP_GUIDE_POSITION_UNDEFINED ||
+ move->guide_position < 0 ||
move->guide_position >= width)
delete_guide = TRUE;
break;
@@ -489,7 +487,7 @@ gimp_move_tool_button_release (GimpTool *tool,
gimp_image_flush (image);
move->moving_guide = FALSE;
- move->guide_position = GUIDE_POSITION_INVALID;
+ move->guide_position = GIMP_GUIDE_POSITION_UNDEFINED;
move->guide_orientation = GIMP_ORIENTATION_UNKNOWN;
if (move->guide)
@@ -559,7 +557,7 @@ gimp_move_tool_motion (GimpTool *tool,
if (tx < 0 || tx >= shell->disp_width ||
ty < 0 || ty >= shell->disp_height)
{
- move->guide_position = GUIDE_POSITION_INVALID;
+ move->guide_position = GIMP_GUIDE_POSITION_UNDEFINED;
delete_guide = TRUE;
}
@@ -845,7 +843,8 @@ gimp_move_tool_draw (GimpDrawTool *draw_tool)
gimp_canvas_item_set_highlight (item, TRUE);
}
- if (move->moving_guide && move->guide_position != GUIDE_POSITION_INVALID)
+ if (move->moving_guide &&
+ move->guide_position != GIMP_GUIDE_POSITION_UNDEFINED)
{
gimp_draw_tool_add_guide (draw_tool,
move->guide_orientation,
@@ -894,7 +893,7 @@ gimp_move_tool_start_guide (GimpMoveTool *move,
move->guide = NULL;
move->moving_guide = TRUE;
- move->guide_position = GUIDE_POSITION_INVALID;
+ move->guide_position = GIMP_GUIDE_POSITION_UNDEFINED;
move->guide_orientation = orientation;
gimp_tool_set_cursor (tool, display,
diff --git a/libgimp/gimpguides_pdb.c b/libgimp/gimpguides_pdb.c
index ff7c2fe..1fb07a3 100644
--- a/libgimp/gimpguides_pdb.c
+++ b/libgimp/gimpguides_pdb.c
@@ -226,7 +226,7 @@ gimp_image_get_guide_position (gint32 image_ID,
{
GimpParam *return_vals;
gint nreturn_vals;
- gint position = -1;
+ gint position = G_MININT /* GIMP_GUIDE_POSITION_UNDEFINED */;
return_vals = gimp_run_procedure ("gimp-image-get-guide-position",
&nreturn_vals,
diff --git a/tools/pdbgen/pdb/guides.pdb b/tools/pdbgen/pdb/guides.pdb
index 42a84ea..7b16ebd 100644
--- a/tools/pdbgen/pdb/guides.pdb
+++ b/tools/pdbgen/pdb/guides.pdb
@@ -219,7 +219,8 @@ HELP
);
@outargs = (
- { name => 'position', type => 'int32', libdef => '-1',
+ { name => 'position', type => 'int32',
+ libdef => 'G_MININT /* GIMP_GUIDE_POSITION_UNDEFINED */',
desc => "The guide's position relative to top or left of image" }
);
@@ -238,10 +239,14 @@ CODE
}
- headers = qw("core/gimpguide.h" "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
+ procs = qw(image_add_hguide image_add_vguide
+ image_delete_guide
+ image_find_next_guide
+ image_get_guide_orientation
image_get_guide_position);
%exports = (app => [ procs], lib => [ procs]);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]