Commit e2f373cb authored by Simon Budig's avatar Simon Budig Committed by Simon Budig
Browse files

app/Makefile.am app/apptypes.h app/path_bezier.[ch] app/path_curves.[ch]

2001-04-07  Simon Budig  <simon@gimp.org>

        * app/Makefile.am
        * app/apptypes.h
        * app/path_bezier.[ch]
        * app/path_curves.[ch]
        * app/pixmaps2.h
        * app/tools/Makefile.am
        * app/tools/gimpdrawtool.[ch]
        * app/tools/path_tool.[ch]
        * app/tools/path_toolP.h
        * app/tools/tools.c

        new files:
        * app/tools/gimppathtool.c
        * app/tools/gimppathtool.h

        Reactivated (at least partially) the old new path tool. It
        will undergo major restructuring. Especially the path data
        will become proper objects. This definitely is work in progress
        and totally unuseable now.
parent 1187328d
2001-04-07 Simon Budig <simon@gimp.org>
* app/Makefile.am
* app/apptypes.h
* app/path_bezier.[ch]
* app/path_curves.[ch]
* app/pixmaps2.h
* app/tools/Makefile.am
* app/tools/gimpdrawtool.[ch]
* app/tools/path_tool.[ch]
* app/tools/path_toolP.h
* app/tools/tools.c
new files:
* app/tools/gimppathtool.c
* app/tools/gimppathtool.h
Reactivated (at least partially) the old new path tool. It
will undergo major restructuring. Especially the path stuff
will become proper objects. This definitely is work in progress
and totally unuseable now.
2001-04-07 Michael Natterer <mitch@gimp.org>
* configure.in
......
......@@ -240,6 +240,10 @@ gimp_SOURCES = \
paths_dialog.c \
paths_dialog.h \
paths_dialogP.h \
path_curves.h \
path_curves.c \
path_bezier.h \
path_bezier.c \
pattern_header.h \
pattern_select.c \
pattern_select.h \
......
......@@ -79,6 +79,7 @@ typedef struct _GimpToolInfo GimpToolInfo;
typedef struct _GimpTool GimpTool;
typedef struct _GimpPaintTool GimpPaintTool;
typedef struct _GimpDrawTool GimpDrawTool;
typedef struct _GimpPathTool GimpPathTool;
typedef struct _GimpTransformTool GimpTransformTool;
typedef struct _GimpBezierSelectPoint GimpBezierSelectPoint;
......
......@@ -19,6 +19,10 @@
#include <math.h>
#include <glib.h>
#include <gdk/gdk.h>
#include "apptypes.h"
#include "path_curves.h"
#include "path_bezier.h"
#define HANDLE_HALFWIDTH 3
......@@ -33,9 +37,8 @@
*/
guint
path_bezier_get_points (PathTool *path_tool,
PathSegment *segment,
GdkPoint *points,
path_bezier_get_points (PathSegment *segment,
gfloat *points,
guint npoints,
gdouble start,
gdouble end)
......@@ -44,8 +47,7 @@ path_bezier_get_points (PathTool *path_tool,
}
void
path_bezier_get_point (PathTool *path_tool,
PathSegment *segment,
path_bezier_get_point (PathSegment *segment,
gdouble pos,
gdouble *x,
gdouble *y)
......@@ -72,9 +74,10 @@ path_bezier_get_point (PathTool *path_tool,
}
void
path_bezier_draw_handles (GimpTool *tool,
path_bezier_draw_handles (GimpDrawTool *tool,
PathSegment *segment)
{
#if 0
PathTool *path_tool = (PathTool *) (tool->private);
PathBezierData *data = (PathBezierData *) segment->data;
GDisplay * gdisp = tool->gdisp;
......@@ -112,10 +115,11 @@ path_bezier_draw_handles (GimpTool *tool,
HANDLE_WIDTH, HANDLE_WIDTH);
}
}
#endif
}
void
path_bezier_draw_segment (GimpTool *tool,
path_bezier_draw_segment (GimpDrawTool *tool,
PathSegment *segment)
{
return;
......@@ -123,8 +127,7 @@ path_bezier_draw_segment (GimpTool *tool,
gdouble
path_bezier_on_segment (GimpTool *tool,
PathSegment *segment,
path_bezier_on_segment (PathSegment *segment,
gint x,
gint y,
gint halfwidth,
......@@ -134,8 +137,7 @@ path_bezier_on_segment (GimpTool *tool,
}
void
path_bezier_drag_segment (PathTool *path_tool,
PathSegment *segment,
path_bezier_drag_segment (PathSegment *segment,
gdouble pos,
gdouble dx,
gdouble dy)
......@@ -157,8 +159,7 @@ path_bezier_drag_segment (PathTool *path_tool,
}
gint
path_bezier_on_handles (PathTool *path_tool,
PathSegment *segment,
path_bezier_on_handles (PathSegment *segment,
gdouble x,
gdouble y,
gdouble halfwidth)
......@@ -179,8 +180,7 @@ path_bezier_on_handles (PathTool *path_tool,
}
void
path_bezier_drag_handles (PathTool *path_tool,
PathSegment *segment,
path_bezier_drag_handles (PathSegment *segment,
gdouble dx,
gdouble dy,
gint handle_id)
......@@ -198,16 +198,14 @@ path_bezier_drag_handles (PathTool *path_tool,
PathSegment *
path_bezier_insert_anchor (PathTool *path_tool,
PathSegment *segment,
path_bezier_insert_anchor (PathSegment *segment,
gdouble position)
{
return NULL;
}
void
path_bezier_update_segment (PathTool *path_tool,
PathSegment *segment)
path_bezier_update_segment (PathSegment *segment)
{
return;
}
......
......@@ -29,79 +29,67 @@
#define __PATH_BEZIER_H__
#include "path_toolP.h"
typedef struct
{
gdouble x1;
gdouble y1;
gdouble x2;
gdouble y2;
} PathBezierData;
guint
path_bezier_get_points (PathTool *path_tool,
PathSegment *segment,
GdkPoint *points,
path_bezier_get_points (PathSegment *segment,
gfloat *points,
guint npoints,
gdouble start,
gdouble end);
void
path_bezier_get_point (PathTool *path_tool,
PathSegment *segment,
path_bezier_get_point (PathSegment *segment,
gdouble position,
gdouble *x,
gdouble *y);
void
path_bezier_draw_handles (GimpTool *tool,
path_bezier_draw_handles (GimpDrawTool *tool,
PathSegment *segment);
void
path_bezier_draw_segment (GimpTool *tool,
path_bezier_draw_segment (GimpDrawTool *tool,
PathSegment *segment);
gdouble
path_bezier_on_segment (GimpTool *tool,
PathSegment *segment,
path_bezier_on_segment (PathSegment *segment,
gint x,
gint y,
gint halfwidth,
gint *distance);
void
path_bezier_drag_segment (PathTool *path_tool,
PathSegment *segment,
path_bezier_drag_segment (PathSegment *segment,
gdouble position,
gdouble dx,
gdouble dy);
gint
path_bezier_on_handles (PathTool *path_tool,
PathSegment *segment,
path_bezier_on_handles (PathSegment *segment,
gdouble x,
gdouble y,
gdouble halfwidth);
void
path_bezier_drag_handles (PathTool *path_tool,
PathSegment *segment,
path_bezier_drag_handles (PathSegment *segment,
gdouble dx,
gdouble dy,
gint handle_id);
PathSegment *
path_bezier_insert_anchor (PathTool *path_tool,
PathSegment *segment,
path_bezier_insert_anchor (PathSegment *segment,
gdouble position);
void
path_bezier_update_segment (PathTool *path_tool,
PathSegment *segment);
path_bezier_update_segment (PathSegment *segment);
void
path_bezier_flip_segment (PathSegment *segment);
......
......@@ -18,9 +18,14 @@
*/
#include <math.h>
#include <glib.h>
#include <gdk/gdk.h>
#include "apptypes.h"
#include "path_curves.h"
#include "path_bezier.h"
#include "tools/gimpdrawtool.h"
/* only here temporarily */
PathSegment * path_split_segment (PathSegment *, gdouble);
......@@ -37,7 +42,7 @@ static CurveDescription CurveTypes[] =
{
NULL, /* path_bezier_get_points, */
path_bezier_get_point,
path_bezier_draw_handles,
NULL, /* path_bezier_draw_handles, */
NULL, /* path_bezier_draw_segment, */
NULL, /* path_bezier_on_segment, */
path_bezier_drag_segment,
......@@ -60,25 +65,25 @@ static CurveDescription CurveTypes[] =
guint
path_curve_get_points (PathTool *path_tool,
PathSegment *segment,
GdkPoint *points,
path_curve_get_points (PathSegment *segment,
gdouble *points,
guint npoints,
gdouble start,
gdouble end)
{
gdouble pos, x, y;
gint index=0;
if (segment && segment->next) {
if (CurveTypes[segment->type].get_points)
return (* CurveTypes[segment->type].get_points) (path_tool, segment, points, npoints, start, end);
return (* CurveTypes[segment->type].get_points) (segment, points, npoints, start, end);
else {
if (npoints > 1 && segment && segment->next) {
for (pos = start; pos <= end; pos += (end - start) / (npoints -1)) {
path_curve_get_point (path_tool, segment, pos, &x, &y);
points[index].x = (guint) (x + 0.5);
points[index].y = (guint) (y + 0.5);
path_curve_get_point (segment, pos, &points[index*2],
&points[index*2+1]);
index++;
}
return index;
......@@ -95,21 +100,20 @@ path_curve_get_points (PathTool *path_tool,
void
path_curve_get_point (PathTool *path_tool,
PathSegment *segment,
path_curve_get_point (PathSegment *segment,
gdouble position,
gdouble *x,
gdouble *y)
{
if (segment && segment->next) {
if (CurveTypes[segment->type].get_point)
(* CurveTypes[segment->type].get_point) (path_tool, segment, position, x, y);
(* CurveTypes[segment->type].get_point) (segment, position, x, y);
else {
#if 0
*x = segment->x + (segment->next->x - segment->x) * position;
*y = segment->y + (segment->next->y - segment->y) * position;
#else
/* Only here for debugging purposes: A bezier curve fith fixed tangents */
/* Only here for debugging purposes: A bezier curve with fixed tangents */
*x = (1-position)*(1-position)*(1-position) * segment->x +
3 * position *(1-position)*(1-position) * (segment->x - 60) +
......@@ -130,7 +134,7 @@ path_curve_get_point (PathTool *path_tool,
}
void
path_curve_draw_handles (Tool *tool,
path_curve_draw_handles (GimpDrawTool *tool,
PathSegment *segment)
{
if (segment && CurveTypes[segment->type].draw_handles)
......@@ -141,7 +145,7 @@ path_curve_draw_handles (Tool *tool,
}
void
path_curve_draw_segment (Tool *tool,
path_curve_draw_segment (GimpDrawTool *tool,
PathSegment *segment)
{
gint x, y, numpts, index;
......@@ -151,20 +155,9 @@ path_curve_draw_segment (Tool *tool,
(* CurveTypes[segment->type].draw_segment) (tool, segment);
return;
} else {
GdkPoint *coordinates = g_new (GdkPoint, 100);
numpts = path_curve_get_points (((PathTool *) tool->private), segment,
coordinates, 100, 0, 1);
for (index=0; index < numpts; index++) {
gdisplay_transform_coords (tool->gdisp,
coordinates[index].x,
coordinates[index].y,
&x, &y, FALSE);
coordinates[index].x = x;
coordinates[index].y = y;
}
gdk_draw_lines (((PathTool *) tool->private)->core->win,
((PathTool *) tool->private)->core->gc,
coordinates, numpts);
gdouble *coordinates = g_new (gdouble, 200);
numpts = path_curve_get_points (segment, coordinates, 100, 0, 1);
gimp_draw_tool_draw_lines (tool, coordinates, 100, FALSE);
g_free (coordinates);
}
......@@ -180,8 +173,7 @@ path_curve_draw_segment (Tool *tool,
gdouble
path_curve_on_segment (Tool *tool,
PathSegment *segment,
path_curve_on_segment (PathSegment *segment,
gint x,
gint y,
gint halfwidth,
......@@ -189,21 +181,21 @@ path_curve_on_segment (Tool *tool,
{
if (segment && CurveTypes[segment->type].on_segment)
return (* CurveTypes[segment->type].on_segment) (tool, segment, x, y, halfwidth, distance);
return (* CurveTypes[segment->type].on_segment) (segment, x, y, halfwidth, distance);
else {
if (segment && segment->next) {
#if 1
gint x1, y1, numpts, index;
GdkPoint *coordinates = g_new (GdkPoint, 100);
gdouble *coordinates;
gint bestindex = -1;
coordinates = g_new (gdouble, 200);
*distance = halfwidth * halfwidth + 1;
numpts = path_curve_get_points (((PathTool *) tool->private), segment,
coordinates, 100, 0, 1);
numpts = path_curve_get_points (segment, coordinates, 100, 0, 1);
for (index=0; index < numpts; index++) {
x1 = coordinates[index].x;
y1 = coordinates[index].y;
x1 = coordinates[2*index];
y1 = coordinates[2*index+1];
if (((x - x1) * (x - x1) + (y - y1) * (y - y1)) < *distance) {
*distance = (x - x1) * (x - x1) + (y - y1) * (y - y1);
bestindex = index;
......@@ -247,47 +239,43 @@ path_curve_on_segment (Tool *tool,
}
void
path_curve_drag_segment (PathTool *path_tool,
PathSegment *segment,
path_curve_drag_segment (PathSegment *segment,
gdouble position,
gdouble dx,
gdouble dy)
{
if (segment && CurveTypes[segment->type].drag_segment)
(* CurveTypes[segment->type].drag_segment) (path_tool, segment, position, dx, dy);
(* CurveTypes[segment->type].drag_segment) (segment, position, dx, dy);
return;
}
gint
path_curve_on_handle (PathTool *path_tool,
PathSegment *segment,
path_curve_on_handle (PathSegment *segment,
gdouble x,
gdouble y,
gdouble halfwidth)
{
if (segment && CurveTypes[segment->type].on_handles)
return (* CurveTypes[segment->type].on_handles) (path_tool, segment, x, y, halfwidth);
return (* CurveTypes[segment->type].on_handles) (segment, x, y, halfwidth);
return FALSE;
}
void
path_curve_drag_handle (PathTool *path_tool,
PathSegment *segment,
path_curve_drag_handle (PathSegment *segment,
gdouble dx,
gdouble dy,
gint handle_id)
{
if (segment && CurveTypes[segment->type].drag_handle)
(* CurveTypes[segment->type].drag_handle) (path_tool, segment, dx, dy, handle_id);
(* CurveTypes[segment->type].drag_handle) (segment, dx, dy, handle_id);
}
PathSegment *
path_curve_insert_anchor (PathTool *path_tool,
PathSegment *segment,
path_curve_insert_anchor (PathSegment *segment,
gdouble position)
{
if (segment && CurveTypes[segment->type].insert_anchor)
return (* CurveTypes[segment->type].insert_anchor) (path_tool, segment, position);
return (* CurveTypes[segment->type].insert_anchor) (segment, position);
else {
return path_split_segment (segment, position);
}
......@@ -302,11 +290,10 @@ path_curve_flip_segment (PathSegment *segment)
}
void
path_curve_update_segment (PathTool *path_tool,
PathSegment *segment)
path_curve_update_segment (PathSegment *segment)
{
if (segment && CurveTypes[segment->type].update_segment)
(* CurveTypes[segment->type].update_segment) (path_tool, segment);
(* CurveTypes[segment->type].update_segment) (segment);
return;
}
......
......@@ -20,8 +20,85 @@
#ifndef __PATH_CURVES_H__
#define __PATH_CURVES_H__
#include <gdk/gdk.h>
#include "path_toolP.h"
#undef PATH_TOOL_DEBUG
#ifdef PATH_TOOL_DEBUG
#include <stdio.h>
#endif
#define IMAGE_COORDS 1
#define AA_IMAGE_COORDS 2
#define SCREEN_COORDS 3
#define SEGMENT_ACTIVE 1
#define PATH_TOOL_DRAG 1
#define PATH_TOOL_REDRAW_ALL 1
#define PATH_TOOL_REDRAW_ACTIVE 2
#define PATH_TOOL_REDRAW_HANDLES 4
#define SUBDIVIDE 1000
typedef enum { SEGMENT_LINE=0, SEGMENT_BEZIER} SegmentType;
enum { ON_ANCHOR, ON_HANDLE, ON_CURVE, ON_CANVAS };
typedef struct _path_segment PathSegment;
typedef struct _path_curve PathCurve;
typedef struct _npath NPath;
struct _path_segment
{
SegmentType type; /* What type of segment */
gdouble x, y; /* location of starting-point in image space */
gpointer data; /* Additional data, dependant of segment-type */
guint32 flags; /* Various Flags: Is the Segment active? */
PathCurve *parent; /* the parent Curve */
PathSegment *next; /* Next Segment or NULL */
PathSegment *prev; /* Previous Segment or NULL */
};
struct _path_curve
{
PathSegment *segments; /* The segments of the curve */
PathSegment *cur_segment; /* the current segment */
NPath *parent; /* the parent Path */
PathCurve *next; /* Next Curve or NULL */
PathCurve *prev; /* Previous Curve or NULL */
};
struct _npath
{
PathCurve *curves; /* the curves */
PathCurve *cur_curve; /* the current curve */
GString *name; /* the name of the path */
guint32 state; /* is the path locked? */
/* GimpPathTool *path_tool; */ /* The parent Path Tool */
};
typedef void
(*PathTraverseFunc) (NPath *,
PathCurve *,
gpointer);
typedef void
(*CurveTraverseFunc) (NPath *,
PathCurve *,
PathSegment *,
gpointer);
typedef void
(*SegmentTraverseFunc) (NPath *,
PathCurve *,
PathSegment *,
gint,
gint,
gpointer);
/*
......@@ -32,57 +109,49 @@
* Array is allocated.
*/
typedef guint (*PathGetPointsFunc) (PathTool *path_tool,
PathSegment *segment,
GdkPoint *points,
typedef guint (*PathGetPointsFunc) (PathSegment *segment,
gdouble *points,
guint npoints,
gdouble start,
gdouble end);
typedef void (*PathGetPointFunc) (PathTool *path_tool,
PathSegment *segment,
typedef void (*PathGetPointFunc) (PathSegment *segment,
gdouble position,
gdouble *x,
gdouble *y);
typedef void (*PathDrawHandlesFunc) (Tool *tool,
typedef void (*PathDrawHandlesFunc) (GimpDrawTool *tool,
PathSegment *segment);
typedef void (*PathDrawSegmentFunc) (Tool *tool,
typedef void (*PathDrawSegmentFunc) (GimpDrawTool *tool,
PathSegment *segment);
typedef gdouble (*PathOnSegmentFunc) (Tool *tool,
PathSegment *segment,
typedef gdouble (*PathOnSegmentFunc) (PathSegment *segment,
gint x,
gint y,
gint halfwidth,
gint *distance);
typedef void (*PathDragSegmentFunc) (PathTool *path_tool,
PathSegment *segment,
typedef void (*PathDragSegmentFunc) (PathSegment *segment,
gdouble position,
gdouble dx,
gdouble dy);
typedef gint (*PathOnHandlesFunc) (PathTool *path_tool,
PathSegment *segment,
typedef gint (*PathOnHandlesFunc) (PathSegment *segment,
gdouble x,
gdouble y,
gdouble halfwidth);
typedef void (*PathDragHandleFunc) (PathTool *path_tool,
PathSegment *segment,
typedef void (*PathDragHandleFunc) (PathSegment *segment,
gdouble dx,
gdouble dy,
gint handle_id);
typedef PathSegment * (*PathInsertAnchorFunc) (PathTool *path_tool,
PathSegment *segment,
typedef PathSegment * (*PathInsertAnchorFunc) (PathSegment *segment,
gdouble position);
typedef void (*PathUpdateSegmentFunc) (PathTool *path_tool,
PathSegment *segment);
typedef void (*PathUpdateSegmentFunc) (PathSegment *segment);
typedef void (*PathFlipSegmentFunc) (PathSegment *segment);
......@@ -108,66 +177,58 @@ typedef struct {