From 7c4d375aa998347073fd421a53c51e4f2eab530b Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Thu, 17 Jul 2003 18:06:32 +0000 Subject: [PATCH] app/vectors/Makefile.am added a simple GimpAnchor API. 2003-07-17 Sven Neumann * app/vectors/Makefile.am * app/vectors/gimpanchor.[ch]: added a simple GimpAnchor API. * app/vectors/gimpbezierstroke.c * app/vectors/gimpstroke.c: use the new functions. --- ChangeLog | 8 +++++ app/vectors/Makefile.am | 1 + app/vectors/gimpanchor.c | 55 ++++++++++++++++++++++++++++++++++ app/vectors/gimpanchor.h | 9 +++++- app/vectors/gimpbezierstroke.c | 49 ++++++++++++++++-------------- app/vectors/gimpstroke.c | 27 ++++++++--------- 6 files changed, 110 insertions(+), 39 deletions(-) create mode 100644 app/vectors/gimpanchor.c diff --git a/ChangeLog b/ChangeLog index 2453f190ba..15ec0afc05 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2003-07-17 Sven Neumann + + * app/vectors/Makefile.am + * app/vectors/gimpanchor.[ch]: added a simple GimpAnchor API. + + * app/vectors/gimpbezierstroke.c + * app/vectors/gimpstroke.c: use the new functions. + 2003-07-17 Jakub Steiner * plug-ins/common/*.c: added mnemonics for plugins diff --git a/app/vectors/Makefile.am b/app/vectors/Makefile.am index 2359155382..7652a86a8e 100644 --- a/app/vectors/Makefile.am +++ b/app/vectors/Makefile.am @@ -15,6 +15,7 @@ noinst_LIBRARIES = libappvectors.a libappvectors_a_SOURCES = \ vectors-types.h \ + gimpanchor.c \ gimpanchor.h \ gimpbezierstroke.h \ gimpbezierstroke.c \ diff --git a/app/vectors/gimpanchor.c b/app/vectors/gimpanchor.c new file mode 100644 index 0000000000..c7ba769a01 --- /dev/null +++ b/app/vectors/gimpanchor.c @@ -0,0 +1,55 @@ +/* The GIMP -- an image manipulation program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * gimpanchor.c + * Copyright (C) 2002 Simon Budig + * + * 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 "glib-object.h" + +#include "vectors-types.h" + +#include "gimpanchor.h" + + +GimpAnchor * +gimp_anchor_new (GimpAnchorType type, + const GimpCoords *position) +{ + GimpAnchor *anchor = g_new0 (GimpAnchor, 1); + + anchor->type = type; + + if (position) + anchor->position = *position; + + return anchor; +} + +void +gimp_anchor_free (GimpAnchor *anchor) +{ + g_free (anchor); +} + +GimpAnchor * +gimp_anchor_duplicate (const GimpAnchor *anchor) +{ + return g_memdup (anchor, sizeof (GimpAnchor)); +} diff --git a/app/vectors/gimpanchor.h b/app/vectors/gimpanchor.h index e5e958d31e..167ddfd8cf 100644 --- a/app/vectors/gimpanchor.h +++ b/app/vectors/gimpanchor.h @@ -1,6 +1,6 @@ /* The GIMP -- an image manipulation program * Copyright (C) 1995 Spencer Kimball and Peter Mattis - * + * * gimpanchor.h * Copyright (C) 2002 Simon Budig * @@ -31,4 +31,11 @@ struct _GimpAnchor gboolean selected; }; + +GimpAnchor * gimp_anchor_new (GimpAnchorType type, + const GimpCoords *position); +void gimp_anchor_free (GimpAnchor *anchor); +GimpAnchor * gimp_anchor_duplicate (const GimpAnchor *anchor); + + #endif /* __GIMP_ANCHOR_H__ */ diff --git a/app/vectors/gimpbezierstroke.c b/app/vectors/gimpbezierstroke.c index b7832a7413..8027c7ad52 100644 --- a/app/vectors/gimpbezierstroke.c +++ b/app/vectors/gimpbezierstroke.c @@ -3,7 +3,7 @@ * * gimpstroke.c * Copyright (C) 2002 Simon Budig - * + * * 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 @@ -113,7 +113,7 @@ gimp_bezier_stroke_get_type (void) }; bezier_stroke_type = g_type_register_static (GIMP_TYPE_STROKE, - "GimpBezierStroke", + "GimpBezierStroke", &bezier_stroke_info, 0); } @@ -166,6 +166,7 @@ gimp_bezier_stroke_new (void) stroke->anchors = NULL; stroke->closed = FALSE; + return stroke; } @@ -224,9 +225,7 @@ gimp_bezier_stroke_extend (GimpBezierStroke *bezier_stroke, /* assure that there is no neighbor specified */ g_return_val_if_fail (neighbor == NULL, NULL); - anchor = g_new0 (GimpAnchor, 1); - anchor->position = *coords; - anchor->type = GIMP_ANCHOR_CONTROL; + anchor = gimp_anchor_new (GIMP_ANCHOR_CONTROL, coords); stroke->anchors = g_list_append (stroke->anchors, anchor); @@ -247,9 +246,11 @@ gimp_bezier_stroke_extend (GimpBezierStroke *bezier_stroke, EXTEND_SIMPLE); break; + default: anchor = NULL; } + return anchor; } else @@ -324,6 +325,8 @@ gimp_bezier_stroke_extend (GimpBezierStroke *bezier_stroke, if (loose_end) { + GimpAnchorType type; + /* We have to detect the type of the point to add... */ control_count = 0; @@ -350,28 +353,28 @@ gimp_bezier_stroke_extend (GimpBezierStroke *bezier_stroke, switch (extend_mode) { case EXTEND_SIMPLE: - anchor = g_new0 (GimpAnchor, 1); - anchor->position = *coords; - switch (control_count) { case 0: - anchor->type = GIMP_ANCHOR_CONTROL; + type = GIMP_ANCHOR_CONTROL; break; case 1: if (listneighbor) /* only one handle in the path? */ - anchor->type = GIMP_ANCHOR_CONTROL; + type = GIMP_ANCHOR_CONTROL; else - anchor->type = GIMP_ANCHOR_ANCHOR; + type = GIMP_ANCHOR_ANCHOR; break; case 2: - anchor->type = GIMP_ANCHOR_ANCHOR; + type = GIMP_ANCHOR_ANCHOR; break; default: - g_printerr ("inconsistent bezier curve: " - "%d successive control handles", control_count); + g_warning ("inconsistent bezier curve: " + "%d successive control handles", control_count); + type = GIMP_ANCHOR_ANCHOR; } + anchor = gimp_anchor_new (type, coords); + if (loose_end == 1) stroke->anchors = g_list_append (stroke->anchors, anchor); @@ -406,8 +409,8 @@ gimp_bezier_stroke_extend (GimpBezierStroke *bezier_stroke, EXTEND_SIMPLE); break; default: - g_printerr ("inconsistent bezier curve: " - "%d successive control handles", control_count); + g_warning ("inconsistent bezier curve: " + "%d successive control handles", control_count); } } @@ -542,8 +545,8 @@ gimp_bezier_stroke_anchor_convert (GimpStroke *stroke, break; default: - g_printerr ("gimp_bezier_stroke_anchor_convert: " - "unimplemented anchor conversion %d\n", feature); + g_warning ("gimp_bezier_stroke_anchor_convert: " + "unimplemented anchor conversion %d\n", feature); } } @@ -560,7 +563,7 @@ gimp_bezier_stroke_interpolate (const GimpStroke *stroke, g_return_val_if_fail (GIMP_IS_BEZIER_STROKE (stroke), NULL); g_return_val_if_fail (ret_closed != NULL, NULL); - + if (!stroke->anchors) { *ret_closed = FALSE; @@ -604,7 +607,7 @@ gimp_bezier_stroke_interpolate (const GimpStroke *stroke, segmentcoords[3] = ((GimpAnchor *) anchorlist->data)->position; gimp_bezier_coords_subdivide (segmentcoords, precision, &ret_coords); - + } ret_coords = g_array_append_val (ret_coords, segmentcoords[3]); @@ -646,7 +649,7 @@ gimp_bezier_coords_mix (const gdouble amul, } } - + /* (a+b)/2 */ static void @@ -738,7 +741,7 @@ gimp_bezier_coords_length (const GimpCoords *a) /* * a helper function that determines if a bezier segment is "straight * enough" to be approximated by a line. - * + * * Needs four GimpCoords in an array. */ @@ -876,7 +879,7 @@ gimp_bezier_coords_subdivide2 (const GimpCoords *beziercoords, gimp_bezier_coords_subdivide2 (&(subdivided[3]), precision, ret_coords, depth-1); } - + /* g_printerr ("gimp_bezier_coords_subdivide end: %d entries\n", (*ret_coords)->len); */ } diff --git a/app/vectors/gimpstroke.c b/app/vectors/gimpstroke.c index 95ba477115..223195cb44 100644 --- a/app/vectors/gimpstroke.c +++ b/app/vectors/gimpstroke.c @@ -3,7 +3,7 @@ * * gimpstroke.c * Copyright (C) 2002 Simon Budig - * + * * 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 @@ -101,7 +101,7 @@ gimp_stroke_get_type (void) }; stroke_type = g_type_register_static (GIMP_TYPE_OBJECT, - "GimpStroke", + "GimpStroke", &stroke_info, 0); } @@ -162,12 +162,15 @@ static void gimp_stroke_finalize (GObject *object) { GimpStroke *stroke; + GList *list; stroke = GIMP_STROKE (object); -#ifdef __GNUC__ -#warning FIXME: implement gimp_stroke_finalize() -#endif + for (list = stroke->anchors; list; list = list->next) + gimp_anchor_free ((GimpAnchor *) list->data); + + if (stroke->temp_anchor) + gimp_anchor_free (stroke->temp_anchor); G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -274,7 +277,7 @@ gimp_stroke_real_anchor_get_next (const GimpStroke *stroke, if (list) return (GimpAnchor *) list->data; - + return NULL; } @@ -533,18 +536,12 @@ gimp_stroke_real_duplicate (const GimpStroke *stroke) for (list = new_stroke->anchors; list; list = g_list_next (list)) { - GimpAnchor *new_anchor = g_new0 (GimpAnchor, 1); - - *new_anchor = *((GimpAnchor *) (list->data)); - - list->data = new_anchor; + list->data = gimp_anchor_duplicate ((GimpAnchor *) list->data); } if (stroke->temp_anchor) { - new_stroke->temp_anchor = g_new0 (GimpAnchor, 1); - - *(new_stroke->temp_anchor) = *(stroke->temp_anchor); + new_stroke->temp_anchor = gimp_anchor_duplicate (stroke->temp_anchor); } return new_stroke; @@ -628,7 +625,7 @@ gimp_stroke_real_get_draw_controls (const GimpStroke *stroke) return g_list_reverse (ret_list); } - + GArray * gimp_stroke_get_draw_lines (const GimpStroke *stroke)