Commit 29b80633 authored by Simon Budig's avatar Simon Budig Committed by Simon Budig

app/vectors/gimpvectors.c Changed to a container of GimpStrokes. This will

2002-02-25  Simon Budig  <simon@gimp.org>

        * app/vectors/gimpvectors.c
        * app/vectors/gimpvectors.h: Changed to a container of
        GimpStrokes. This will enable it to contain different
        Stroke-types in one Vectors-Object (think Entry in path
        dialog)

        * app/vectors/gimpstroke.c
        * app/vectors/gimpstroke.h
        * app/vectors/gimpbezierstroke.c
        * app/vectors/gimpbezierstroke.h: New Objects: A connected
        component in a vector.

        * app/vectors/gimpbezier.c
        * app/vectors/gimpbezier.h: Removed, obsoleted by gimpstroke
        and gimpbezierstroke.

        * app/tools/gimpvectortool.c
        * app/vectors/Makefile.am
        * app/vectors/vectors-types.h
        * app/vectors/gimpanchor.h: Changed accordingly.

        There is a nasty bug I am yet unable to find in the tool.
        Don't use it. For some reason a wrong function instead of
        gimp_stroke_real_anchor_get_next gets called. I have *no*
        idea, whats wrong here. I stared at the code for hours.

        If somebody has an idea I'd appreciate a hint.
