Commit 62b61811 authored by Simon Budig's avatar Simon Budig Committed by Simon Budig

New Type: GimpVectorExtendMode

2002-12-31  Simon Budig  <simon@gimp.org>

        * app/vectors/vectors-types.h: New Type: GimpVectorExtendMode

        * app/tools/gimpvectortool.c
        * app/vectors/gimpstroke.[ch]
        * app/vectors/gimpbezierstroke.[ch]: More stuff on the path
        (pun intended) to a better path tool...

        Thanks to Sven for being my host in Berlin!
parent 8c692331
2002-12-31 Simon Budig <simon@gimp.org>
* app/vectors/vectors-types.h: New Type: GimpVectorExtendMode
* app/tools/gimpvectortool.c
* app/vectors/gimpstroke.[ch]
* app/vectors/gimpbezierstroke.[ch]: More stuff on the path
(pun intended) to a better path tool...
Thanks to Sven for being my host in Berlin!
2002-12-31 Sven Neumann <sven@gimp.org>
* tools/pdbgen/pdb/fileops.pdb (gimp_temp_name): need to expand the
......
......@@ -51,7 +51,7 @@
/* definitions */
#define TARGET 8
#define TARGET 9
#define ARC_RADIUS 30
#define STATUSBAR_SIZE 128
......@@ -273,15 +273,19 @@ gimp_vector_tool_button_press (GimpTool *tool,
{
gimp_draw_tool_pause (GIMP_DRAW_TOOL (vector_tool));
vector_tool->function = VECTORS_MOVING;
vector_tool->cur_stroke = stroke;
vector_tool->cur_anchor = anchor;
if (anchor->type == ANCHOR_HANDLE)
gimp_stroke_anchor_select (stroke, anchor, TRUE);
/* doublecheck if there are control handles at this anchor */
anchor = gimp_vectors_anchor_get (vector_tool->vectors,
coords, &stroke);
vector_tool->function = VECTORS_MOVING;
vector_tool->cur_stroke = stroke;
vector_tool->cur_anchor = anchor;
gimp_draw_tool_resume (GIMP_DRAW_TOOL (vector_tool));
}
}
if (vector_tool->function == VECTORS_CREATING)
......@@ -324,13 +328,9 @@ gimp_vector_tool_button_press (GimpTool *tool,
gimp_draw_tool_stop (GIMP_DRAW_TOOL (vector_tool));
}
anchor = gimp_bezier_stroke_extend (GIMP_BEZIER_STROKE (vector_tool->cur_stroke), coords, vector_tool->cur_anchor);
anchor = gimp_bezier_stroke_extend (GIMP_BEZIER_STROKE (vector_tool->cur_stroke), coords, vector_tool->cur_anchor, EXTEND_EDITABLE);
if (anchor)
{
vector_tool->cur_anchor = anchor;
if (anchor->type == ANCHOR_HANDLE)
gimp_stroke_anchor_select (stroke, anchor, TRUE);
}
vector_tool->cur_anchor = anchor;
/* set the gdisplay */
tool->gdisp = gdisp;
......@@ -491,8 +491,7 @@ gimp_vector_tool_draw (GimpDrawTool *draw_tool)
g_list_free (draw_anchors);
/* control handles */
draw_anchors = gimp_stroke_get_draw_controls (cur_stroke,
vector_tool->cur_anchor);
draw_anchors = gimp_stroke_get_draw_controls (cur_stroke);
ptr = draw_anchors;
while (ptr)
......@@ -503,8 +502,8 @@ gimp_vector_tool_draw (GimpDrawTool *draw_tool)
GIMP_HANDLE_SQUARE,
cur_anchor->position.x,
cur_anchor->position.y,
TARGET-1,
TARGET-1,
TARGET-2,
TARGET-2,
GTK_ANCHOR_CENTER,
FALSE);
ptr = ptr->next;
......@@ -513,7 +512,7 @@ gimp_vector_tool_draw (GimpDrawTool *draw_tool)
g_list_free (draw_anchors);
/* the lines to the control handles */
coords = gimp_stroke_get_draw_lines (cur_stroke, vector_tool->cur_anchor);
coords = gimp_stroke_get_draw_lines (cur_stroke);
if (coords->len % 2 == 0)
{
......
......@@ -172,7 +172,7 @@ gimp_bezier_stroke_new (const GimpCoords *start)
g_printerr ("Adding at %f, %f\n", start->x, start->y);
anchor->type = ANCHOR_HANDLE;
anchor->selected = FALSE;
anchor->selected = TRUE;
stroke->anchors = g_list_append (stroke->anchors, anchor);
return stroke;
......@@ -200,7 +200,8 @@ gimp_bezier_stroke_new_from_coords (const GimpCoords *coords,
{
last_anchor = gimp_bezier_stroke_extend (bezier_stroke,
&(coords[count]),
last_anchor);
last_anchor,
EXTEND_SIMPLE);
}
}
return stroke;
......@@ -208,15 +209,15 @@ gimp_bezier_stroke_new_from_coords (const GimpCoords *coords,
GimpAnchor *
gimp_bezier_stroke_extend (GimpBezierStroke *bezier_stroke,
const GimpCoords *coords,
GimpAnchor *neighbor)
gimp_bezier_stroke_extend (GimpBezierStroke *bezier_stroke,
const GimpCoords *coords,
GimpAnchor *neighbor,
GimpVectorExtendMode extend_mode)
{
GimpAnchor *anchor;
GimpAnchor *anchor=NULL;
GimpStroke *stroke;
GList *listneighbor;
gint loose_end;
GimpAnchorType ntype1 = -1, ntype2 = -1;
gint loose_end, control_count;
g_return_val_if_fail (GIMP_IS_BEZIER_STROKE (bezier_stroke), NULL);
g_return_val_if_fail ((neighbor != NULL), NULL);
......@@ -245,57 +246,97 @@ gimp_bezier_stroke_extend (GimpBezierStroke *bezier_stroke,
if (loose_end)
{
anchor = g_new0 (GimpAnchor, 1);
anchor->position.x = coords->x;
anchor->position.y = coords->y;
anchor->position.pressure = 1.0;
anchor->position.xtilt = 0.5;
anchor->position.ytilt = 0.5;
anchor->position.wheel = 0.5;
anchor->selected = FALSE;
/* We have to detect the type of the point to add... */
/* We have to detect the type of the newly added point... */
control_count = 0;
ntype1 = ((GimpAnchor *) listneighbor->data)->type;
if (loose_end == 1 && listneighbor->prev)
{
ntype2 = ((GimpAnchor *) listneighbor->prev->data)->type;
}
else if (loose_end == -1 && listneighbor->next)
if (loose_end == 1)
{
ntype2 = ((GimpAnchor *) listneighbor->next->data)->type;
while (listneighbor &&
((GimpAnchor *) listneighbor->data)->type == CONTROL_HANDLE)
{
control_count++;
listneighbor = listneighbor->prev;
}
}
else
{
anchor->type = CONTROL_HANDLE;
while (listneighbor &&
((GimpAnchor *) listneighbor->data)->type == CONTROL_HANDLE)
{
control_count++;
listneighbor = listneighbor->next;
}
}
if (ntype1 == ANCHOR_HANDLE)
switch (extend_mode)
{
anchor->type = CONTROL_HANDLE;
}
else
{
if (ntype2 == CONTROL_HANDLE)
{
anchor->type = ANCHOR_HANDLE;
}
else
case EXTEND_SIMPLE:
anchor = g_new0 (GimpAnchor, 1);
anchor->position.x = coords->x;
anchor->position.y = coords->y;
anchor->position.pressure = 1.0;
anchor->position.xtilt = 0.5;
anchor->position.ytilt = 0.5;
anchor->position.wheel = 0.5;
anchor->selected = FALSE;
switch (control_count)
{
case 0:
case 1:
anchor->type = CONTROL_HANDLE;
break;
case 2:
anchor->type = ANCHOR_HANDLE;
break;
default:
g_printerr ("inconsistent bezier curve: "
"%d successive control handles", control_count);
}
}
g_printerr ("Extending at %f, %f, type %d\n",
coords->x, coords->y, anchor->type);
g_printerr ("Extending at %f, %f, type %d\n",
coords->x, coords->y, anchor->type);
if (loose_end == 1)
stroke->anchors = g_list_append (stroke->anchors, anchor);
if (loose_end == 1)
stroke->anchors = g_list_append (stroke->anchors, anchor);
if (loose_end == -1)
stroke->anchors = g_list_prepend (stroke->anchors, anchor);
if (loose_end == -1)
stroke->anchors = g_list_prepend (stroke->anchors, anchor);
break;
case EXTEND_EDITABLE:
switch (control_count)
{
case 0:
neighbor = gimp_bezier_stroke_extend (bezier_stroke,
&(neighbor->position),
neighbor,
EXTEND_SIMPLE);
case 1:
neighbor = gimp_bezier_stroke_extend (bezier_stroke,
coords,
neighbor,
EXTEND_SIMPLE);
case 2:
neighbor = gimp_bezier_stroke_extend (bezier_stroke,
coords,
neighbor,
EXTEND_SIMPLE);
gimp_stroke_anchor_select (stroke, neighbor, TRUE);
anchor = gimp_bezier_stroke_extend (bezier_stroke,
coords,
neighbor,
EXTEND_SIMPLE);
break;
default:
g_printerr ("inconsistent bezier curve: "
"%d successive control handles", control_count);
}
}
return anchor;
}
else
......
......@@ -61,9 +61,10 @@ GimpStroke * gimp_bezier_stroke_new (const GimpCoords *start);
GimpStroke * gimp_bezier_stroke_new_from_coords (const GimpCoords *coords,
const gint ncoords);
GimpAnchor * gimp_bezier_stroke_extend (GimpBezierStroke *bezier_stroke,
const GimpCoords *coords,
GimpAnchor *neighbor);
GimpAnchor * gimp_bezier_stroke_extend (GimpBezierStroke *bezier_stroke,
const GimpCoords *coords,
GimpAnchor *neighbor,
GimpVectorExtendMode extend_mode);
GArray * gimp_bezier_stroke_interpolate (const GimpStroke *stroke,
const gdouble precision,
......
......@@ -149,27 +149,33 @@ static GimpAnchor *
gimp_stroke_real_anchor_get (const GimpStroke *stroke,
const GimpCoords *coord)
{
gdouble dx, dy, mindist;
gdouble dx, dy, mindist = -1;
GList *list;
GimpAnchor *anchor = NULL;
g_return_val_if_fail (GIMP_IS_STROKE (stroke), NULL);
list = stroke->anchors;
if (list)
list = gimp_stroke_get_draw_controls (stroke);
while (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;
if (mindist < 0 || mindist > dx * dx + dy * dy)
{
mindist = dx * dx + dy * dy;
anchor = (GimpAnchor *) list->data;
}
list = list->next;
}
list = gimp_stroke_get_draw_anchors (stroke);
while (list)
{
dx = coord->x - ((GimpAnchor *) list->data)->position.x;
dy = coord->y - ((GimpAnchor *) list->data)->position.y;
if (mindist > dx * dx + dy * dy)
if (mindist < 0 || mindist > dx * dx + dy * dy)
{
mindist = dx * dx + dy * dy;
anchor = (GimpAnchor *) list->data;
......@@ -500,8 +506,7 @@ gimp_stroke_get_draw_anchors (const GimpStroke *stroke)
GList *
gimp_stroke_get_draw_controls (const GimpStroke *stroke,
const GimpAnchor *active)
gimp_stroke_get_draw_controls (const GimpStroke *stroke)
{
GimpStrokeClass *stroke_class;
......@@ -510,7 +515,7 @@ gimp_stroke_get_draw_controls (const GimpStroke *stroke,
stroke_class = GIMP_STROKE_GET_CLASS (stroke);
if (stroke_class->get_draw_controls)
return stroke_class->get_draw_controls (stroke, active);
return stroke_class->get_draw_controls (stroke);
else
{
GList *cur_ptr, *ret_list = NULL;
......@@ -540,8 +545,7 @@ gimp_stroke_get_draw_controls (const GimpStroke *stroke,
}
GArray *
gimp_stroke_get_draw_lines (const GimpStroke *stroke,
const GimpAnchor *active)
gimp_stroke_get_draw_lines (const GimpStroke *stroke)
{
GimpStrokeClass *stroke_class;
......@@ -550,7 +554,7 @@ gimp_stroke_get_draw_lines (const GimpStroke *stroke,
stroke_class = GIMP_STROKE_GET_CLASS (stroke);
if (stroke_class->get_draw_lines)
return stroke_class->get_draw_lines (stroke, active);
return stroke_class->get_draw_lines (stroke);
else
{
GList *cur_ptr;
......
......@@ -99,11 +99,9 @@ struct _GimpStrokeClass
GList * (* get_draw_anchors) (const GimpStroke *stroke);
GList * (* get_draw_controls) (const GimpStroke *stroke,
const GimpAnchor *active);
GList * (* get_draw_controls) (const GimpStroke *stroke);
GArray * (* get_draw_lines) (const GimpStroke *stroke,
const GimpAnchor *active);
GArray * (* get_draw_lines) (const GimpStroke *stroke);
};
......@@ -176,10 +174,8 @@ GimpStroke * gimp_stroke_make_bezier (const GimpStroke *stroke);
GList * gimp_stroke_get_draw_anchors (const GimpStroke *stroke);
GList * gimp_stroke_get_draw_controls (const GimpStroke *stroke,
const GimpAnchor *active);
GList * gimp_stroke_get_draw_controls (const GimpStroke *stroke);
GArray * gimp_stroke_get_draw_lines (const GimpStroke *stroke,
const GimpAnchor *active);
GArray * gimp_stroke_get_draw_lines (const GimpStroke *stroke);
#endif /* __GIMP_STROKE_H__ */
......@@ -33,6 +33,12 @@ typedef enum
CONTROL_HANDLE,
} GimpAnchorType;
typedef enum
{
EXTEND_SIMPLE,
EXTEND_EDITABLE,
} GimpVectorExtendMode;
typedef struct _GimpStroke GimpStroke;
typedef struct _GimpStrokeClass GimpStrokeClass;
typedef struct _GimpBezierStroke GimpBezierStroke;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment