2002-02-22 08:11:37 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimpvectors.c
|
2002-02-25 11:16:41 +08:00
|
|
|
* Copyright (C) 2002 Simon Budig <simon@gimp.org>
|
2002-02-22 08:11:37 +08:00
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
2002-02-25 21:39:34 +08:00
|
|
|
#include "core/gimpimage.h"
|
2003-05-09 08:38:51 +08:00
|
|
|
#include "core/gimpimage-undo-push.h"
|
2003-04-14 22:46:34 +08:00
|
|
|
#include "core/gimpmarshal.h"
|
2002-02-25 21:39:34 +08:00
|
|
|
|
2002-02-25 11:16:41 +08:00
|
|
|
#include "gimpanchor.h"
|
|
|
|
#include "gimpstroke.h"
|
2002-02-22 08:11:37 +08:00
|
|
|
#include "gimpvectors.h"
|
2002-02-25 21:39:34 +08:00
|
|
|
#include "gimpvectors-preview.h"
|
2002-02-22 08:11:37 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2003-03-17 08:14:59 +08:00
|
|
|
|
2002-02-22 08:11:37 +08:00
|
|
|
|
2003-04-14 22:46:34 +08:00
|
|
|
enum
|
|
|
|
{
|
2003-05-09 08:38:51 +08:00
|
|
|
FREEZE,
|
|
|
|
THAW,
|
2003-04-14 22:46:34 +08:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-05-09 08:38:51 +08:00
|
|
|
static void gimp_vectors_class_init (GimpVectorsClass *klass);
|
|
|
|
static void gimp_vectors_init (GimpVectors *vectors);
|
2002-02-22 08:11:37 +08:00
|
|
|
|
2003-05-09 08:38:51 +08:00
|
|
|
static void gimp_vectors_finalize (GObject *object);
|
2002-02-22 08:11:37 +08:00
|
|
|
|
2003-05-09 08:38:51 +08:00
|
|
|
static gsize gimp_vectors_get_memsize (GimpObject *object);
|
2003-02-11 21:52:47 +08:00
|
|
|
|
2003-05-09 08:38:51 +08:00
|
|
|
static GimpItem * gimp_vectors_duplicate (GimpItem *item,
|
|
|
|
GType new_type,
|
|
|
|
gboolean add_alpha);
|
|
|
|
static void gimp_vectors_translate (GimpItem *item,
|
|
|
|
gint offset_x,
|
2003-05-09 21:05:37 +08:00
|
|
|
gint offset_y,
|
|
|
|
gboolean push_undo);
|
2003-05-09 08:38:51 +08:00
|
|
|
static void gimp_vectors_scale (GimpItem *item,
|
|
|
|
gint new_width,
|
|
|
|
gint new_height,
|
|
|
|
gint new_offset_x,
|
|
|
|
gint new_offset_y,
|
|
|
|
GimpInterpolationType interp_type);
|
|
|
|
static void gimp_vectors_resize (GimpItem *item,
|
|
|
|
gint new_width,
|
|
|
|
gint new_height,
|
|
|
|
gint offset_x,
|
|
|
|
gint offset_y);
|
2003-05-12 23:56:36 +08:00
|
|
|
static void gimp_vectors_flip (GimpItem *item,
|
|
|
|
GimpOrientationType flip_type,
|
|
|
|
gdouble axis);
|
|
|
|
static void gimp_vectors_transform (GimpItem *item,
|
|
|
|
GimpMatrix3 matrix,
|
|
|
|
GimpTransformDirection direction,
|
|
|
|
GimpInterpolationType interp_type,
|
|
|
|
gboolean clip_result,
|
|
|
|
GimpProgressFunc progress_callback,
|
|
|
|
gpointer progress_data);
|
2003-05-09 08:38:51 +08:00
|
|
|
|
2003-05-12 23:56:36 +08:00
|
|
|
static void gimp_vectors_real_thaw (GimpVectors *vectors);
|
2002-02-22 08:11:37 +08:00
|
|
|
|
|
|
|
|
2003-02-01 02:08:32 +08:00
|
|
|
/* private variables */
|
2002-02-25 11:16:41 +08:00
|
|
|
|
2003-04-14 22:46:34 +08:00
|
|
|
static guint gimp_vectors_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2003-02-01 02:08:32 +08:00
|
|
|
static GimpItemClass *parent_class = NULL;
|
2002-02-25 21:39:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
GType
|
|
|
|
gimp_vectors_get_type (void)
|
2002-02-22 08:11:37 +08:00
|
|
|
{
|
2002-02-25 21:39:34 +08:00
|
|
|
static GType vectors_type = 0;
|
2002-02-22 08:11:37 +08:00
|
|
|
|
2002-02-25 21:39:34 +08:00
|
|
|
if (! vectors_type)
|
|
|
|
{
|
|
|
|
static const GTypeInfo vectors_info =
|
|
|
|
{
|
|
|
|
sizeof (GimpVectorsClass),
|
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_vectors_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpVectors),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_vectors_init,
|
|
|
|
};
|
|
|
|
|
2002-02-26 01:58:50 +08:00
|
|
|
vectors_type = g_type_register_static (GIMP_TYPE_ITEM,
|
2002-02-25 21:39:34 +08:00
|
|
|
"GimpVectors",
|
|
|
|
&vectors_info, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return vectors_type;
|
|
|
|
}
|
2002-02-22 08:11:37 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_vectors_class_init (GimpVectorsClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class;
|
|
|
|
GimpObjectClass *gimp_object_class;
|
|
|
|
GimpViewableClass *viewable_class;
|
2003-02-11 21:52:47 +08:00
|
|
|
GimpItemClass *item_class;
|
2002-02-22 08:11:37 +08:00
|
|
|
|
|
|
|
object_class = G_OBJECT_CLASS (klass);
|
|
|
|
gimp_object_class = GIMP_OBJECT_CLASS (klass);
|
|
|
|
viewable_class = GIMP_VIEWABLE_CLASS (klass);
|
2003-02-11 21:52:47 +08:00
|
|
|
item_class = GIMP_ITEM_CLASS (klass);
|
2002-02-22 08:11:37 +08:00
|
|
|
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
|
2003-05-09 08:38:51 +08:00
|
|
|
gimp_vectors_signals[FREEZE] =
|
|
|
|
g_signal_new ("freeze",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpVectorsClass, freeze),
|
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
|
|
gimp_vectors_signals[THAW] =
|
|
|
|
g_signal_new ("thaw",
|
2003-04-14 22:46:34 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
2003-05-09 08:38:51 +08:00
|
|
|
G_STRUCT_OFFSET (GimpVectorsClass, thaw),
|
2003-04-14 22:46:34 +08:00
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
2003-02-01 02:08:32 +08:00
|
|
|
object_class->finalize = gimp_vectors_finalize;
|
2002-02-22 08:11:37 +08:00
|
|
|
|
2003-02-01 02:08:32 +08:00
|
|
|
gimp_object_class->get_memsize = gimp_vectors_get_memsize;
|
2002-02-22 08:11:37 +08:00
|
|
|
|
2003-02-01 02:08:32 +08:00
|
|
|
viewable_class->get_new_preview = gimp_vectors_get_new_preview;
|
2002-02-25 21:39:34 +08:00
|
|
|
|
2003-02-11 21:52:47 +08:00
|
|
|
item_class->duplicate = gimp_vectors_duplicate;
|
2003-05-09 08:38:51 +08:00
|
|
|
item_class->translate = gimp_vectors_translate;
|
2003-05-07 19:09:00 +08:00
|
|
|
item_class->scale = gimp_vectors_scale;
|
2003-05-07 22:45:26 +08:00
|
|
|
item_class->resize = gimp_vectors_resize;
|
2003-05-12 23:56:36 +08:00
|
|
|
item_class->flip = gimp_vectors_flip;
|
|
|
|
item_class->transform = gimp_vectors_transform;
|
2003-03-17 08:14:59 +08:00
|
|
|
item_class->default_name = _("Path");
|
|
|
|
item_class->rename_desc = _("Rename Path");
|
2003-02-11 21:52:47 +08:00
|
|
|
|
2003-05-09 08:38:51 +08:00
|
|
|
klass->freeze = NULL;
|
|
|
|
klass->thaw = gimp_vectors_real_thaw;
|
2002-02-22 08:11:37 +08:00
|
|
|
|
2003-02-01 02:08:32 +08:00
|
|
|
klass->stroke_add = NULL;
|
|
|
|
klass->stroke_get = NULL;
|
|
|
|
klass->stroke_get_next = NULL;
|
|
|
|
klass->stroke_get_length = NULL;
|
2002-02-25 11:16:41 +08:00
|
|
|
|
2003-02-01 02:08:32 +08:00
|
|
|
klass->anchor_get = NULL;
|
2002-02-22 08:11:37 +08:00
|
|
|
|
2003-02-01 02:08:32 +08:00
|
|
|
klass->get_length = NULL;
|
|
|
|
klass->get_distance = NULL;
|
|
|
|
klass->interpolate = NULL;
|
2002-02-22 08:11:37 +08:00
|
|
|
|
2003-02-01 02:08:32 +08:00
|
|
|
klass->make_bezier = NULL;
|
2002-02-22 08:11:37 +08:00
|
|
|
}
|
|
|
|
|
2002-02-25 21:39:34 +08:00
|
|
|
static void
|
|
|
|
gimp_vectors_init (GimpVectors *vectors)
|
2002-02-22 08:11:37 +08:00
|
|
|
{
|
2003-05-09 08:38:51 +08:00
|
|
|
vectors->strokes = NULL;
|
|
|
|
vectors->freeze_count = 0;
|
2002-02-25 21:39:34 +08:00
|
|
|
};
|
2002-02-22 08:11:37 +08:00
|
|
|
|
2002-02-25 21:39:34 +08:00
|
|
|
static void
|
|
|
|
gimp_vectors_finalize (GObject *object)
|
|
|
|
{
|
2003-05-09 08:38:51 +08:00
|
|
|
GimpVectors *vectors;
|
|
|
|
|
|
|
|
vectors = GIMP_VECTORS (object);
|
|
|
|
|
2003-02-01 02:08:32 +08:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#warning FIXME: implement gimp_vectors_finalize()
|
|
|
|
#endif
|
|
|
|
|
2002-02-25 21:39:34 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
2002-02-22 08:11:37 +08:00
|
|
|
|
2003-02-01 02:08:32 +08:00
|
|
|
static gsize
|
|
|
|
gimp_vectors_get_memsize (GimpObject *object)
|
|
|
|
{
|
|
|
|
GimpVectors *vectors;
|
2003-04-14 22:46:34 +08:00
|
|
|
GList *list;
|
2003-02-01 02:08:32 +08:00
|
|
|
gsize memsize = 0;
|
|
|
|
|
|
|
|
vectors = GIMP_VECTORS (object);
|
|
|
|
|
2003-04-14 22:46:34 +08:00
|
|
|
for (list = vectors->strokes; list; list = g_list_next (list))
|
|
|
|
memsize += (gimp_object_get_memsize (GIMP_OBJECT (list->data)) +
|
|
|
|
sizeof (GList));
|
2003-02-01 02:08:32 +08:00
|
|
|
|
|
|
|
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object);
|
|
|
|
}
|
|
|
|
|
2003-04-14 08:37:04 +08:00
|
|
|
|
2003-02-11 21:52:47 +08:00
|
|
|
static GimpItem *
|
|
|
|
gimp_vectors_duplicate (GimpItem *item,
|
|
|
|
GType new_type,
|
|
|
|
gboolean add_alpha)
|
|
|
|
{
|
|
|
|
GimpVectors *vectors;
|
|
|
|
GimpItem *new_item;
|
|
|
|
GimpVectors *new_vectors;
|
|
|
|
|
|
|
|
g_return_val_if_fail (g_type_is_a (new_type, GIMP_TYPE_VECTORS), NULL);
|
|
|
|
|
|
|
|
new_item = GIMP_ITEM_CLASS (parent_class)->duplicate (item, new_type,
|
|
|
|
add_alpha);
|
|
|
|
|
|
|
|
if (! GIMP_IS_VECTORS (new_item))
|
|
|
|
return new_item;
|
|
|
|
|
|
|
|
vectors = GIMP_VECTORS (item);
|
|
|
|
new_vectors = GIMP_VECTORS (new_item);
|
|
|
|
|
|
|
|
gimp_vectors_copy_strokes (vectors, new_vectors);
|
|
|
|
|
2003-04-14 22:46:34 +08:00
|
|
|
return new_item;
|
2003-02-11 21:52:47 +08:00
|
|
|
}
|
|
|
|
|
2003-05-09 08:38:51 +08:00
|
|
|
static void
|
|
|
|
gimp_vectors_translate (GimpItem *item,
|
|
|
|
gint offset_x,
|
2003-05-09 21:05:37 +08:00
|
|
|
gint offset_y,
|
|
|
|
gboolean push_undo)
|
2003-05-09 08:38:51 +08:00
|
|
|
{
|
|
|
|
GimpVectors *vectors;
|
2003-05-09 21:05:37 +08:00
|
|
|
GList *list;
|
2003-05-09 08:38:51 +08:00
|
|
|
|
|
|
|
vectors = GIMP_VECTORS (item);
|
|
|
|
|
|
|
|
gimp_vectors_freeze (vectors);
|
|
|
|
|
2003-05-09 21:05:37 +08:00
|
|
|
if (push_undo)
|
|
|
|
gimp_image_undo_push_vectors_mod (gimp_item_get_image (item),
|
|
|
|
_("Move Path"),
|
|
|
|
vectors);
|
|
|
|
|
|
|
|
for (list = vectors->strokes; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
GimpStroke *stroke = list->data;
|
|
|
|
GList *list2;
|
|
|
|
|
|
|
|
for (list2 = stroke->anchors; list2; list2 = g_list_next (list2))
|
|
|
|
{
|
|
|
|
GimpAnchor *anchor = list2->data;
|
|
|
|
|
|
|
|
anchor->position.x += offset_x;
|
|
|
|
anchor->position.y += offset_y;
|
|
|
|
}
|
|
|
|
}
|
2003-05-09 08:38:51 +08:00
|
|
|
|
|
|
|
gimp_vectors_thaw (vectors);
|
|
|
|
}
|
|
|
|
|
2003-05-07 19:09:00 +08:00
|
|
|
static void
|
|
|
|
gimp_vectors_scale (GimpItem *item,
|
|
|
|
gint new_width,
|
|
|
|
gint new_height,
|
|
|
|
gint new_offset_x,
|
|
|
|
gint new_offset_y,
|
2003-05-09 08:38:51 +08:00
|
|
|
GimpInterpolationType interpolation_type)
|
2003-05-07 19:09:00 +08:00
|
|
|
{
|
2003-05-09 08:38:51 +08:00
|
|
|
GimpVectors *vectors;
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
vectors = GIMP_VECTORS (item);
|
|
|
|
|
|
|
|
gimp_vectors_freeze (vectors);
|
|
|
|
|
|
|
|
gimp_image_undo_push_vectors_mod (gimp_item_get_image (item),
|
|
|
|
_("Scale Path"),
|
|
|
|
vectors);
|
|
|
|
|
|
|
|
for (list = vectors->strokes; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
GimpStroke *stroke = list->data;
|
|
|
|
GList *list2;
|
|
|
|
|
|
|
|
for (list2 = stroke->anchors; list2; list2 = g_list_next (list2))
|
|
|
|
{
|
|
|
|
GimpAnchor *anchor = list2->data;
|
|
|
|
|
|
|
|
anchor->position.x *= (gdouble) new_width / (gdouble) item->width;
|
|
|
|
anchor->position.y *= (gdouble) new_height / (gdouble) item->height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GIMP_ITEM_CLASS (parent_class)->scale (item, new_width, new_height,
|
|
|
|
new_offset_x, new_offset_y,
|
|
|
|
interpolation_type);
|
|
|
|
|
|
|
|
gimp_vectors_thaw (vectors);
|
2003-05-07 19:09:00 +08:00
|
|
|
}
|
|
|
|
|
2003-05-07 22:45:26 +08:00
|
|
|
static void
|
|
|
|
gimp_vectors_resize (GimpItem *item,
|
|
|
|
gint new_width,
|
|
|
|
gint new_height,
|
|
|
|
gint offset_x,
|
|
|
|
gint offset_y)
|
|
|
|
{
|
2003-05-09 08:38:51 +08:00
|
|
|
GimpVectors *vectors;
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
vectors = GIMP_VECTORS (item);
|
|
|
|
|
|
|
|
gimp_vectors_freeze (vectors);
|
|
|
|
|
|
|
|
gimp_image_undo_push_vectors_mod (gimp_item_get_image (item),
|
|
|
|
_("Resize Path"),
|
|
|
|
vectors);
|
|
|
|
|
|
|
|
for (list = vectors->strokes; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
GimpStroke *stroke = list->data;
|
|
|
|
GList *list2;
|
|
|
|
|
|
|
|
for (list2 = stroke->anchors; list2; list2 = g_list_next (list2))
|
|
|
|
{
|
|
|
|
GimpAnchor *anchor = list2->data;
|
|
|
|
|
|
|
|
anchor->position.x += offset_x;
|
|
|
|
anchor->position.y += offset_y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GIMP_ITEM_CLASS (parent_class)->resize (item, new_width, new_height,
|
|
|
|
offset_x, offset_y);
|
|
|
|
|
|
|
|
gimp_vectors_thaw (vectors);
|
|
|
|
}
|
|
|
|
|
2003-05-12 23:56:36 +08:00
|
|
|
static void
|
|
|
|
gimp_vectors_flip (GimpItem *item,
|
|
|
|
GimpOrientationType flip_type,
|
|
|
|
gdouble axis)
|
|
|
|
{
|
|
|
|
GimpVectors *vectors;
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
vectors = GIMP_VECTORS (item);
|
|
|
|
|
|
|
|
gimp_vectors_freeze (vectors);
|
|
|
|
|
|
|
|
gimp_image_undo_push_vectors_mod (gimp_item_get_image (item),
|
|
|
|
_("Flip Path"),
|
|
|
|
vectors);
|
|
|
|
|
|
|
|
for (list = vectors->strokes; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
GimpStroke *stroke = list->data;
|
|
|
|
GList *list2;
|
|
|
|
|
|
|
|
for (list2 = stroke->anchors; list2; list2 = g_list_next (list2))
|
|
|
|
{
|
|
|
|
GimpAnchor *anchor = list2->data;
|
|
|
|
|
|
|
|
switch (flip_type)
|
|
|
|
{
|
|
|
|
case GIMP_ORIENTATION_HORIZONTAL:
|
|
|
|
anchor->position.x = -(anchor->position.x - axis) + axis;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_ORIENTATION_VERTICAL:
|
|
|
|
anchor->position.y = -(anchor->position.y - axis) + axis;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_vectors_thaw (vectors);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_vectors_transform (GimpItem *item,
|
|
|
|
GimpMatrix3 matrix,
|
|
|
|
GimpTransformDirection direction,
|
|
|
|
GimpInterpolationType interpolation_type,
|
|
|
|
gboolean clip_result,
|
|
|
|
GimpProgressFunc progress_callback,
|
|
|
|
gpointer progress_data)
|
|
|
|
{
|
|
|
|
GimpVectors *vectors;
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
vectors = GIMP_VECTORS (item);
|
|
|
|
|
|
|
|
gimp_vectors_freeze (vectors);
|
|
|
|
|
|
|
|
gimp_image_undo_push_vectors_mod (gimp_item_get_image (item),
|
|
|
|
_("Transform Path"),
|
|
|
|
vectors);
|
|
|
|
|
|
|
|
for (list = vectors->strokes; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
GimpStroke *stroke = list->data;
|
|
|
|
GList *list2;
|
|
|
|
|
|
|
|
for (list2 = stroke->anchors; list2; list2 = g_list_next (list2))
|
|
|
|
{
|
|
|
|
GimpAnchor *anchor = list2->data;
|
|
|
|
|
|
|
|
gimp_matrix3_transform_point (matrix,
|
|
|
|
anchor->position.x,
|
|
|
|
anchor->position.y,
|
|
|
|
&anchor->position.x,
|
|
|
|
&anchor->position.y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_vectors_thaw (vectors);
|
|
|
|
}
|
|
|
|
|
2003-05-09 08:38:51 +08:00
|
|
|
static void
|
|
|
|
gimp_vectors_real_thaw (GimpVectors *vectors)
|
|
|
|
{
|
|
|
|
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (vectors));
|
2003-05-07 22:45:26 +08:00
|
|
|
}
|
|
|
|
|
2003-02-01 02:08:32 +08:00
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
GimpVectors *
|
|
|
|
gimp_vectors_new (GimpImage *gimage,
|
|
|
|
const gchar *name)
|
|
|
|
{
|
|
|
|
GimpVectors *vectors;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
|
|
|
|
|
|
|
|
vectors = g_object_new (GIMP_TYPE_VECTORS, NULL);
|
|
|
|
|
2003-05-08 22:21:39 +08:00
|
|
|
gimp_item_configure (GIMP_ITEM (vectors), gimage,
|
|
|
|
0, 0, gimage->width, gimage->height,
|
|
|
|
name);
|
2003-02-01 02:08:32 +08:00
|
|
|
|
|
|
|
return vectors;
|
|
|
|
}
|
|
|
|
|
2003-05-09 08:38:51 +08:00
|
|
|
void
|
|
|
|
gimp_vectors_freeze (GimpVectors *vectors)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_VECTORS (vectors));
|
|
|
|
|
|
|
|
vectors->freeze_count++;
|
|
|
|
|
|
|
|
if (vectors->freeze_count == 1)
|
|
|
|
g_signal_emit (vectors, gimp_vectors_signals[FREEZE], 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_vectors_thaw (GimpVectors *vectors)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_VECTORS (vectors));
|
|
|
|
g_return_if_fail (vectors->freeze_count > 0);
|
|
|
|
|
|
|
|
vectors->freeze_count--;
|
|
|
|
|
|
|
|
if (vectors->freeze_count == 0)
|
|
|
|
g_signal_emit (vectors, gimp_vectors_signals[THAW], 0);
|
|
|
|
}
|
2003-04-14 08:37:04 +08:00
|
|
|
|
2003-02-01 02:08:32 +08:00
|
|
|
void
|
|
|
|
gimp_vectors_copy_strokes (const GimpVectors *src_vectors,
|
|
|
|
GimpVectors *dest_vectors)
|
|
|
|
{
|
2003-04-14 08:37:04 +08:00
|
|
|
GList *current_lstroke;
|
|
|
|
|
2003-02-01 02:08:32 +08:00
|
|
|
g_return_if_fail (GIMP_IS_VECTORS (src_vectors));
|
|
|
|
g_return_if_fail (GIMP_IS_VECTORS (dest_vectors));
|
2003-05-09 08:38:51 +08:00
|
|
|
|
|
|
|
gimp_vectors_freeze (dest_vectors);
|
|
|
|
|
|
|
|
if (dest_vectors->strokes)
|
|
|
|
{
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#warning FIXME: free old dest_vectors->strokes
|
|
|
|
#endif
|
|
|
|
}
|
2003-02-01 02:08:32 +08:00
|
|
|
|
2003-04-14 08:37:04 +08:00
|
|
|
dest_vectors->strokes = g_list_copy (src_vectors->strokes);
|
|
|
|
current_lstroke = dest_vectors->strokes;
|
|
|
|
|
|
|
|
while (current_lstroke)
|
|
|
|
{
|
|
|
|
current_lstroke->data = gimp_stroke_duplicate (current_lstroke->data);
|
|
|
|
current_lstroke = g_list_next (current_lstroke);
|
|
|
|
}
|
2003-05-09 08:38:51 +08:00
|
|
|
|
|
|
|
gimp_vectors_thaw (dest_vectors);
|
2003-02-01 02:08:32 +08:00
|
|
|
}
|
|
|
|
|
2002-02-22 08:11:37 +08:00
|
|
|
|
|
|
|
/* Calling the virtual functions */
|
|
|
|
|
|
|
|
GimpAnchor *
|
|
|
|
gimp_vectors_anchor_get (const GimpVectors *vectors,
|
2002-02-26 00:57:19 +08:00
|
|
|
const GimpCoords *coord,
|
|
|
|
GimpStroke **ret_stroke)
|
2002-02-22 08:11:37 +08:00
|
|
|
{
|
|
|
|
GimpVectorsClass *vectors_class;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_VECTORS (vectors), NULL);
|
|
|
|
|
|
|
|
vectors_class = GIMP_VECTORS_GET_CLASS (vectors);
|
|
|
|
|
|
|
|
if (vectors_class->anchor_get)
|
2002-02-26 00:57:19 +08:00
|
|
|
return vectors_class->anchor_get (vectors, coord, ret_stroke);
|
2002-02-22 08:11:37 +08:00
|
|
|
else
|
2002-02-25 11:16:41 +08:00
|
|
|
{
|
|
|
|
gdouble dx, dy, mindist;
|
2003-04-14 08:37:04 +08:00
|
|
|
GList *stroke;
|
2002-02-25 11:16:41 +08:00
|
|
|
GimpAnchor *anchor = NULL, *minanchor = NULL;
|
|
|
|
|
|
|
|
mindist = -1;
|
|
|
|
|
2003-04-14 08:37:04 +08:00
|
|
|
for (stroke = vectors->strokes; stroke; stroke = g_list_next (stroke))
|
2002-02-25 11:16:41 +08:00
|
|
|
{
|
2003-04-14 08:37:04 +08:00
|
|
|
anchor = gimp_stroke_anchor_get (GIMP_STROKE (stroke->data), coord);
|
2002-02-25 11:16:41 +08:00
|
|
|
if (anchor)
|
|
|
|
{
|
|
|
|
dx = coord->x - anchor->position.x;
|
|
|
|
dy = coord->y - anchor->position.y;
|
|
|
|
if (mindist > dx * dx + dy * dy || mindist < 0)
|
|
|
|
{
|
|
|
|
mindist = dx * dx + dy * dy;
|
|
|
|
minanchor = anchor;
|
2002-02-26 00:57:19 +08:00
|
|
|
if (ret_stroke)
|
2003-04-14 08:37:04 +08:00
|
|
|
*ret_stroke = stroke->data;
|
2002-02-25 11:16:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return minanchor;
|
|
|
|
}
|
2002-02-22 08:11:37 +08:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-25 11:16:41 +08:00
|
|
|
void
|
|
|
|
gimp_vectors_stroke_add (GimpVectors *vectors,
|
|
|
|
GimpStroke *stroke)
|
|
|
|
{
|
|
|
|
GimpVectorsClass *vectors_class;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_VECTORS (vectors));
|
|
|
|
g_return_if_fail (GIMP_IS_STROKE (stroke));
|
|
|
|
|
|
|
|
vectors_class = GIMP_VECTORS_GET_CLASS (vectors);
|
|
|
|
|
2003-05-09 08:38:51 +08:00
|
|
|
gimp_vectors_freeze (vectors);
|
|
|
|
|
2002-02-25 11:16:41 +08:00
|
|
|
if (vectors_class->stroke_add)
|
2002-02-26 00:57:19 +08:00
|
|
|
{
|
|
|
|
vectors_class->stroke_add (vectors, stroke);
|
|
|
|
}
|
2002-02-25 11:16:41 +08:00
|
|
|
else
|
|
|
|
{
|
2003-04-14 08:37:04 +08:00
|
|
|
vectors->strokes = g_list_prepend (vectors->strokes, stroke);
|
2003-01-06 06:07:10 +08:00
|
|
|
g_object_ref (stroke);
|
2002-02-25 11:16:41 +08:00
|
|
|
}
|
2003-05-09 08:38:51 +08:00
|
|
|
|
|
|
|
gimp_vectors_thaw (vectors);
|
2002-02-25 11:16:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-22 08:11:37 +08:00
|
|
|
GimpStroke *
|
|
|
|
gimp_vectors_stroke_get (const GimpVectors *vectors,
|
2002-02-25 11:16:41 +08:00
|
|
|
const GimpCoords *coord)
|
2002-02-22 08:11:37 +08:00
|
|
|
{
|
|
|
|
GimpVectorsClass *vectors_class;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_VECTORS (vectors), NULL);
|
|
|
|
|
|
|
|
vectors_class = GIMP_VECTORS_GET_CLASS (vectors);
|
|
|
|
|
|
|
|
if (vectors_class->stroke_get)
|
|
|
|
return vectors_class->stroke_get (vectors, coord);
|
|
|
|
else
|
2002-02-25 11:16:41 +08:00
|
|
|
{
|
|
|
|
gdouble dx, dy, mindist;
|
2003-04-14 08:37:04 +08:00
|
|
|
GList *stroke;
|
2002-02-25 11:16:41 +08:00
|
|
|
GimpStroke *minstroke = NULL;
|
|
|
|
GimpAnchor *anchor = NULL;
|
|
|
|
|
|
|
|
mindist = -1;
|
2003-04-14 08:37:04 +08:00
|
|
|
stroke = vectors->strokes;
|
2002-02-25 11:16:41 +08:00
|
|
|
|
2002-02-26 00:57:19 +08:00
|
|
|
while (stroke)
|
2002-02-25 11:16:41 +08:00
|
|
|
{
|
2003-04-14 08:37:04 +08:00
|
|
|
anchor = gimp_stroke_anchor_get (stroke->data, coord);
|
2002-02-25 11:16:41 +08:00
|
|
|
if (anchor)
|
|
|
|
{
|
|
|
|
dx = coord->x - anchor->position.x;
|
|
|
|
dy = coord->y - anchor->position.y;
|
|
|
|
if (mindist > dx * dx + dy * dy || mindist < 0)
|
|
|
|
{
|
|
|
|
mindist = dx * dx + dy * dy;
|
2003-04-14 08:37:04 +08:00
|
|
|
minstroke = GIMP_STROKE (stroke->data);
|
2002-02-25 11:16:41 +08:00
|
|
|
}
|
|
|
|
}
|
2003-04-14 08:37:04 +08:00
|
|
|
stroke = g_list_next (stroke);
|
2002-02-25 11:16:41 +08:00
|
|
|
}
|
|
|
|
return minstroke;
|
|
|
|
}
|
2002-02-22 08:11:37 +08:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GimpStroke *
|
|
|
|
gimp_vectors_stroke_get_next (const GimpVectors *vectors,
|
|
|
|
const GimpStroke *prev)
|
|
|
|
{
|
|
|
|
GimpVectorsClass *vectors_class;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_VECTORS (vectors), NULL);
|
|
|
|
|
|
|
|
vectors_class = GIMP_VECTORS_GET_CLASS (vectors);
|
|
|
|
|
|
|
|
if (vectors_class->stroke_get_next)
|
|
|
|
return vectors_class->stroke_get_next (vectors, prev);
|
|
|
|
else
|
2002-02-25 11:16:41 +08:00
|
|
|
{
|
2002-02-26 00:57:19 +08:00
|
|
|
if (!prev)
|
|
|
|
{
|
2003-04-14 22:46:34 +08:00
|
|
|
return vectors->strokes ? vectors->strokes->data : NULL;
|
2002-02-26 00:57:19 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-04-14 08:37:04 +08:00
|
|
|
GList *stroke;
|
|
|
|
stroke = g_list_find (vectors->strokes, prev);
|
|
|
|
g_return_val_if_fail (stroke != NULL, NULL);
|
|
|
|
return stroke->next ? GIMP_STROKE (stroke->next->data) : NULL;
|
2002-02-25 11:16:41 +08:00
|
|
|
}
|
|
|
|
}
|
2002-02-22 08:11:37 +08:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gdouble
|
|
|
|
gimp_vectors_stroke_get_length (const GimpVectors *vectors,
|
|
|
|
const GimpStroke *prev)
|
|
|
|
{
|
|
|
|
GimpVectorsClass *vectors_class;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_VECTORS (vectors), 0);
|
|
|
|
|
|
|
|
vectors_class = GIMP_VECTORS_GET_CLASS (vectors);
|
|
|
|
|
|
|
|
if (vectors_class->stroke_get_length)
|
|
|
|
return vectors_class->stroke_get_length (vectors, prev);
|
|
|
|
else
|
|
|
|
g_printerr ("gimp_vectors_stroke_get_length: default implementation\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gdouble
|
|
|
|
gimp_vectors_get_length (const GimpVectors *vectors,
|
|
|
|
const GimpAnchor *start)
|
|
|
|
{
|
|
|
|
GimpVectorsClass *vectors_class;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_VECTORS (vectors), 0);
|
|
|
|
|
|
|
|
vectors_class = GIMP_VECTORS_GET_CLASS (vectors);
|
|
|
|
|
|
|
|
if (vectors_class->get_length)
|
|
|
|
return vectors_class->get_length (vectors, start);
|
|
|
|
else
|
|
|
|
g_printerr ("gimp_vectors_get_length: default implementation\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gdouble
|
|
|
|
gimp_vectors_get_distance (const GimpVectors *vectors,
|
|
|
|
const GimpCoords *coord)
|
|
|
|
{
|
|
|
|
GimpVectorsClass *vectors_class;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_VECTORS (vectors), 0);
|
|
|
|
|
|
|
|
vectors_class = GIMP_VECTORS_GET_CLASS (vectors);
|
|
|
|
|
|
|
|
if (vectors_class->get_distance)
|
|
|
|
return vectors_class->get_distance (vectors, coord);
|
|
|
|
else
|
|
|
|
g_printerr ("gimp_vectors_get_distance: default implementation\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gint
|
|
|
|
gimp_vectors_interpolate (const GimpVectors *vectors,
|
|
|
|
const GimpStroke *stroke,
|
|
|
|
const gdouble precision,
|
|
|
|
const gint max_points,
|
|
|
|
GimpCoords *ret_coords)
|
|
|
|
{
|
|
|
|
GimpVectorsClass *vectors_class;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_VECTORS (vectors), 0);
|
|
|
|
|
|
|
|
vectors_class = GIMP_VECTORS_GET_CLASS (vectors);
|
|
|
|
|
|
|
|
if (vectors_class->interpolate)
|
|
|
|
return vectors_class->interpolate (vectors, stroke, precision, max_points, ret_coords);
|
|
|
|
else
|
|
|
|
g_printerr ("gimp_vectors_interpolate: default implementation\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GimpVectors *
|
|
|
|
gimp_vectors_make_bezier (const GimpVectors *vectors)
|
|
|
|
{
|
|
|
|
GimpVectorsClass *vectors_class;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_VECTORS (vectors), NULL);
|
|
|
|
|
|
|
|
vectors_class = GIMP_VECTORS_GET_CLASS (vectors);
|
|
|
|
|
|
|
|
if (vectors_class->make_bezier)
|
|
|
|
return vectors_class->make_bezier (vectors);
|
|
|
|
else
|
|
|
|
g_printerr ("gimp_vectors_make_bezier: default implementation\n");
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|