2002-02-25 11:16:41 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimpstroke.c
|
|
|
|
* Copyright (C) 2002 Simon Budig <simon@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 "glib-object.h"
|
|
|
|
|
|
|
|
#include "vectors-types.h"
|
|
|
|
|
|
|
|
#include "gimpanchor.h"
|
|
|
|
#include "gimpstroke.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* Prototypes */
|
|
|
|
|
2002-02-25 21:39:34 +08:00
|
|
|
static void gimp_stroke_class_init (GimpStrokeClass *klass);
|
2002-02-25 11:16:41 +08:00
|
|
|
static void gimp_stroke_init (GimpStroke *stroke);
|
|
|
|
|
2002-02-25 21:39:34 +08:00
|
|
|
static void gimp_stroke_finalize (GObject *object);
|
|
|
|
|
2003-02-01 02:08:32 +08:00
|
|
|
static gsize gimp_stroke_get_memsize (GimpObject *object);
|
|
|
|
|
2002-02-25 11:16:41 +08:00
|
|
|
static GimpAnchor * gimp_stroke_real_anchor_get (const GimpStroke *stroke,
|
|
|
|
const GimpCoords *coord);
|
|
|
|
static GimpAnchor * gimp_stroke_real_anchor_get_next (const GimpStroke *stroke,
|
|
|
|
const GimpAnchor *prev);
|
2003-05-17 00:49:04 +08:00
|
|
|
static void gimp_stroke_real_anchor_select (GimpStroke *stroke,
|
|
|
|
GimpAnchor *anchor,
|
|
|
|
gboolean exclusive);
|
|
|
|
static void gimp_stroke_real_anchor_move_relative (GimpStroke *stroke,
|
|
|
|
GimpAnchor *anchor,
|
|
|
|
const GimpCoords *delta,
|
|
|
|
GimpAnchorFeatureType feature);
|
|
|
|
static void gimp_stroke_real_anchor_move_absolute (GimpStroke *stroke,
|
|
|
|
GimpAnchor *anchor,
|
|
|
|
const GimpCoords *delta,
|
|
|
|
GimpAnchorFeatureType feature);
|
|
|
|
static void gimp_stroke_real_anchor_convert (GimpStroke *stroke,
|
|
|
|
GimpAnchor *anchor,
|
|
|
|
GimpAnchorFeatureType feature);
|
|
|
|
static void gimp_stroke_real_anchor_delete (GimpStroke *stroke,
|
|
|
|
GimpAnchor *anchor);
|
|
|
|
static gdouble gimp_stroke_real_get_length (const GimpStroke *stroke);
|
|
|
|
static gdouble gimp_stroke_real_get_distance (const GimpStroke *stroke,
|
|
|
|
const GimpCoords *coord);
|
|
|
|
static GArray * gimp_stroke_real_interpolate (const GimpStroke *stroke,
|
|
|
|
gdouble precision,
|
|
|
|
gboolean *closed);
|
|
|
|
static GimpAnchor * gimp_stroke_real_temp_anchor_get (const GimpStroke *stroke);
|
|
|
|
static GimpAnchor * gimp_stroke_real_temp_anchor_set (GimpStroke *stroke,
|
|
|
|
const GimpCoords *coord);
|
|
|
|
static gboolean gimp_stroke_real_temp_anchor_fix (GimpStroke *stroke);
|
|
|
|
static GimpStroke * gimp_stroke_real_duplicate (const GimpStroke *stroke);
|
|
|
|
static GimpStroke * gimp_stroke_real_make_bezier (const GimpStroke *stroke);
|
|
|
|
static GList * gimp_stroke_real_get_draw_anchors (const GimpStroke *stroke);
|
|
|
|
static GList * gimp_stroke_real_get_draw_controls (const GimpStroke *stroke);
|
|
|
|
static GArray * gimp_stroke_real_get_draw_lines (const GimpStroke *stroke);
|
|
|
|
|
2002-02-25 11:16:41 +08:00
|
|
|
|
2003-02-01 02:08:32 +08:00
|
|
|
/* private variables */
|
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
static GimpObjectClass *parent_class = NULL;
|
2003-02-01 02:08:32 +08:00
|
|
|
|
|
|
|
|
2002-02-25 21:39:34 +08:00
|
|
|
GType
|
|
|
|
gimp_stroke_get_type (void)
|
2002-02-25 11:16:41 +08:00
|
|
|
{
|
2002-02-25 21:39:34 +08:00
|
|
|
static GType stroke_type = 0;
|
|
|
|
|
|
|
|
if (! stroke_type)
|
|
|
|
{
|
|
|
|
static const GTypeInfo stroke_info =
|
|
|
|
{
|
|
|
|
sizeof (GimpStrokeClass),
|
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_stroke_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpStroke),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_stroke_init,
|
|
|
|
};
|
|
|
|
|
2003-02-01 02:08:32 +08:00
|
|
|
stroke_type = g_type_register_static (GIMP_TYPE_OBJECT,
|
2002-02-25 21:39:34 +08:00
|
|
|
"GimpStroke",
|
|
|
|
&stroke_info, 0);
|
|
|
|
}
|
2002-02-25 11:16:41 +08:00
|
|
|
|
2002-02-25 21:39:34 +08:00
|
|
|
return stroke_type;
|
|
|
|
}
|
2002-02-25 11:16:41 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_stroke_class_init (GimpStrokeClass *klass)
|
|
|
|
{
|
2003-02-01 02:08:32 +08:00
|
|
|
GObjectClass *object_class;
|
|
|
|
GimpObjectClass *gimp_object_class;
|
2002-02-25 11:16:41 +08:00
|
|
|
|
|
|
|
object_class = G_OBJECT_CLASS (klass);
|
2003-02-01 02:08:32 +08:00
|
|
|
gimp_object_class = GIMP_OBJECT_CLASS (klass);
|
2002-02-25 11:16:41 +08:00
|
|
|
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
|
2003-02-01 02:08:32 +08:00
|
|
|
object_class->finalize = gimp_stroke_finalize;
|
|
|
|
|
|
|
|
gimp_object_class->get_memsize = gimp_stroke_get_memsize;
|
2002-02-25 11:16:41 +08:00
|
|
|
|
2003-02-01 02:08:32 +08:00
|
|
|
klass->changed = NULL;
|
|
|
|
klass->removed = NULL;
|
2002-02-25 11:16:41 +08:00
|
|
|
|
2003-02-01 02:08:32 +08:00
|
|
|
klass->anchor_get = gimp_stroke_real_anchor_get;
|
|
|
|
klass->anchor_get_next = gimp_stroke_real_anchor_get_next;
|
2003-05-17 00:49:04 +08:00
|
|
|
klass->anchor_select = gimp_stroke_real_anchor_select;
|
2003-02-01 02:08:32 +08:00
|
|
|
klass->anchor_move_relative = gimp_stroke_real_anchor_move_relative;
|
|
|
|
klass->anchor_move_absolute = gimp_stroke_real_anchor_move_absolute;
|
2003-05-17 00:49:04 +08:00
|
|
|
klass->anchor_convert = gimp_stroke_real_anchor_convert;
|
|
|
|
klass->anchor_delete = gimp_stroke_real_anchor_delete;
|
2002-02-25 11:16:41 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
klass->get_length = gimp_stroke_real_get_length;
|
|
|
|
klass->get_distance = gimp_stroke_real_get_distance;
|
|
|
|
klass->interpolate = gimp_stroke_real_interpolate;
|
2002-02-25 11:16:41 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
klass->temp_anchor_get = gimp_stroke_real_temp_anchor_get;
|
|
|
|
klass->temp_anchor_set = gimp_stroke_real_temp_anchor_set;
|
|
|
|
klass->temp_anchor_fix = gimp_stroke_real_temp_anchor_fix;
|
2002-02-25 11:16:41 +08:00
|
|
|
|
2003-04-14 08:37:04 +08:00
|
|
|
klass->duplicate = gimp_stroke_real_duplicate;
|
2003-05-17 00:49:04 +08:00
|
|
|
klass->make_bezier = gimp_stroke_real_make_bezier;
|
2002-12-31 00:36:01 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
klass->get_draw_anchors = gimp_stroke_real_get_draw_anchors;
|
|
|
|
klass->get_draw_controls = gimp_stroke_real_get_draw_controls;
|
|
|
|
klass->get_draw_lines = gimp_stroke_real_get_draw_lines;
|
2002-02-25 11:16:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_stroke_init (GimpStroke *stroke)
|
|
|
|
{
|
2003-04-14 08:37:04 +08:00
|
|
|
stroke->anchors = NULL;
|
|
|
|
stroke->temp_anchor = NULL;
|
2003-05-17 00:49:04 +08:00
|
|
|
stroke->closed = FALSE;
|
2003-07-03 02:01:19 +08:00
|
|
|
}
|
2002-02-25 11:16:41 +08:00
|
|
|
|
2002-02-25 21:39:34 +08:00
|
|
|
static void
|
|
|
|
gimp_stroke_finalize (GObject *object)
|
|
|
|
{
|
2003-05-17 00:49:04 +08:00
|
|
|
GimpStroke *stroke;
|
|
|
|
|
|
|
|
stroke = GIMP_STROKE (object);
|
|
|
|
|
2003-02-01 02:08:32 +08:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#warning FIXME: implement gimp_stroke_finalize()
|
|
|
|
#endif
|
|
|
|
|
2002-02-25 21:39:34 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
2002-02-25 11:16:41 +08:00
|
|
|
|
2003-02-01 02:08:32 +08:00
|
|
|
static gsize
|
|
|
|
gimp_stroke_get_memsize (GimpObject *object)
|
|
|
|
{
|
|
|
|
GimpStroke *stroke;
|
|
|
|
gsize memsize = 0;
|
|
|
|
|
|
|
|
stroke = GIMP_STROKE (object);
|
|
|
|
|
|
|
|
memsize += g_list_length (stroke->anchors) * (sizeof (GList) +
|
|
|
|
sizeof (GimpAnchor));
|
|
|
|
|
|
|
|
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-25 11:16:41 +08:00
|
|
|
GimpAnchor *
|
|
|
|
gimp_stroke_anchor_get (const GimpStroke *stroke,
|
2003-05-19 07:08:01 +08:00
|
|
|
const GimpCoords *coord)
|
2002-02-25 11:16:41 +08:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_STROKE (stroke), NULL);
|
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
return GIMP_STROKE_GET_CLASS (stroke)->anchor_get (stroke, coord);
|
2002-02-25 11:16:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static GimpAnchor *
|
|
|
|
gimp_stroke_real_anchor_get (const GimpStroke *stroke,
|
|
|
|
const GimpCoords *coord)
|
|
|
|
{
|
2003-05-17 00:49:04 +08:00
|
|
|
gdouble dx, dy;
|
|
|
|
gdouble mindist = -1;
|
|
|
|
GList *anchors;
|
2002-02-25 11:16:41 +08:00
|
|
|
GList *list;
|
|
|
|
GimpAnchor *anchor = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_STROKE (stroke), NULL);
|
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
anchors = gimp_stroke_get_draw_controls (stroke);
|
2002-12-31 11:18:49 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
for (list = anchors; list; list = g_list_next (list))
|
2002-02-25 11:16:41 +08:00
|
|
|
{
|
|
|
|
dx = coord->x - ((GimpAnchor *) list->data)->position.x;
|
|
|
|
dy = coord->y - ((GimpAnchor *) list->data)->position.y;
|
2003-05-17 00:49:04 +08:00
|
|
|
|
2002-12-31 11:18:49 +08:00
|
|
|
if (mindist < 0 || mindist > dx * dx + dy * dy)
|
|
|
|
{
|
|
|
|
mindist = dx * dx + dy * dy;
|
|
|
|
anchor = (GimpAnchor *) list->data;
|
|
|
|
}
|
2002-02-25 11:16:41 +08:00
|
|
|
}
|
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
g_list_free (anchors);
|
2003-04-14 08:37:04 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
anchors = gimp_stroke_get_draw_anchors (stroke);
|
2002-12-31 11:18:49 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
for (list = anchors; list; list = g_list_next (list))
|
2002-02-25 11:16:41 +08:00
|
|
|
{
|
|
|
|
dx = coord->x - ((GimpAnchor *) list->data)->position.x;
|
|
|
|
dy = coord->y - ((GimpAnchor *) list->data)->position.y;
|
2003-05-17 00:49:04 +08:00
|
|
|
|
2002-12-31 11:18:49 +08:00
|
|
|
if (mindist < 0 || mindist > dx * dx + dy * dy)
|
2002-02-25 11:16:41 +08:00
|
|
|
{
|
|
|
|
mindist = dx * dx + dy * dy;
|
|
|
|
anchor = (GimpAnchor *) list->data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
g_list_free (anchors);
|
2003-04-14 08:37:04 +08:00
|
|
|
|
2002-02-25 11:16:41 +08:00
|
|
|
return anchor;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GimpAnchor *
|
|
|
|
gimp_stroke_anchor_get_next (const GimpStroke *stroke,
|
2003-05-19 07:08:01 +08:00
|
|
|
const GimpAnchor *prev)
|
2002-02-25 11:16:41 +08:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_STROKE (stroke), NULL);
|
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
return GIMP_STROKE_GET_CLASS (stroke)->anchor_get_next (stroke, prev);
|
2002-02-25 11:16:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static GimpAnchor *
|
|
|
|
gimp_stroke_real_anchor_get_next (const GimpStroke *stroke,
|
|
|
|
const GimpAnchor *prev)
|
|
|
|
{
|
2003-05-17 00:49:04 +08:00
|
|
|
GList *list;
|
2002-02-25 11:16:41 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_STROKE (stroke), NULL);
|
|
|
|
|
2002-02-26 00:57:19 +08:00
|
|
|
if (prev)
|
|
|
|
{
|
2003-05-17 00:49:04 +08:00
|
|
|
list = g_list_find (stroke->anchors, prev);
|
|
|
|
if (list)
|
|
|
|
list = g_list_next (list);
|
2002-02-25 11:16:41 +08:00
|
|
|
}
|
2002-02-26 00:57:19 +08:00
|
|
|
else
|
2003-05-17 00:49:04 +08:00
|
|
|
{
|
|
|
|
list = stroke->anchors;
|
|
|
|
}
|
2002-02-25 11:16:41 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
if (list)
|
|
|
|
return (GimpAnchor *) list->data;
|
2002-02-25 11:16:41 +08:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-31 00:36:01 +08:00
|
|
|
void
|
2003-05-17 00:49:04 +08:00
|
|
|
gimp_stroke_anchor_select (GimpStroke *stroke,
|
|
|
|
GimpAnchor *anchor,
|
|
|
|
gboolean exclusive)
|
2002-12-31 00:36:01 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_STROKE (stroke));
|
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
GIMP_STROKE_GET_CLASS (stroke)->anchor_select (stroke, anchor, exclusive);
|
|
|
|
}
|
2002-12-31 00:36:01 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
static void
|
|
|
|
gimp_stroke_real_anchor_select (GimpStroke *stroke,
|
|
|
|
GimpAnchor *anchor,
|
|
|
|
gboolean exclusive)
|
|
|
|
{
|
|
|
|
GList *list;
|
2002-12-31 00:36:01 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
list = stroke->anchors;
|
2002-12-31 00:36:01 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
if (exclusive)
|
|
|
|
{
|
|
|
|
while (list)
|
2002-12-31 00:36:01 +08:00
|
|
|
{
|
2003-05-17 00:49:04 +08:00
|
|
|
((GimpAnchor *) list->data)->selected = FALSE;
|
|
|
|
list = g_list_next (list);
|
2002-12-31 00:36:01 +08:00
|
|
|
}
|
|
|
|
}
|
2003-05-17 00:49:04 +08:00
|
|
|
|
|
|
|
list = g_list_find (stroke->anchors, anchor);
|
|
|
|
|
|
|
|
if (list)
|
|
|
|
((GimpAnchor *) list->data)->selected = TRUE;
|
2002-12-31 00:36:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-25 11:16:41 +08:00
|
|
|
void
|
2003-05-17 00:49:04 +08:00
|
|
|
gimp_stroke_anchor_move_relative (GimpStroke *stroke,
|
|
|
|
GimpAnchor *anchor,
|
2003-05-19 07:08:01 +08:00
|
|
|
const GimpCoords *delta,
|
2003-05-17 00:49:04 +08:00
|
|
|
GimpAnchorFeatureType feature)
|
2002-02-25 11:16:41 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_STROKE (stroke));
|
2003-05-17 00:49:04 +08:00
|
|
|
g_return_if_fail (anchor != NULL);
|
|
|
|
g_return_if_fail (g_list_find (stroke->anchors, anchor));
|
2002-02-25 11:16:41 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
GIMP_STROKE_GET_CLASS (stroke)->anchor_move_relative (stroke, anchor,
|
|
|
|
delta, feature);
|
2002-02-25 11:16:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-05-17 00:49:04 +08:00
|
|
|
gimp_stroke_real_anchor_move_relative (GimpStroke *stroke,
|
|
|
|
GimpAnchor *anchor,
|
|
|
|
const GimpCoords *delta,
|
|
|
|
GimpAnchorFeatureType feature)
|
2002-02-25 11:16:41 +08:00
|
|
|
{
|
2003-05-17 00:49:04 +08:00
|
|
|
anchor->position.x += delta->x;
|
|
|
|
anchor->position.y += delta->y;
|
2002-02-25 11:16:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2003-05-17 00:49:04 +08:00
|
|
|
gimp_stroke_anchor_move_absolute (GimpStroke *stroke,
|
|
|
|
GimpAnchor *anchor,
|
|
|
|
const GimpCoords *coord,
|
|
|
|
GimpAnchorFeatureType feature)
|
2002-02-25 11:16:41 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_STROKE (stroke));
|
2003-05-17 00:49:04 +08:00
|
|
|
g_return_if_fail (anchor != NULL);
|
|
|
|
g_return_if_fail (g_list_find (stroke->anchors, anchor));
|
2002-02-25 11:16:41 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
GIMP_STROKE_GET_CLASS (stroke)->anchor_move_absolute (stroke, anchor,
|
|
|
|
coord, feature);
|
2002-02-25 11:16:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-05-17 00:49:04 +08:00
|
|
|
gimp_stroke_real_anchor_move_absolute (GimpStroke *stroke,
|
|
|
|
GimpAnchor *anchor,
|
|
|
|
const GimpCoords *coord,
|
|
|
|
GimpAnchorFeatureType feature)
|
2002-02-25 11:16:41 +08:00
|
|
|
{
|
2003-05-17 00:49:04 +08:00
|
|
|
anchor->position.x = coord->x;
|
|
|
|
anchor->position.y = coord->y;
|
2002-02-25 11:16:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-29 12:47:44 +08:00
|
|
|
void
|
|
|
|
gimp_stroke_anchor_convert (GimpStroke *stroke,
|
|
|
|
GimpAnchor *anchor,
|
|
|
|
GimpAnchorFeatureType feature)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_STROKE (stroke));
|
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
GIMP_STROKE_GET_CLASS (stroke)->anchor_convert (stroke, anchor, feature);
|
|
|
|
}
|
2003-03-29 12:47:44 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
static void
|
|
|
|
gimp_stroke_real_anchor_convert (GimpStroke *stroke,
|
|
|
|
GimpAnchor *anchor,
|
|
|
|
GimpAnchorFeatureType feature)
|
|
|
|
{
|
|
|
|
g_printerr ("gimp_stroke_anchor_convert: default implementation\n");
|
2003-03-29 12:47:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-25 11:16:41 +08:00
|
|
|
void
|
2003-05-17 00:49:04 +08:00
|
|
|
gimp_stroke_anchor_delete (GimpStroke *stroke,
|
|
|
|
GimpAnchor *anchor)
|
2002-02-25 11:16:41 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_STROKE (stroke));
|
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
GIMP_STROKE_GET_CLASS (stroke)->anchor_delete (stroke, anchor);
|
|
|
|
}
|
2002-02-25 11:16:41 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
static void
|
|
|
|
gimp_stroke_real_anchor_delete (GimpStroke *stroke,
|
|
|
|
GimpAnchor *anchor)
|
|
|
|
{
|
|
|
|
g_printerr ("gimp_stroke_anchor_delete: default implementation\n");
|
2002-02-25 11:16:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gdouble
|
|
|
|
gimp_stroke_get_length (const GimpStroke *stroke)
|
|
|
|
{
|
2003-05-17 00:49:04 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_STROKE (stroke), 0.0);
|
2002-02-25 11:16:41 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
return GIMP_STROKE_GET_CLASS (stroke)->get_length (stroke);
|
|
|
|
}
|
2002-02-25 11:16:41 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
static gdouble
|
|
|
|
gimp_stroke_real_get_length (const GimpStroke *stroke)
|
|
|
|
{
|
|
|
|
g_printerr ("gimp_stroke_get_length: default implementation\n");
|
2002-02-25 11:16:41 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
return 0.0;
|
2002-02-25 11:16:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gdouble
|
|
|
|
gimp_stroke_get_distance (const GimpStroke *stroke,
|
2003-05-17 00:49:04 +08:00
|
|
|
const GimpCoords *coord)
|
2002-02-25 11:16:41 +08:00
|
|
|
{
|
2003-05-17 00:49:04 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_STROKE (stroke), 0.0);
|
2002-02-25 11:16:41 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
return GIMP_STROKE_GET_CLASS (stroke)->get_distance (stroke, coord);
|
|
|
|
}
|
2002-02-25 11:16:41 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
static gdouble
|
|
|
|
gimp_stroke_real_get_distance (const GimpStroke *stroke,
|
|
|
|
const GimpCoords *coord)
|
|
|
|
{
|
|
|
|
g_printerr ("gimp_stroke_get_distance: default implementation\n");
|
2002-02-25 11:16:41 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
return 0.0;
|
2002-02-25 11:16:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-29 07:52:29 +08:00
|
|
|
GArray *
|
2003-05-17 00:49:04 +08:00
|
|
|
gimp_stroke_interpolate (const GimpStroke *stroke,
|
|
|
|
gdouble precision,
|
|
|
|
gboolean *ret_closed)
|
2002-02-25 11:16:41 +08:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_STROKE (stroke), 0);
|
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
return GIMP_STROKE_GET_CLASS (stroke)->interpolate (stroke, precision,
|
|
|
|
ret_closed);
|
|
|
|
}
|
2002-02-25 11:16:41 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
static GArray *
|
|
|
|
gimp_stroke_real_interpolate (const GimpStroke *stroke,
|
|
|
|
gdouble precision,
|
|
|
|
gboolean *ret_closed)
|
|
|
|
{
|
|
|
|
g_printerr ("gimp_stroke_interpolate: default implementation\n");
|
2002-02-25 11:16:41 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
return NULL;
|
2002-02-25 11:16:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GimpAnchor *
|
|
|
|
gimp_stroke_temp_anchor_get (const GimpStroke *stroke)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_STROKE (stroke), NULL);
|
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
return GIMP_STROKE_GET_CLASS (stroke)->temp_anchor_get (stroke);
|
|
|
|
}
|
2002-02-25 11:16:41 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
static GimpAnchor *
|
|
|
|
gimp_stroke_real_temp_anchor_get (const GimpStroke *stroke)
|
|
|
|
{
|
|
|
|
g_printerr ("gimp_stroke_temp_anchor_get: default implementation\n");
|
2002-02-25 11:16:41 +08:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GimpAnchor *
|
2003-05-17 00:49:04 +08:00
|
|
|
gimp_stroke_temp_anchor_set (GimpStroke *stroke,
|
|
|
|
const GimpCoords *coord)
|
2002-02-25 11:16:41 +08:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_STROKE (stroke), NULL);
|
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
return GIMP_STROKE_GET_CLASS (stroke)->temp_anchor_set (stroke, coord);
|
|
|
|
}
|
2002-02-25 11:16:41 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
static GimpAnchor *
|
|
|
|
gimp_stroke_real_temp_anchor_set (GimpStroke *stroke,
|
|
|
|
const GimpCoords *coord)
|
|
|
|
{
|
|
|
|
g_printerr ("gimp_stroke_temp_anchor_set: default implementation\n");
|
2002-02-25 11:16:41 +08:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gimp_stroke_temp_anchor_fix (GimpStroke *stroke)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_STROKE (stroke), FALSE);
|
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
return GIMP_STROKE_GET_CLASS (stroke)->temp_anchor_fix (stroke);
|
|
|
|
}
|
2002-02-25 11:16:41 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_stroke_real_temp_anchor_fix (GimpStroke *stroke)
|
|
|
|
{
|
|
|
|
g_printerr ("gimp_stroke_temp_anchor_fix: default implementation\n");
|
2002-02-25 11:16:41 +08:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-14 08:37:04 +08:00
|
|
|
GimpStroke *
|
|
|
|
gimp_stroke_duplicate (const GimpStroke *stroke)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_STROKE (stroke), NULL);
|
|
|
|
|
|
|
|
return (GIMP_STROKE_GET_CLASS (stroke))->duplicate (stroke);
|
|
|
|
}
|
|
|
|
|
|
|
|
GimpStroke *
|
|
|
|
gimp_stroke_real_duplicate (const GimpStroke *stroke)
|
|
|
|
{
|
|
|
|
GimpStroke *new_stroke;
|
2003-05-17 00:49:04 +08:00
|
|
|
GList *list;
|
2003-04-14 08:37:04 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
new_stroke = g_object_new (G_TYPE_FROM_INSTANCE (stroke),
|
|
|
|
"name", GIMP_OBJECT (stroke)->name,
|
|
|
|
NULL);
|
2003-04-14 08:37:04 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
new_stroke->anchors = g_list_copy (stroke->anchors);
|
2003-04-14 08:37:04 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
for (list = new_stroke->anchors; list; list = g_list_next (list))
|
2003-04-14 08:37:04 +08:00
|
|
|
{
|
2003-05-17 00:49:04 +08:00
|
|
|
GimpAnchor *new_anchor = g_new0 (GimpAnchor, 1);
|
|
|
|
|
|
|
|
*new_anchor = *((GimpAnchor *) (list->data));
|
2003-04-14 08:37:04 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
list->data = new_anchor;
|
2003-04-14 08:37:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (stroke->temp_anchor)
|
|
|
|
{
|
2003-05-17 00:49:04 +08:00
|
|
|
new_stroke->temp_anchor = g_new0 (GimpAnchor, 1);
|
|
|
|
|
2003-04-14 08:37:04 +08:00
|
|
|
*(new_stroke->temp_anchor) = *(stroke->temp_anchor);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new_stroke;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-25 11:16:41 +08:00
|
|
|
GimpStroke *
|
|
|
|
gimp_stroke_make_bezier (const GimpStroke *stroke)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_STROKE (stroke), NULL);
|
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
return GIMP_STROKE_GET_CLASS (stroke)->make_bezier (stroke);
|
|
|
|
}
|
2002-02-25 11:16:41 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
static GimpStroke *
|
|
|
|
gimp_stroke_real_make_bezier (const GimpStroke *stroke)
|
|
|
|
{
|
|
|
|
g_printerr ("gimp_stroke_make_bezier: default implementation\n");
|
2002-02-25 11:16:41 +08:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-31 00:36:01 +08:00
|
|
|
GList *
|
|
|
|
gimp_stroke_get_draw_anchors (const GimpStroke *stroke)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_STROKE (stroke), NULL);
|
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
return GIMP_STROKE_GET_CLASS (stroke)->get_draw_anchors (stroke);
|
|
|
|
}
|
2002-12-31 00:36:01 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
static GList *
|
|
|
|
gimp_stroke_real_get_draw_anchors (const GimpStroke *stroke)
|
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
GList *ret_list = NULL;
|
2002-12-31 00:36:01 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
for (list = stroke->anchors; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
if (((GimpAnchor *) list->data)->type == GIMP_ANCHOR_ANCHOR)
|
|
|
|
ret_list = g_list_prepend (ret_list, list->data);
|
2002-12-31 00:36:01 +08:00
|
|
|
}
|
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
return g_list_reverse (ret_list);
|
2002-12-31 00:36:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GList *
|
2002-12-31 11:18:49 +08:00
|
|
|
gimp_stroke_get_draw_controls (const GimpStroke *stroke)
|
2002-12-31 00:36:01 +08:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_STROKE (stroke), NULL);
|
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
return GIMP_STROKE_GET_CLASS (stroke)->get_draw_controls (stroke);
|
|
|
|
}
|
2002-12-31 00:36:01 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
static GList *
|
|
|
|
gimp_stroke_real_get_draw_controls (const GimpStroke *stroke)
|
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
GList *ret_list = NULL;
|
2002-12-31 00:36:01 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
for (list = stroke->anchors; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
GimpAnchor *anchor = list->data;
|
2002-12-31 00:36:01 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
if (anchor->type == GIMP_ANCHOR_CONTROL)
|
2002-12-31 00:36:01 +08:00
|
|
|
{
|
2003-05-17 00:49:04 +08:00
|
|
|
GimpAnchor *next = list->next ? list->next->data : NULL;
|
|
|
|
GimpAnchor *prev = list->prev ? list->prev->data : NULL;
|
|
|
|
|
|
|
|
if (next && next->type == GIMP_ANCHOR_ANCHOR && next->selected)
|
|
|
|
{
|
|
|
|
ret_list = g_list_prepend (ret_list, anchor);
|
|
|
|
}
|
|
|
|
else if (prev && prev->type == GIMP_ANCHOR_ANCHOR && prev->selected)
|
2002-12-31 00:36:01 +08:00
|
|
|
{
|
2003-05-17 00:49:04 +08:00
|
|
|
ret_list = g_list_prepend (ret_list, anchor);
|
2002-12-31 00:36:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
return g_list_reverse (ret_list);
|
2002-12-31 00:36:01 +08:00
|
|
|
}
|
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
|
2002-12-31 00:36:01 +08:00
|
|
|
GArray *
|
2002-12-31 11:18:49 +08:00
|
|
|
gimp_stroke_get_draw_lines (const GimpStroke *stroke)
|
2002-12-31 00:36:01 +08:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_STROKE (stroke), NULL);
|
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
return GIMP_STROKE_GET_CLASS (stroke)->get_draw_lines (stroke);
|
|
|
|
}
|
2002-12-31 00:36:01 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
static GArray *
|
|
|
|
gimp_stroke_real_get_draw_lines (const GimpStroke *stroke)
|
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
GArray *ret_lines = g_array_new (FALSE, FALSE, sizeof (GimpCoords));
|
2002-12-31 00:36:01 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
for (list = stroke->anchors; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
GimpAnchor *anchor = list->data;
|
2002-12-31 00:36:01 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
if (anchor->type == GIMP_ANCHOR_ANCHOR && anchor->selected)
|
2002-12-31 00:36:01 +08:00
|
|
|
{
|
2003-05-17 00:49:04 +08:00
|
|
|
if (list->next)
|
2002-12-31 00:36:01 +08:00
|
|
|
{
|
2003-05-17 00:49:04 +08:00
|
|
|
GimpAnchor *next = list->next->data;
|
2002-12-31 00:36:01 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
ret_lines = g_array_append_val (ret_lines, anchor->position);
|
|
|
|
ret_lines = g_array_append_val (ret_lines, next->position);
|
|
|
|
}
|
2002-12-31 00:36:01 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
if (list->prev)
|
|
|
|
{
|
|
|
|
GimpAnchor *prev = list->prev->data;
|
2002-12-31 00:36:01 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
ret_lines = g_array_append_val (ret_lines, anchor->position);
|
|
|
|
ret_lines = g_array_append_val (ret_lines, prev->position);
|
2002-12-31 00:36:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-02-25 11:16:41 +08:00
|
|
|
|
2003-05-17 00:49:04 +08:00
|
|
|
return ret_lines;
|
|
|
|
}
|