parent d7127846
2002-02-25 Simon Budig <simon@gimp.org>
* app/vectors/gimpvectors.c
* app/vectors/gimpvectors.h: Changed to a container of
GimpStrokes. This will enable it to contain different
Stroke-types in one Vectors-Object (think Entry in path
dialog)
* app/vectors/gimpstroke.c
* app/vectors/gimpstroke.h
* app/vectors/gimpbezierstroke.c
* app/vectors/gimpbezierstroke.h: New Objects: A connected
component in a vector.
* app/vectors/gimpbezier.c
* app/vectors/gimpbezier.h: Removed, obsoleted by gimpstroke
and gimpbezierstroke.
* app/tools/gimpvectortool.c
* app/vectors/Makefile.am
* app/vectors/vectors-types.h
* app/vectors/gimpanchor.h: Changed accordingly.
There is a nasty bug I am yet unable to find in the tool.
Don't use it. For some reason a wrong function instead of
gimp_stroke_real_anchor_get_next gets called. I have *no*
idea, whats wrong here. I stared at the code for hours.
If somebody has an idea I'd appreciate a hint.
2002-02-25 Sven Neumann <sven@gimp.org>
* app/gui/Makefile.am
......
......@@ -38,7 +38,7 @@
#include "vectors/gimpanchor.h"
#include "vectors/gimpvectors.h"
#include "vectors/gimpbezier.h"
#include "vectors/gimpbezierstroke.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplay-foreach.h"
......@@ -190,7 +190,7 @@ gimp_vector_tool_init (GimpVectorTool *vector_tool)
tool->preserve = TRUE; /* Preserve on drawable change */
vector_tool->vectors = g_object_new (GIMP_TYPE_BEZIER, 0);
vector_tool->vectors = g_object_new (GIMP_TYPE_VECTORS, 0);
}
static void
......@@ -229,12 +229,13 @@ gimp_vector_tool_button_press (GimpTool *tool,
GdkModifierType state,
GimpDisplay *gdisp)
{
GimpVectorTool *vector_tool;
VectorOptions *options;
GimpVectorTool *vector_tool;
VectorOptions *options;
GimpDisplayShell *shell;
gint i;
GimpCoords cur_point;
GimpAnchor *anchor;
GimpStroke *stroke;
vector_tool = GIMP_VECTOR_TOOL (tool);
......@@ -256,7 +257,7 @@ gimp_vector_tool_button_press (GimpTool *tool,
* the new function will be moving or adding a new point or guide
*/
anchor = gimp_bezier_anchor_get (vector_tool->vectors, coords);
anchor = gimp_vectors_anchor_get (vector_tool->vectors, coords);
if (anchor && gimp_draw_tool_on_handle (GIMP_DRAW_TOOL (tool), gdisp,
coords->x,
......@@ -282,9 +283,11 @@ gimp_vector_tool_button_press (GimpTool *tool,
gimp_draw_tool_stop (GIMP_DRAW_TOOL (vector_tool));
}
cur_point.x = coords->x;
cur_point.y = coords->y;
anchor = gimp_vectors_anchor_set (vector_tool->vectors, &cur_point, TRUE);
stroke = gimp_bezier_stroke_new (coords);
anchor = gimp_stroke_anchor_get (stroke, coords);
gimp_vectors_stroke_add (vector_tool->vectors, stroke);
vector_tool->cur_anchor = anchor;
vector_tool->function = VMOVING;
......@@ -371,7 +374,7 @@ gimp_vector_tool_cursor_update (GimpTool *tool,
if (tool->state == ACTIVE && tool->gdisp == gdisp)
{
anchor = gimp_bezier_anchor_get (vector_tool->vectors, coords);
anchor = gimp_vectors_anchor_get (vector_tool->vectors, coords);
if (anchor && gimp_draw_tool_on_handle (GIMP_DRAW_TOOL (tool), gdisp,
coords->x,
......@@ -411,15 +414,20 @@ gimp_vector_tool_draw (GimpDrawTool *draw_tool)
vectors = vector_tool->vectors;
while ((cur_anchor = gimp_vectors_anchor_get_next (vectors, cur_anchor))) {
gimp_draw_tool_draw_handle (draw_tool,
GIMP_HANDLE_CIRCLE,
cur_anchor->position.x,
cur_anchor->position.y,
TARGET,
TARGET,
GTK_ANCHOR_CENTER,
FALSE);
while ((cur_stroke = gimp_vectors_stroke_get_next (vectors, cur_stroke))) {
cur_anchor = NULL;
while ((cur_anchor = gimp_stroke_anchor_get_next (cur_stroke, cur_anchor))) {
g_printerr ("drawing %p\n", cur_anchor);
gimp_draw_tool_draw_handle (draw_tool,
GIMP_HANDLE_CIRCLE,
cur_anchor->position.x,
cur_anchor->position.y,
TARGET,
TARGET,
GTK_ANCHOR_CENTER,
FALSE);
G_BREAKPOINT();
}
}
for (i = 0; i < vector_tool->num_points; i++)
......
......@@ -17,9 +17,10 @@ noinst_LIBRARIES = libappvectors.a
libappvectors_a_sources = @STRIP_BEGIN@ \
gimpanchor.h \
gimpbezier.c \
gimpbezier.h \
gimpbezierstroke.h \
gimpbezierstroke.c \
gimpstroke.h \
gimpstroke.c \
gimpvectors.c \
gimpvectors.h \
@STRIP_END@
......
......@@ -2,7 +2,7 @@
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpanchor.h
* Copyright (C) 2001 Simon Budig <simon@gimp.org>
* 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 GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpbezier.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 "gimpbezier.h"
/* private BezierStroke struct */
typedef struct _GimpBezierStroke GimpBezierStroke;
struct _GimpBezierStroke
{
gboolean closed;
GList * controls; /* of GimpBezierNodes */
};
typedef struct _GimpBezierNode GimpBezierNode;
struct _GimpBezierNode
{
GimpAnchor * ctrl_prev;
GimpAnchor * ctrl;
GimpAnchor * ctrl_next;
};
/* private variables */
static GimpVectorsClass *parent_class = NULL;
static void
gimp_bezier_finalize (GObject *object)
{
/* blablabla */
}
/* local function prototypes */
static void gimp_bezier_init (GimpBezier *vectors);
static void
gimp_bezier_class_init (GimpBezierClass *klass)
{
GObjectClass *object_class;
GimpObjectClass *gimp_object_class;
GimpViewableClass *viewable_class;
GimpVectorsClass *vectors_class;
object_class = G_OBJECT_CLASS (klass);
gimp_object_class = GIMP_OBJECT_CLASS (klass);
viewable_class = GIMP_VIEWABLE_CLASS (klass);
vectors_class = GIMP_VECTORS_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
vectors_class->anchor_set = gimp_bezier_anchor_set;
vectors_class->anchor_get_next = gimp_bezier_anchor_get_next;
vectors_class->anchor_move_absolute = gimp_bezier_anchor_move_absolute;
/* Lots of pointers missing */
object_class->finalize = gimp_bezier_finalize;
}
GType
gimp_bezier_get_type (void)
{
static GType bezier_type = 0;
if (! bezier_type)
{
static const GTypeInfo bezier_info =
{
sizeof (GimpBezierClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_bezier_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpBezier),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_bezier_init,
};
bezier_type = g_type_register_static (GIMP_TYPE_VECTORS,
"GimpBezier",
&bezier_info, 0);
}
return bezier_type;
}
static void
gimp_bezier_init (GimpBezier *bezier)
{
bezier->anchors = NULL;
bezier->strokes = NULL;
};
GimpAnchor *
gimp_bezier_anchor_get (const GimpVectors *vectors,
const GimpCoords *coord)
{
gdouble dx, dy, mindist;
GList *list;
GimpBezier *bezier;
GimpAnchor *anchor = NULL;
g_return_val_if_fail (GIMP_IS_BEZIER (vectors), NULL);
bezier = GIMP_BEZIER(vectors);
list = bezier->anchors;
if (list) {
dx = coord->x - ((GimpAnchor *) list->data)->position.x;
dy = coord->y - ((GimpAnchor *) list->data)->position.y;
anchor = (GimpAnchor *) list->data;
mindist = dx * dx + dy * dy;
list = list->next;
}
while (list) {
dx = coord->x - ((GimpAnchor *) list->data)->position.x;
dy = coord->y - ((GimpAnchor *) list->data)->position.y;
if (mindist > dx * dx + dy * dy) {
mindist = dx * dx + dy * dy;
anchor = (GimpAnchor *) list->data;
}
list = list->next;
}
return anchor;
}
/* prev == NULL: "first" anchor */
GimpAnchor *
gimp_bezier_anchor_get_next (const GimpVectors *vectors,
const GimpAnchor *prev)
{
static GList *last_shown = NULL;
GimpBezier *bezier;
g_return_val_if_fail (GIMP_IS_BEZIER (vectors), NULL);
bezier = GIMP_BEZIER(vectors);
if (!prev) {
last_shown = bezier->anchors;
return (GimpAnchor *) last_shown->data;
} else {
if (!last_shown || last_shown->data != prev) {
last_shown = g_list_find (bezier->anchors, prev);
}
last_shown = last_shown->next;
}
if (last_shown)
return (GimpAnchor *) last_shown->data;
else
return NULL;
}
GimpAnchor *
gimp_bezier_anchor_set (const GimpVectors *vectors,
const GimpCoords *coord,
const gboolean new_stroke)
{
GimpBezier *bezier;
GimpAnchor *anchor;
g_return_val_if_fail (GIMP_IS_BEZIER (vectors), NULL);
bezier = GIMP_BEZIER(vectors);
anchor = g_new0 (GimpAnchor, 1);
anchor->position.x = coord->x;
anchor->position.y = coord->y;
anchor->position.pressure = 1;
anchor->active = FALSE;
bezier->anchors = g_list_append (bezier->anchors, anchor);
return anchor;
}
void
gimp_bezier_anchor_move_relative (GimpVectors *vectors,
GimpAnchor *anchor,
const GimpCoords *deltacoord,
const gint type)
{
GimpBezier *bezier;
g_return_if_fail (GIMP_IS_BEZIER (vectors));
bezier = GIMP_BEZIER(vectors);
if (anchor) {
anchor->position.x += deltacoord->x;
anchor->position.y += deltacoord->y;
}
}
void
gimp_bezier_anchor_move_absolute (GimpVectors *vectors,
GimpAnchor *anchor,
const GimpCoords *coord,
const gint type)
{
GimpBezier *bezier;
g_return_if_fail (GIMP_IS_BEZIER (vectors));
bezier = GIMP_BEZIER(vectors);
if (anchor) {
anchor->position.x = coord->x;
anchor->position.y = coord->y;
}
}
void
gimp_bezier_anchor_delete (GimpVectors *vectors,
GimpAnchor *anchor);
/* accessing the shape of the curve */
gdouble
gimp_bezier_get_length (const GimpVectors *vectors,
const GimpAnchor *start);
/* returns the number of valid coordinates */
gint
gimp_bezier_interpolate (const GimpVectors *vectors,
const GimpStroke *start,
const gdouble precision,
const gint max_points,
GimpCoords *ret_coords);
/* Allow a singular temorary anchor (marking the "working point")? */
GimpAnchor *
gimp_bezier_temp_anchor_get (const GimpVectors *vectors);
GimpAnchor *
gimp_bezier_temp_anchor_set (GimpVectors *vectors,
const GimpCoords *coord);
gboolean
gimp_bezier_temp_anchor_fix (GimpVectors *vectors);
void
gimp_bezier_temp_anchor_delete (GimpVectors *vectors);
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpbezier.h
* Copyright (C) 2001 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.
*/
#ifndef __GIMP_BEZIER_H__
#define __GIMP_BEZIER_H__
/* Temporary implementation with straight lines. */
#include "config.h"
#include "glib-object.h"
#include "vectors-types.h"
#include "gimpvectors.h"
#define GIMP_TYPE_BEZIER (gimp_bezier_get_type ())
#define GIMP_BEZIER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_BEZIER, GimpBezier))
#define GIMP_BEZIER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_BEZIER, GimpBezierClass))
#define GIMP_IS_BEZIER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_BEZIER))
#define GIMP_IS_BEZIER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_BEZIER))
#define GIMP_BEZIER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_BEZIER, GimpBezierClass))
/* Bezier Data Structure */
struct _GimpBezier
{
GimpVectors parent_instance;
GList * anchors;
GList * strokes;
};
struct _GimpBezierClass
{
GimpVectorsClass parent_class;
};
GType gimp_bezier_get_type (void) G_GNUC_CONST;
/* accessing / modifying the anchors */
GimpAnchor * gimp_bezier_anchor_get (const GimpVectors *vectors,
const GimpCoords *coord);
/* prev == NULL: "first" anchor */
GimpAnchor * gimp_bezier_anchor_get_next (const GimpVectors *vectors,
const GimpAnchor *prev);
GimpAnchor * gimp_bezier_anchor_set (const GimpVectors *vectors,
const GimpCoords *coord,
const gboolean new_stroke);
void gimp_bezier_anchor_move_relative (GimpVectors *vectors,
GimpAnchor *anchor,
const GimpCoords *deltacoord,
const gint type);
void gimp_bezier_anchor_move_absolute (GimpVectors *vectors,
GimpAnchor *anchor,
const GimpCoords *coord,
const gint type);
void gimp_bezier_anchor_delete (GimpVectors *vectors,
GimpAnchor *anchor);
/* accessing the shape of the curve */
gdouble gimp_bezier_get_length (const GimpVectors *vectors,
const GimpAnchor *start);
/* returns the number of valid coordinates */
gint gimp_bezier_interpolate (const GimpVectors *vectors,
const GimpStroke *start,
const gdouble precision,
const gint max_points,
GimpCoords *ret_coords);
/* Allow a singular temorary anchor (marking the "working point")? */
GimpAnchor * gimp_bezier_temp_anchor_get (const GimpVectors *vectors);
GimpAnchor * gimp_bezier_temp_anchor_set (GimpVectors *vectors,
const GimpCoords *coord);
gboolean gimp_bezier_temp_anchor_fix (GimpVectors *vectors);
void gimp_bezier_temp_anchor_delete (GimpVectors *vectors);
#endif /* __GIMP_BEZIER_H__ */
/* 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 "gimpbezierstroke.h"
/* private variables */
static GObjectClass *parent_class = NULL;
static void gimp_bezier_stroke_init (GimpBezierStroke *bezier_stroke);
static void
gimp_bezier_stroke_finalize (GObject *object)
{
/* blablabla */
}
static void
gimp_bezier_stroke_class_init (GimpStrokeClass *klass)
{
GObjectClass *object_class;
object_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = gimp_bezier_stroke_finalize;
}
GType
gimp_bezier_stroke_get_type (void)
{
static GType bezier_stroke_type = 0;
if (! bezier_stroke_type)
{
static const GTypeInfo bezier_stroke_info =
{
sizeof (GimpBezierStrokeClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_bezier_stroke_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpBezierStroke),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_bezier_stroke_init,
};
bezier_stroke_type = g_type_register_static (GIMP_TYPE_STROKE,
"GimpBezierStroke",
&bezier_stroke_info, 0);
}
return bezier_stroke_type;
}
static void
gimp_bezier_stroke_init (GimpBezierStroke *bezier_stroke)
{
/* pass */
};
/* Bezier specific functions */
GimpStroke *
gimp_bezier_stroke_new (const GimpCoords *start)
{
GimpBezierStroke *bezier_stroke;
GimpStroke *stroke;
GimpAnchor *anchor;
bezier_stroke = g_object_new (GIMP_TYPE_BEZIER_STROKE, NULL);
stroke = GIMP_STROKE (bezier_stroke);
stroke->anchors = NULL;
anchor = g_new0 (GimpAnchor, 1);
anchor->position.x = start->x;
anchor->position.y = start->y;
anchor->position.pressure = 1;
g_printerr ("Adding at %f, %f\n", start->x, start->y);
anchor->type = 0; /* FIXME */
anchor->active = FALSE;
stroke->anchors = g_list_append (stroke->anchors, anchor);
return stroke;
}
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpbezierstroke.h
* 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.
*/
#ifndef __GIMP_BEZIER_STROKE_H__
#define __GIMP_BEZIER_STROKE_H__
#include "config.h"
#include "glib-object.h"
#include "vectors-types.h"
#include "gimpstroke.h"
#define GIMP_TYPE_BEZIER_STROKE (gimp_bezier_stroke_get_type ())
#define GIMP_BEZIER_STROKE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_BEZIER_STROKE, GimpBezierStroke))
#define GIMP_BEZIER_STROKE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_BEZIER_STROKE, GimpBezierStrokeClass))
#define GIMP_IS_BEZIER_STROKE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_BEZIER_STROKE))
#define GIMP_IS_BEZIER_STROKE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_BEZIER_STROKE))
#define GIMP_BEZIER_STROKE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_BEZIER_STROKE, GimpBezierStrokeClass))
struct _GimpBezierStroke
{
GimpStroke parent_instance;
/* Stuff missing? */
};
struct _GimpBezierStrokeClass
{
GimpStrokeClass parent_class;
};
GType gimp_bezier_stroke_get_type (void) G_GNUC_CONST;
GimpStroke * gimp_bezier_stroke_new (const GimpCoords *start);
#endif /* __GIMP_BEZIER_STROKE_H__ */
/* 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