gimp/app/vectors/gimpvectors.c

1066 lines
32 KiB
C
Raw Normal View History

/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpvectors.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 "libgimpcolor/gimpcolor.h"
#include "vectors-types.h"
#include "core/gimp.h"
#include "core/gimpcontainer.h"
#include "core/gimpcontext.h"
#include "core/gimpdrawable-stroke.h"
#include "core/gimp-transform-utils.h"
#include "core/gimpimage.h"
#include "core/gimpimage-undo-push.h"
#include "core/gimpmarshal.h"
added new virtual function GimpItem::stroke(). 2003-09-01 Michael Natterer <mitch@gimp.org> * app/core/gimpitem.[ch]: added new virtual function GimpItem::stroke(). * app/core/gimpchannel.c * app/vectors/gimpvectors.c: implement GimpItem::stroke(). * app/core/gimpimage-mask.[ch] (gimp_image_mask_stroke): changed signature to match gimp_item_stroke() (the selection mask *really* should be a GimpChannel subclass). Removed global variable "gboolean gimp_image_mask_stroking"... * app/core/gimpimage.[ch]: ...and added "gboolean mask_stroking" to the GimpImage struct. * app/gui/vectors-commands.[ch]: removed vectors_stroke_vectors(). * app/widgets/widgets-types.h: removed GimpStrokeItemFunc typedef. * app/widgets/gimpvectorstreeview.[ch]: removed "stroke_item_func" member and use gimp_item_stroke() instead. * app/gui/dialogs-constructors.c (dialogs_vectors_list_view_new) * app/gui/edit-commands.c (edit_stroke_cmd_callback) * app/gui/vectors-commands. (vectors_stroke_cmd_callback) * app/widgets/gimpselectioneditor.c (gimp_selection_editor_stroke_clicked) * tools/pdbgen/pdb/edit.pdb (gimp_edit_stroke): changed accordingly. * app/pdb/edit_cmds.c: regenerated. Note that there is no GUI for "stroke channel", although it would be utterly cool to have one, since currently slelection stroking cannot be masked by a selection (because we stroke the selection). Anyway, if anyone has an idea how to trigger "stroke channel" with another drawable active (the one to stroke to), please let me know...
2003-09-02 01:56:44 +08:00
#include "core/gimppaintinfo.h"
#include "core/gimpstrokeoptions.h"
added new virtual function GimpItem::stroke(). 2003-09-01 Michael Natterer <mitch@gimp.org> * app/core/gimpitem.[ch]: added new virtual function GimpItem::stroke(). * app/core/gimpchannel.c * app/vectors/gimpvectors.c: implement GimpItem::stroke(). * app/core/gimpimage-mask.[ch] (gimp_image_mask_stroke): changed signature to match gimp_item_stroke() (the selection mask *really* should be a GimpChannel subclass). Removed global variable "gboolean gimp_image_mask_stroking"... * app/core/gimpimage.[ch]: ...and added "gboolean mask_stroking" to the GimpImage struct. * app/gui/vectors-commands.[ch]: removed vectors_stroke_vectors(). * app/widgets/widgets-types.h: removed GimpStrokeItemFunc typedef. * app/widgets/gimpvectorstreeview.[ch]: removed "stroke_item_func" member and use gimp_item_stroke() instead. * app/gui/dialogs-constructors.c (dialogs_vectors_list_view_new) * app/gui/edit-commands.c (edit_stroke_cmd_callback) * app/gui/vectors-commands. (vectors_stroke_cmd_callback) * app/widgets/gimpselectioneditor.c (gimp_selection_editor_stroke_clicked) * tools/pdbgen/pdb/edit.pdb (gimp_edit_stroke): changed accordingly. * app/pdb/edit_cmds.c: regenerated. Note that there is no GUI for "stroke channel", although it would be utterly cool to have one, since currently slelection stroking cannot be masked by a selection (because we stroke the selection). Anyway, if anyone has an idea how to trigger "stroke channel" with another drawable active (the one to stroke to), please let me know...
2003-09-02 01:56:44 +08:00
#include "paint/gimppaintcore-stroke.h"
#include "paint/gimppaintoptions.h"
#include "gimpanchor.h"
#include "gimpstroke.h"
#include "gimpvectors.h"
#include "gimpvectors-preview.h"
#include "gimp-intl.h"
enum
{
FREEZE,
THAW,
LAST_SIGNAL
};
static void gimp_vectors_class_init (GimpVectorsClass *klass);
static void gimp_vectors_init (GimpVectors *vectors);
static void gimp_vectors_finalize (GObject *object);
static gint64 gimp_vectors_get_memsize (GimpObject *object,
gint64 *gui_size);
static gboolean gimp_vectors_is_attached (GimpItem *item);
static GimpItem * gimp_vectors_duplicate (GimpItem *item,
GType new_type,
gboolean add_alpha);
static GimpItem * gimp_vectors_convert (GimpItem *item,
GimpImage *dest_image,
GType new_type,
gboolean add_alpha);
static void gimp_vectors_translate (GimpItem *item,
gint offset_x,
gint offset_y,
gboolean push_undo);
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);
static void gimp_vectors_flip (GimpItem *item,
GimpOrientationType flip_type,
gdouble axis,
gboolean clip_result);
static void gimp_vectors_rotate (GimpItem *item,
GimpRotationType rotate_type,
gdouble center_x,
gdouble center_y,
gboolean clip_result);
added new virtual function GimpItem::stroke(). 2003-09-01 Michael Natterer <mitch@gimp.org> * app/core/gimpitem.[ch]: added new virtual function GimpItem::stroke(). * app/core/gimpchannel.c * app/vectors/gimpvectors.c: implement GimpItem::stroke(). * app/core/gimpimage-mask.[ch] (gimp_image_mask_stroke): changed signature to match gimp_item_stroke() (the selection mask *really* should be a GimpChannel subclass). Removed global variable "gboolean gimp_image_mask_stroking"... * app/core/gimpimage.[ch]: ...and added "gboolean mask_stroking" to the GimpImage struct. * app/gui/vectors-commands.[ch]: removed vectors_stroke_vectors(). * app/widgets/widgets-types.h: removed GimpStrokeItemFunc typedef. * app/widgets/gimpvectorstreeview.[ch]: removed "stroke_item_func" member and use gimp_item_stroke() instead. * app/gui/dialogs-constructors.c (dialogs_vectors_list_view_new) * app/gui/edit-commands.c (edit_stroke_cmd_callback) * app/gui/vectors-commands. (vectors_stroke_cmd_callback) * app/widgets/gimpselectioneditor.c (gimp_selection_editor_stroke_clicked) * tools/pdbgen/pdb/edit.pdb (gimp_edit_stroke): changed accordingly. * app/pdb/edit_cmds.c: regenerated. Note that there is no GUI for "stroke channel", although it would be utterly cool to have one, since currently slelection stroking cannot be masked by a selection (because we stroke the selection). Anyway, if anyone has an idea how to trigger "stroke channel" with another drawable active (the one to stroke to), please let me know...
2003-09-02 01:56:44 +08:00
static void gimp_vectors_transform (GimpItem *item,
const GimpMatrix3 *matrix,
GimpTransformDirection direction,
GimpInterpolationType interp_type,
gboolean clip_result,
GimpProgressFunc progress_callback,
gpointer progress_data);
static gboolean gimp_vectors_stroke (GimpItem *item,
GimpDrawable *drawable,
GimpObject *stroke_desc,
gboolean use_default_values);
added new virtual function GimpItem::stroke(). 2003-09-01 Michael Natterer <mitch@gimp.org> * app/core/gimpitem.[ch]: added new virtual function GimpItem::stroke(). * app/core/gimpchannel.c * app/vectors/gimpvectors.c: implement GimpItem::stroke(). * app/core/gimpimage-mask.[ch] (gimp_image_mask_stroke): changed signature to match gimp_item_stroke() (the selection mask *really* should be a GimpChannel subclass). Removed global variable "gboolean gimp_image_mask_stroking"... * app/core/gimpimage.[ch]: ...and added "gboolean mask_stroking" to the GimpImage struct. * app/gui/vectors-commands.[ch]: removed vectors_stroke_vectors(). * app/widgets/widgets-types.h: removed GimpStrokeItemFunc typedef. * app/widgets/gimpvectorstreeview.[ch]: removed "stroke_item_func" member and use gimp_item_stroke() instead. * app/gui/dialogs-constructors.c (dialogs_vectors_list_view_new) * app/gui/edit-commands.c (edit_stroke_cmd_callback) * app/gui/vectors-commands. (vectors_stroke_cmd_callback) * app/widgets/gimpselectioneditor.c (gimp_selection_editor_stroke_clicked) * tools/pdbgen/pdb/edit.pdb (gimp_edit_stroke): changed accordingly. * app/pdb/edit_cmds.c: regenerated. Note that there is no GUI for "stroke channel", although it would be utterly cool to have one, since currently slelection stroking cannot be masked by a selection (because we stroke the selection). Anyway, if anyone has an idea how to trigger "stroke channel" with another drawable active (the one to stroke to), please let me know...
2003-09-02 01:56:44 +08:00
#
static void gimp_vectors_real_thaw (GimpVectors *vectors);
static void gimp_vectors_real_stroke_add (GimpVectors *vectors,
GimpStroke *stroke);
static void gimp_vectors_real_stroke_remove (GimpVectors *vectors,
GimpStroke *stroke);
static GimpStroke * gimp_vectors_real_stroke_get (const GimpVectors *vectors,
const GimpCoords *coord);
static GimpStroke *gimp_vectors_real_stroke_get_next(const GimpVectors *vectors,
const GimpStroke *prev);
static gdouble gimp_vectors_real_stroke_get_length (const GimpVectors *vectors,
const GimpStroke *prev);
static GimpAnchor * gimp_vectors_real_anchor_get (const GimpVectors *vectors,
const GimpCoords *coord,
GimpStroke **ret_stroke);
static void gimp_vectors_real_anchor_delete (GimpVectors *vectors,
GimpAnchor *anchor);
static gdouble gimp_vectors_real_get_length (const GimpVectors *vectors,
const GimpAnchor *start);
static gdouble gimp_vectors_real_get_distance (const GimpVectors *vectors,
const GimpCoords *coord);
static gint gimp_vectors_real_interpolate (const GimpVectors *vectors,
const GimpStroke *stroke,
gdouble precision,
gint max_points,
GimpCoords *ret_coords);
static GimpVectors * gimp_vectors_real_make_bezier (const GimpVectors *vectors);
/* private variables */
static guint gimp_vectors_signals[LAST_SIGNAL] = { 0 };
static GimpItemClass *parent_class = NULL;
GType
gimp_vectors_get_type (void)
{
static GType vectors_type = 0;
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,
};
app/core/Makefile.am app/core/core-types.h new base class for something 2002-02-25 Michael Natterer <mitch@gimp.org> * app/core/Makefile.am * app/core/core-types.h * app/core/gimpitem.[ch]: new base class for something which is a child of an image, has a PDB ID, a tattoo, parasites and emits a "removed" signal. * app/core/gimpdrawable.[ch] * app/vectors/gimpvectors.[ch]: derive from GimpItem. Removed lots of stuff from GimpDrawable. * app/core/gimp.[ch]: changed gimp->drawable_table and gimp->next_drawable_ID to gimp->item_table and gimp->next_item_id. * app/undo.[ch]: s/undo_push_drawable_parasite/undo_push_item_parasite/, minor cleanups. * app/core/gimplayer.[ch]: changed gimp_layer_new_from_tiles() and gimp_layer_new_from_drawable() to take the "dest_gimage" as second, not first parameter. * app/image_map.c * app/core/gimpchannel.c * app/core/gimpdrawable-blend.c * app/core/gimpdrawable-bucket-fill.c * app/core/gimpdrawable-histogram.c * app/core/gimpdrawable-offset.c * app/core/gimpdrawable-preview.c * app/core/gimpdrawable-transform.c * app/core/gimpedit.c * app/core/gimpimage-duplicate.c * app/core/gimpimage-mask.c * app/core/gimpimage-merge.c * app/core/gimpimage-pick-color.c * app/core/gimpimage.c * app/core/gimplayer-floating-sel.c * app/display/gimpdisplayshell-dnd.c * app/file/file-save.c * app/gui/channels-commands.c * app/gui/file-save-dialog.c * app/gui/layers-commands.c * app/gui/offset-dialog.c * app/gui/paths-dialog.c * app/gui/toolbox.c * app/paint/gimpairbrush.c * app/paint/gimpclone.c * app/paint/gimpconvolve.c * app/paint/gimpdodgeburn.c * app/paint/gimperaser.c * app/paint/gimppaintbrush.c * app/paint/gimppaintcore.c * app/paint/gimppencil.c * app/paint/gimpsmudge.c * app/plug-in/plug-in.c * app/tools/gimpbezierselecttool.c * app/tools/gimpbycolorselecttool.c * app/tools/gimpinktool.c * app/tools/gimppainttool.c * app/xcf/xcf-load.c * app/xcf/xcf-save.c * app/widgets/gimpdrawablepreview.c: changed accordingly. * app/widgets/Makefile.am * app/widgets/widgets-types.h * app/widgets/gimpitemlistview.[ch]: new widget implementing most of the stuff formerly done by GimpDrawableListView. * app/widgets/gimpchannellistview.c * app/widgets/gimpdrawablelistitem.c * app/widgets/gimpdrawablelistview.[ch] * app/widgets/gimplayerlistview.c: changed accordingly. * app/widgets/gimpdnd.[ch]: added a vectors DND type. * app/gui/menus.c * app/gui/dialogs.c * app/gui/dialogs-constructors.[ch]: added a vectors dialog and a vectors item_factory. * app/gui/Makefile.am * app/gui/vectors-commands.[ch]: new files implementing the callbacks for the new vectors dialog and item_factory. * app/pdb/pdb_glue.h: some more ugly hacks to keep intermediate perl code working... * tools/pdbgen/pdb.pl: added a vectors type, use GimpItem for all ID lookups. * tools/pdbgen/pdb/channel.pdb * tools/pdbgen/pdb/color.pdb * tools/pdbgen/pdb/drawable.pdb * tools/pdbgen/pdb/edit.pdb * tools/pdbgen/pdb/image.pdb * tools/pdbgen/pdb/layer.pdb * tools/pdbgen/pdb/misc_tools.pdb * tools/pdbgen/pdb/parasite.pdb * tools/pdbgen/pdb/selection.pdb * tools/pdbgen/pdb/selection_tools.pdb: misc changes according to stuff above. * app/pdb/channel_cmds.c * app/pdb/color_cmds.c * app/pdb/drawable_cmds.c * app/pdb/edit_cmds.c * app/pdb/floating_sel_cmds.c * app/pdb/image_cmds.c * app/pdb/layer_cmds.c * app/pdb/misc_tools_cmds.c * app/pdb/paint_tools_cmds.c * app/pdb/parasite_cmds.c * app/pdb/selection_cmds.c * app/pdb/selection_tools_cmds.c * app/pdb/text_tool_cmds.c * app/pdb/transform_tools_cmds.c: regenerated.
2002-02-26 01:58:50 +08:00
vectors_type = g_type_register_static (GIMP_TYPE_ITEM,
"GimpVectors",
&vectors_info, 0);
}
return vectors_type;
}
static void
gimp_vectors_class_init (GimpVectorsClass *klass)
{
GObjectClass *object_class;
GimpObjectClass *gimp_object_class;
GimpViewableClass *viewable_class;
GimpItemClass *item_class;
object_class = G_OBJECT_CLASS (klass);
gimp_object_class = GIMP_OBJECT_CLASS (klass);
viewable_class = GIMP_VIEWABLE_CLASS (klass);
item_class = GIMP_ITEM_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
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",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpVectorsClass, thaw),
NULL, NULL,
gimp_marshal_VOID__VOID,
G_TYPE_NONE, 0);
object_class->finalize = gimp_vectors_finalize;
gimp_object_class->get_memsize = gimp_vectors_get_memsize;
viewable_class->get_new_preview = gimp_vectors_get_new_preview;
viewable_class->default_stock_id = "gimp-path";
item_class->is_attached = gimp_vectors_is_attached;
item_class->duplicate = gimp_vectors_duplicate;
item_class->convert = gimp_vectors_convert;
item_class->translate = gimp_vectors_translate;
item_class->scale = gimp_vectors_scale;
item_class->resize = gimp_vectors_resize;
item_class->flip = gimp_vectors_flip;
item_class->rotate = gimp_vectors_rotate;
item_class->transform = gimp_vectors_transform;
item_class->stroke = gimp_vectors_stroke;
item_class->default_name = _("Path");
item_class->rename_desc = _("Rename Path");
klass->freeze = NULL;
klass->thaw = gimp_vectors_real_thaw;
klass->stroke_add = gimp_vectors_real_stroke_add;
klass->stroke_remove = gimp_vectors_real_stroke_remove;
klass->stroke_get = gimp_vectors_real_stroke_get;
klass->stroke_get_next = gimp_vectors_real_stroke_get_next;
klass->stroke_get_length = gimp_vectors_real_stroke_get_length;
klass->anchor_get = gimp_vectors_real_anchor_get;
klass->anchor_delete = gimp_vectors_real_anchor_delete;
klass->get_length = gimp_vectors_real_get_length;
klass->get_distance = gimp_vectors_real_get_distance;
klass->interpolate = gimp_vectors_real_interpolate;
klass->make_bezier = gimp_vectors_real_make_bezier;
}
static void
gimp_vectors_init (GimpVectors *vectors)
{
GimpItem *item = GIMP_ITEM (vectors);
item->visible = FALSE;
vectors->strokes = NULL;
vectors->freeze_count = 0;
}
static void
gimp_vectors_finalize (GObject *object)
{
GimpVectors *vectors = GIMP_VECTORS (object);
if (vectors->strokes)
{
g_list_foreach (vectors->strokes, (GFunc) g_object_unref, NULL);
g_list_free (vectors->strokes);
vectors->strokes = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static gint64
changed GimpObject::get_memsize() to return a second value named 2003-08-25 Michael Natterer <mitch@gimp.org> * app/core/gimpobject.[ch]: changed GimpObject::get_memsize() to return a second value named "gui_size", where the primary return value is the "constant" actual size (as long as no operation is performed on the object), and the second "gui_size" return value is the size of temporary stuff like preview caches or boundary segments (which may change asynchronously, even if the object is on the undo stack). * app/core/gimp.c * app/core/gimpbrush.c * app/core/gimpbrushpipe.c * app/core/gimpbuffer.c * app/core/gimpchannel.c * app/core/gimpcontainer.c * app/core/gimpcontext.c * app/core/gimpdata.c * app/core/gimpdatafactory.c * app/core/gimpdrawable.c * app/core/gimpgradient.c * app/core/gimpimage-undo.c * app/core/gimpimage.c * app/core/gimpitem.c * app/core/gimplayer.c * app/core/gimplist.c * app/core/gimppalette.c * app/core/gimpparasitelist.c * app/core/gimppattern.c * app/core/gimpundo.c * app/core/gimpundostack.c * app/core/gimpviewable.c * app/text/gimptextlayer.c * app/vectors/gimpstroke.c * app/vectors/gimpvectors.c: changed get_memsize() implementations accordingly. * app/display/gimpdisplayshell-title.c * app/gui/debug-commands.c * app/widgets/gimppreview.c: changed callers accordingly. * app/core/gimpimage-undo-push.c: changed layer, channel, vectors and layer_mask undo steps to add/subtract the size of the resp. objects whenever they take/drop ownership of them. Ignore the objects' "gui_size" to get identical sizes on adding/subtracting. Fixes bug #120429.
2003-08-25 18:49:33 +08:00
gimp_vectors_get_memsize (GimpObject *object,
gint64 *gui_size)
{
GimpVectors *vectors;
GList *list;
gint64 memsize = 0;
vectors = GIMP_VECTORS (object);
for (list = vectors->strokes; list; list = g_list_next (list))
changed GimpObject::get_memsize() to return a second value named 2003-08-25 Michael Natterer <mitch@gimp.org> * app/core/gimpobject.[ch]: changed GimpObject::get_memsize() to return a second value named "gui_size", where the primary return value is the "constant" actual size (as long as no operation is performed on the object), and the second "gui_size" return value is the size of temporary stuff like preview caches or boundary segments (which may change asynchronously, even if the object is on the undo stack). * app/core/gimp.c * app/core/gimpbrush.c * app/core/gimpbrushpipe.c * app/core/gimpbuffer.c * app/core/gimpchannel.c * app/core/gimpcontainer.c * app/core/gimpcontext.c * app/core/gimpdata.c * app/core/gimpdatafactory.c * app/core/gimpdrawable.c * app/core/gimpgradient.c * app/core/gimpimage-undo.c * app/core/gimpimage.c * app/core/gimpitem.c * app/core/gimplayer.c * app/core/gimplist.c * app/core/gimppalette.c * app/core/gimpparasitelist.c * app/core/gimppattern.c * app/core/gimpundo.c * app/core/gimpundostack.c * app/core/gimpviewable.c * app/text/gimptextlayer.c * app/vectors/gimpstroke.c * app/vectors/gimpvectors.c: changed get_memsize() implementations accordingly. * app/display/gimpdisplayshell-title.c * app/gui/debug-commands.c * app/widgets/gimppreview.c: changed callers accordingly. * app/core/gimpimage-undo-push.c: changed layer, channel, vectors and layer_mask undo steps to add/subtract the size of the resp. objects whenever they take/drop ownership of them. Ignore the objects' "gui_size" to get identical sizes on adding/subtracting. Fixes bug #120429.
2003-08-25 18:49:33 +08:00
memsize += (gimp_object_get_memsize (GIMP_OBJECT (list->data), gui_size) +
sizeof (GList));
changed GimpObject::get_memsize() to return a second value named 2003-08-25 Michael Natterer <mitch@gimp.org> * app/core/gimpobject.[ch]: changed GimpObject::get_memsize() to return a second value named "gui_size", where the primary return value is the "constant" actual size (as long as no operation is performed on the object), and the second "gui_size" return value is the size of temporary stuff like preview caches or boundary segments (which may change asynchronously, even if the object is on the undo stack). * app/core/gimp.c * app/core/gimpbrush.c * app/core/gimpbrushpipe.c * app/core/gimpbuffer.c * app/core/gimpchannel.c * app/core/gimpcontainer.c * app/core/gimpcontext.c * app/core/gimpdata.c * app/core/gimpdatafactory.c * app/core/gimpdrawable.c * app/core/gimpgradient.c * app/core/gimpimage-undo.c * app/core/gimpimage.c * app/core/gimpitem.c * app/core/gimplayer.c * app/core/gimplist.c * app/core/gimppalette.c * app/core/gimpparasitelist.c * app/core/gimppattern.c * app/core/gimpundo.c * app/core/gimpundostack.c * app/core/gimpviewable.c * app/text/gimptextlayer.c * app/vectors/gimpstroke.c * app/vectors/gimpvectors.c: changed get_memsize() implementations accordingly. * app/display/gimpdisplayshell-title.c * app/gui/debug-commands.c * app/widgets/gimppreview.c: changed callers accordingly. * app/core/gimpimage-undo-push.c: changed layer, channel, vectors and layer_mask undo steps to add/subtract the size of the resp. objects whenever they take/drop ownership of them. Ignore the objects' "gui_size" to get identical sizes on adding/subtracting. Fixes bug #120429.
2003-08-25 18:49:33 +08:00
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);
}
static gboolean
gimp_vectors_is_attached (GimpItem *item)
{
return (GIMP_IS_IMAGE (item->gimage) &&
gimp_container_have (item->gimage->vectors, GIMP_OBJECT (item)));
}
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);
return new_item;
}
static GimpItem *
gimp_vectors_convert (GimpItem *item,
GimpImage *dest_image,
GType new_type,
gboolean add_alpha)
{
GimpItem *new_item;
g_return_val_if_fail (g_type_is_a (new_type, GIMP_TYPE_VECTORS), NULL);
new_item = GIMP_ITEM_CLASS (parent_class)->convert (item, dest_image,
new_type, add_alpha);
if (! GIMP_IS_VECTORS (new_item))
return new_item;
if (dest_image != item->gimage)
{
new_item->width = dest_image->width;
new_item->height = dest_image->height;
}
return new_item;
}
static void
gimp_vectors_translate (GimpItem *item,
gint offset_x,
gint offset_y,
gboolean push_undo)
{
GimpVectors *vectors = GIMP_VECTORS (item);
GList *list;
gimp_vectors_freeze (vectors);
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;
gimp_stroke_translate (stroke, offset_x, offset_y);
}
gimp_vectors_thaw (vectors);
}
static void
gimp_vectors_scale (GimpItem *item,
gint new_width,
gint new_height,
gint new_offset_x,
gint new_offset_y,
GimpInterpolationType interpolation_type)
{
GimpVectors *vectors = GIMP_VECTORS (item);
GList *list;
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;
gimp_stroke_scale (stroke,
(gdouble) new_width / (gdouble) item->width,
(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);
}
static void
gimp_vectors_resize (GimpItem *item,
gint new_width,
gint new_height,
gint offset_x,
gint offset_y)
{
GimpVectors *vectors = GIMP_VECTORS (item);
GList *list;
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;
gimp_stroke_translate (stroke, offset_x, offset_y);
}
GIMP_ITEM_CLASS (parent_class)->resize (item, new_width, new_height,
offset_x, offset_y);
gimp_vectors_thaw (vectors);
}
static void
gimp_vectors_flip (GimpItem *item,
GimpOrientationType flip_type,
gdouble axis,
gboolean clip_result)
{
GimpVectors *vectors = GIMP_VECTORS (item);
GList *list;
GimpMatrix3 matrix;
gimp_transform_matrix_flip (flip_type, axis, &matrix);
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;
gimp_stroke_transform (stroke, &matrix);
}
gimp_vectors_thaw (vectors);
}
static void
gimp_vectors_rotate (GimpItem *item,
GimpRotationType rotate_type,
gdouble center_x,
gdouble center_y,
gboolean clip_result)
{
GimpVectors *vectors = GIMP_VECTORS (item);
GList *list;
GimpMatrix3 matrix;
gdouble angle = 0.0;
switch (rotate_type)
{
case GIMP_ROTATE_90:
angle = G_PI_2;
break;
case GIMP_ROTATE_180:
angle = G_PI;
break;
case GIMP_ROTATE_270:
angle = - G_PI_2;
break;
}
gimp_transform_matrix_rotate_center (center_x, center_y, angle, &matrix);
gimp_vectors_freeze (vectors);
gimp_image_undo_push_vectors_mod (gimp_item_get_image (item),
_("Rotate Path"),
vectors);
for (list = vectors->strokes; list; list = g_list_next (list))
{
GimpStroke *stroke = list->data;
gimp_stroke_transform (stroke, &matrix);
}
gimp_vectors_thaw (vectors);
}
static void
gimp_vectors_transform (GimpItem *item,
const GimpMatrix3 *matrix,
GimpTransformDirection direction,
GimpInterpolationType interpolation_type,
gboolean clip_result,
GimpProgressFunc progress_callback,
gpointer progress_data)
{
GimpVectors *vectors = GIMP_VECTORS (item);
GimpMatrix3 local_matrix;
GList *list;
gimp_vectors_freeze (vectors);
gimp_image_undo_push_vectors_mod (gimp_item_get_image (item),
_("Transform Path"),
vectors);
local_matrix = *matrix;
if (direction == GIMP_TRANSFORM_BACKWARD)
gimp_matrix3_invert (&local_matrix);
for (list = vectors->strokes; list; list = g_list_next (list))
{
GimpStroke *stroke = list->data;
gimp_stroke_transform (stroke, &local_matrix);
}
gimp_vectors_thaw (vectors);
}
added new virtual function GimpItem::stroke(). 2003-09-01 Michael Natterer <mitch@gimp.org> * app/core/gimpitem.[ch]: added new virtual function GimpItem::stroke(). * app/core/gimpchannel.c * app/vectors/gimpvectors.c: implement GimpItem::stroke(). * app/core/gimpimage-mask.[ch] (gimp_image_mask_stroke): changed signature to match gimp_item_stroke() (the selection mask *really* should be a GimpChannel subclass). Removed global variable "gboolean gimp_image_mask_stroking"... * app/core/gimpimage.[ch]: ...and added "gboolean mask_stroking" to the GimpImage struct. * app/gui/vectors-commands.[ch]: removed vectors_stroke_vectors(). * app/widgets/widgets-types.h: removed GimpStrokeItemFunc typedef. * app/widgets/gimpvectorstreeview.[ch]: removed "stroke_item_func" member and use gimp_item_stroke() instead. * app/gui/dialogs-constructors.c (dialogs_vectors_list_view_new) * app/gui/edit-commands.c (edit_stroke_cmd_callback) * app/gui/vectors-commands. (vectors_stroke_cmd_callback) * app/widgets/gimpselectioneditor.c (gimp_selection_editor_stroke_clicked) * tools/pdbgen/pdb/edit.pdb (gimp_edit_stroke): changed accordingly. * app/pdb/edit_cmds.c: regenerated. Note that there is no GUI for "stroke channel", although it would be utterly cool to have one, since currently slelection stroking cannot be masked by a selection (because we stroke the selection). Anyway, if anyone has an idea how to trigger "stroke channel" with another drawable active (the one to stroke to), please let me know...
2003-09-02 01:56:44 +08:00
static gboolean
gimp_vectors_stroke (GimpItem *item,
GimpDrawable *drawable,
GimpObject *stroke_desc,
gboolean use_default_values)
added new virtual function GimpItem::stroke(). 2003-09-01 Michael Natterer <mitch@gimp.org> * app/core/gimpitem.[ch]: added new virtual function GimpItem::stroke(). * app/core/gimpchannel.c * app/vectors/gimpvectors.c: implement GimpItem::stroke(). * app/core/gimpimage-mask.[ch] (gimp_image_mask_stroke): changed signature to match gimp_item_stroke() (the selection mask *really* should be a GimpChannel subclass). Removed global variable "gboolean gimp_image_mask_stroking"... * app/core/gimpimage.[ch]: ...and added "gboolean mask_stroking" to the GimpImage struct. * app/gui/vectors-commands.[ch]: removed vectors_stroke_vectors(). * app/widgets/widgets-types.h: removed GimpStrokeItemFunc typedef. * app/widgets/gimpvectorstreeview.[ch]: removed "stroke_item_func" member and use gimp_item_stroke() instead. * app/gui/dialogs-constructors.c (dialogs_vectors_list_view_new) * app/gui/edit-commands.c (edit_stroke_cmd_callback) * app/gui/vectors-commands. (vectors_stroke_cmd_callback) * app/widgets/gimpselectioneditor.c (gimp_selection_editor_stroke_clicked) * tools/pdbgen/pdb/edit.pdb (gimp_edit_stroke): changed accordingly. * app/pdb/edit_cmds.c: regenerated. Note that there is no GUI for "stroke channel", although it would be utterly cool to have one, since currently slelection stroking cannot be masked by a selection (because we stroke the selection). Anyway, if anyone has an idea how to trigger "stroke channel" with another drawable active (the one to stroke to), please let me know...
2003-09-02 01:56:44 +08:00
{
GimpVectors *vectors = GIMP_VECTORS (item);
gboolean retval = FALSE;
added new virtual function GimpItem::stroke(). 2003-09-01 Michael Natterer <mitch@gimp.org> * app/core/gimpitem.[ch]: added new virtual function GimpItem::stroke(). * app/core/gimpchannel.c * app/vectors/gimpvectors.c: implement GimpItem::stroke(). * app/core/gimpimage-mask.[ch] (gimp_image_mask_stroke): changed signature to match gimp_item_stroke() (the selection mask *really* should be a GimpChannel subclass). Removed global variable "gboolean gimp_image_mask_stroking"... * app/core/gimpimage.[ch]: ...and added "gboolean mask_stroking" to the GimpImage struct. * app/gui/vectors-commands.[ch]: removed vectors_stroke_vectors(). * app/widgets/widgets-types.h: removed GimpStrokeItemFunc typedef. * app/widgets/gimpvectorstreeview.[ch]: removed "stroke_item_func" member and use gimp_item_stroke() instead. * app/gui/dialogs-constructors.c (dialogs_vectors_list_view_new) * app/gui/edit-commands.c (edit_stroke_cmd_callback) * app/gui/vectors-commands. (vectors_stroke_cmd_callback) * app/widgets/gimpselectioneditor.c (gimp_selection_editor_stroke_clicked) * tools/pdbgen/pdb/edit.pdb (gimp_edit_stroke): changed accordingly. * app/pdb/edit_cmds.c: regenerated. Note that there is no GUI for "stroke channel", although it would be utterly cool to have one, since currently slelection stroking cannot be masked by a selection (because we stroke the selection). Anyway, if anyone has an idea how to trigger "stroke channel" with another drawable active (the one to stroke to), please let me know...
2003-09-02 01:56:44 +08:00
if (! vectors->strokes)
{
g_message (_("Cannot stroke empty path."));
return FALSE;
}
if (GIMP_IS_STROKE_OPTIONS (stroke_desc))
{
gimp_drawable_stroke_vectors (drawable,
GIMP_STROKE_OPTIONS (stroke_desc),
vectors);
retval = TRUE;
}
else if (GIMP_IS_PAINT_INFO (stroke_desc))
{
GimpImage *gimage = gimp_item_get_image (item);
GimpPaintInfo *paint_info = GIMP_PAINT_INFO (stroke_desc);
GimpPaintOptions *paint_options;
GimpPaintCore *core;
if (use_default_values)
{
paint_options =
gimp_paint_options_new (gimage->gimp,
paint_info->paint_options_type);
/* undefine the paint-relevant context properties and get them
* from the current context
*/
gimp_context_define_properties (GIMP_CONTEXT (paint_options),
GIMP_CONTEXT_PAINT_PROPS_MASK,
FALSE);
gimp_context_set_parent (GIMP_CONTEXT (paint_options),
gimp_get_current_context (gimage->gimp));
}
else
{
paint_options = paint_info->paint_options;
}
core = g_object_new (paint_info->paint_type, NULL);
retval = gimp_paint_core_stroke_vectors (core, drawable,
paint_options,
vectors);
g_object_unref (core);
if (use_default_values)
g_object_unref (paint_options);
}
added new virtual function GimpItem::stroke(). 2003-09-01 Michael Natterer <mitch@gimp.org> * app/core/gimpitem.[ch]: added new virtual function GimpItem::stroke(). * app/core/gimpchannel.c * app/vectors/gimpvectors.c: implement GimpItem::stroke(). * app/core/gimpimage-mask.[ch] (gimp_image_mask_stroke): changed signature to match gimp_item_stroke() (the selection mask *really* should be a GimpChannel subclass). Removed global variable "gboolean gimp_image_mask_stroking"... * app/core/gimpimage.[ch]: ...and added "gboolean mask_stroking" to the GimpImage struct. * app/gui/vectors-commands.[ch]: removed vectors_stroke_vectors(). * app/widgets/widgets-types.h: removed GimpStrokeItemFunc typedef. * app/widgets/gimpvectorstreeview.[ch]: removed "stroke_item_func" member and use gimp_item_stroke() instead. * app/gui/dialogs-constructors.c (dialogs_vectors_list_view_new) * app/gui/edit-commands.c (edit_stroke_cmd_callback) * app/gui/vectors-commands. (vectors_stroke_cmd_callback) * app/widgets/gimpselectioneditor.c (gimp_selection_editor_stroke_clicked) * tools/pdbgen/pdb/edit.pdb (gimp_edit_stroke): changed accordingly. * app/pdb/edit_cmds.c: regenerated. Note that there is no GUI for "stroke channel", although it would be utterly cool to have one, since currently slelection stroking cannot be masked by a selection (because we stroke the selection). Anyway, if anyone has an idea how to trigger "stroke channel" with another drawable active (the one to stroke to), please let me know...
2003-09-02 01:56:44 +08:00
return retval;
}
static void
gimp_vectors_real_thaw (GimpVectors *vectors)
{
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (vectors));
}
/* 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);
gimp_item_configure (GIMP_ITEM (vectors), gimage,
0, 0, gimage->width, gimage->height,
name);
return vectors;
}
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);
}
void
gimp_vectors_copy_strokes (const GimpVectors *src_vectors,
GimpVectors *dest_vectors)
{
g_return_if_fail (GIMP_IS_VECTORS (src_vectors));
g_return_if_fail (GIMP_IS_VECTORS (dest_vectors));
gimp_vectors_freeze (dest_vectors);
if (dest_vectors->strokes)
{
2003-09-02 22:07:43 +08:00
g_list_foreach (dest_vectors->strokes, (GFunc) g_object_unref, NULL);
g_list_free (dest_vectors->strokes);
}
dest_vectors->strokes = NULL;
gimp_vectors_add_strokes (src_vectors, dest_vectors);
gimp_vectors_thaw (dest_vectors);
}
void
gimp_vectors_add_strokes (const GimpVectors *src_vectors,
GimpVectors *dest_vectors)
{
GList *current_lstroke;
GList *strokes_copy;
g_return_if_fail (GIMP_IS_VECTORS (src_vectors));
g_return_if_fail (GIMP_IS_VECTORS (dest_vectors));
gimp_vectors_freeze (dest_vectors);
strokes_copy = g_list_copy (src_vectors->strokes);
current_lstroke = strokes_copy;
while (current_lstroke)
{
current_lstroke->data = gimp_stroke_duplicate (current_lstroke->data);
current_lstroke = g_list_next (current_lstroke);
}
dest_vectors->strokes = g_list_concat (dest_vectors->strokes, strokes_copy);
gimp_vectors_thaw (dest_vectors);
}
/* Calling the virtual functions */
void
gimp_vectors_stroke_add (GimpVectors *vectors,
GimpStroke *stroke)
{
g_return_if_fail (GIMP_IS_VECTORS (vectors));
g_return_if_fail (GIMP_IS_STROKE (stroke));
gimp_vectors_freeze (vectors);
GIMP_VECTORS_GET_CLASS (vectors)->stroke_add (vectors, stroke);
gimp_vectors_thaw (vectors);
}
static void
gimp_vectors_real_stroke_add (GimpVectors *vectors,
GimpStroke *stroke)
{
/* Don't g_list_prepend() here. See ChangeLog 2003-05-21 --Mitch */
vectors->strokes = g_list_append (vectors->strokes, stroke);
g_object_ref (stroke);
}
void
gimp_vectors_stroke_remove (GimpVectors *vectors,
GimpStroke *stroke)
{
g_return_if_fail (GIMP_IS_VECTORS (vectors));
g_return_if_fail (GIMP_IS_STROKE (stroke));
gimp_vectors_freeze (vectors);
GIMP_VECTORS_GET_CLASS (vectors)->stroke_remove (vectors, stroke);
gimp_vectors_thaw (vectors);
}
static void
gimp_vectors_real_stroke_remove (GimpVectors *vectors,
GimpStroke *stroke)
{
GList *list;
list = g_list_find (vectors->strokes, stroke);
if (list)
{
vectors->strokes = g_list_delete_link (vectors->strokes, list);
g_object_unref (stroke);
}
}
GimpStroke *
gimp_vectors_stroke_get (const GimpVectors *vectors,
const GimpCoords *coord)
{
g_return_val_if_fail (GIMP_IS_VECTORS (vectors), NULL);
return GIMP_VECTORS_GET_CLASS (vectors)->stroke_get (vectors, coord);
}
static GimpStroke *
gimp_vectors_real_stroke_get (const GimpVectors *vectors,
const GimpCoords *coord)
{
GList *stroke;
gdouble mindist = G_MAXDOUBLE;
GimpStroke *minstroke = NULL;
for (stroke = vectors->strokes; stroke; stroke = g_list_next (stroke))
{
GimpAnchor *anchor = gimp_stroke_anchor_get (stroke->data, coord);
if (anchor)
{
gdouble dx, dy;
dx = coord->x - anchor->position.x;
dy = coord->y - anchor->position.y;
if (mindist > dx * dx + dy * dy)
{
mindist = dx * dx + dy * dy;
minstroke = GIMP_STROKE (stroke->data);
}
}
}
return minstroke;
}
GimpStroke *
gimp_vectors_stroke_get_next (const GimpVectors *vectors,
const GimpStroke *prev)
{
g_return_val_if_fail (GIMP_IS_VECTORS (vectors), NULL);
return GIMP_VECTORS_GET_CLASS (vectors)->stroke_get_next (vectors, prev);
}
static GimpStroke *
gimp_vectors_real_stroke_get_next (const GimpVectors *vectors,
const GimpStroke *prev)
{
if (! prev)
{
return vectors->strokes ? vectors->strokes->data : NULL;
}
else
{
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;
}
}
gdouble
gimp_vectors_stroke_get_length (const GimpVectors *vectors,
const GimpStroke *prev)
{
g_return_val_if_fail (GIMP_IS_VECTORS (vectors), 0.0);
return GIMP_VECTORS_GET_CLASS (vectors)->stroke_get_length (vectors, prev);
}
static gdouble
gimp_vectors_real_stroke_get_length (const GimpVectors *vectors,
const GimpStroke *prev)
{
g_printerr ("gimp_vectors_stroke_get_length: default implementation\n");
return 0.0;
}
GimpAnchor *
gimp_vectors_anchor_get (const GimpVectors *vectors,
const GimpCoords *coord,
GimpStroke **ret_stroke)
{
g_return_val_if_fail (GIMP_IS_VECTORS (vectors), NULL);
return GIMP_VECTORS_GET_CLASS (vectors)->anchor_get (vectors, coord,
ret_stroke);
}
static GimpAnchor *
gimp_vectors_real_anchor_get (const GimpVectors *vectors,
const GimpCoords *coord,
GimpStroke **ret_stroke)
{
gdouble dx, dy, mindist;
GList *stroke;
GimpAnchor *anchor = NULL;
GimpAnchor *minanchor = NULL;
mindist = -1;
for (stroke = vectors->strokes; stroke; stroke = g_list_next (stroke))
{
anchor = gimp_stroke_anchor_get (GIMP_STROKE (stroke->data), coord);
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;
if (ret_stroke)
*ret_stroke = stroke->data;
}
}
}
return minanchor;
}
void
gimp_vectors_anchor_delete (GimpVectors *vectors,
GimpAnchor *anchor)
{
g_return_if_fail (GIMP_IS_VECTORS (vectors));
g_return_if_fail (anchor != NULL);
GIMP_VECTORS_GET_CLASS (vectors)->anchor_delete (vectors, anchor);
}
static void
gimp_vectors_real_anchor_delete (GimpVectors *vectors,
GimpAnchor *anchor)
{
}
void
gimp_vectors_anchor_select (GimpVectors *vectors,
GimpStroke *target_stroke,
GimpAnchor *anchor,
gboolean selected,
gboolean exclusive)
{
GList *stroke_list;
GimpStroke *stroke;
for (stroke_list = vectors->strokes; stroke_list;
stroke_list = g_list_next (stroke_list))
{
stroke = GIMP_STROKE (stroke_list->data);
gimp_stroke_anchor_select (stroke,
stroke == target_stroke ? anchor : NULL,
selected, exclusive);
}
}
gdouble
gimp_vectors_get_length (const GimpVectors *vectors,
const GimpAnchor *start)
{
g_return_val_if_fail (GIMP_IS_VECTORS (vectors), 0.0);
return GIMP_VECTORS_GET_CLASS (vectors)->get_length (vectors, start);
}
static gdouble
gimp_vectors_real_get_length (const GimpVectors *vectors,
const GimpAnchor *start)
{
g_printerr ("gimp_vectors_get_length: default implementation\n");
return 0;
}
gdouble
gimp_vectors_get_distance (const GimpVectors *vectors,
const GimpCoords *coord)
{
g_return_val_if_fail (GIMP_IS_VECTORS (vectors), 0.0);
return GIMP_VECTORS_GET_CLASS (vectors)->get_distance (vectors, coord);
}
static gdouble
gimp_vectors_real_get_distance (const GimpVectors *vectors,
const GimpCoords *coord)
{
g_printerr ("gimp_vectors_get_distance: default implementation\n");
return 0;
}
gboolean
gimp_vectors_bounds (const GimpVectors *vectors,
gdouble *x1,
gdouble *y1,
gdouble *x2,
gdouble *y2)
{
GArray *stroke_coords;
GimpStroke *cur_stroke;
gint i;
gboolean has_strokes = FALSE;
gboolean closed;
GimpCoords point;
g_return_val_if_fail (GIMP_IS_VECTORS (vectors), FALSE);
g_return_val_if_fail (x1 != NULL, FALSE);
g_return_val_if_fail (y1 != NULL, FALSE);
g_return_val_if_fail (x2 != NULL, FALSE);
g_return_val_if_fail (y2 != NULL, FALSE);
for (cur_stroke = gimp_vectors_stroke_get_next (vectors, NULL);
cur_stroke;
cur_stroke = gimp_vectors_stroke_get_next (vectors, cur_stroke))
{
stroke_coords = gimp_stroke_interpolate (cur_stroke, 1.0, &closed);
if (stroke_coords)
{
if (! has_strokes && stroke_coords->len > 0)
{
has_strokes = TRUE;
point = g_array_index (stroke_coords, GimpCoords, 0);
*x1 = *x2 = point.x;
*y1 = *y2 = point.y;
}
for (i=0; i < stroke_coords->len; i++)
{
point = g_array_index (stroke_coords, GimpCoords, i);
*x1 = MIN (*x1, point.x);
*y1 = MIN (*y1, point.y);
*x2 = MAX (*x2, point.x);
*y2 = MAX (*y2, point.y);
}
g_array_free (stroke_coords, TRUE);
}
}
return has_strokes;
}
gint
gimp_vectors_interpolate (const GimpVectors *vectors,
const GimpStroke *stroke,
gdouble precision,
gint max_points,
GimpCoords *ret_coords)
{
g_return_val_if_fail (GIMP_IS_VECTORS (vectors), 0);
return GIMP_VECTORS_GET_CLASS (vectors)->interpolate (vectors, stroke,
precision, max_points,
ret_coords);
}
static gint
gimp_vectors_real_interpolate (const GimpVectors *vectors,
const GimpStroke *stroke,
gdouble precision,
gint max_points,
GimpCoords *ret_coords)
{
g_printerr ("gimp_vectors_interpolate: default implementation\n");
return 0;
}
GimpVectors *
gimp_vectors_make_bezier (const GimpVectors *vectors)
{
g_return_val_if_fail (GIMP_IS_VECTORS (vectors), NULL);
return GIMP_VECTORS_GET_CLASS (vectors)->make_bezier (vectors);
}
static GimpVectors *
gimp_vectors_real_make_bezier (const GimpVectors *vectors)
{
g_printerr ("gimp_vectors_make_bezier: default implementation\n");
return NULL;
}