diff --git a/ChangeLog b/ChangeLog index 49d6a6a480..fa590a4c2b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2002-02-25 Simon Budig + + * app/vectors/gimpbezierstroke.c + * app/tools/gimpvectortool.[ch] + * app/vectors/gimpstroke.[ch] + * app/vectors/gimpvectors.[ch]: Fixed various bugs, *including* + the nasty one from this morning (thanks Mitch). + 2002-02-25 Sven Neumann * app/gui/tips-parser.[ch]: strip newlines, tabs and adjacent spaces diff --git a/app/tools/gimpvectortool.c b/app/tools/gimpvectortool.c index c7df916ac1..ac581236e2 100644 --- a/app/tools/gimpvectortool.c +++ b/app/tools/gimpvectortool.c @@ -234,8 +234,8 @@ gimp_vector_tool_button_press (GimpTool *tool, GimpDisplayShell *shell; gint i; GimpCoords cur_point; - GimpAnchor *anchor; - GimpStroke *stroke; + GimpAnchor *anchor = NULL; + GimpStroke *stroke = NULL; vector_tool = GIMP_VECTOR_TOOL (tool); @@ -257,7 +257,8 @@ gimp_vector_tool_button_press (GimpTool *tool, * the new function will be moving or adding a new point or guide */ - anchor = gimp_vectors_anchor_get (vector_tool->vectors, coords); + + anchor = gimp_vectors_anchor_get (vector_tool->vectors, coords, &stroke); if (anchor && gimp_draw_tool_on_handle (GIMP_DRAW_TOOL (tool), gdisp, coords->x, @@ -270,6 +271,7 @@ gimp_vector_tool_button_press (GimpTool *tool, FALSE)) { vector_tool->function = VMOVING; + vector_tool->cur_stroke = stroke; vector_tool->cur_anchor = anchor; } @@ -288,6 +290,7 @@ gimp_vector_tool_button_press (GimpTool *tool, gimp_vectors_stroke_add (vector_tool->vectors, stroke); + vector_tool->cur_stroke = stroke; vector_tool->cur_anchor = anchor; vector_tool->function = VMOVING; @@ -346,9 +349,9 @@ gimp_vector_tool_motion (GimpTool *tool, anchor = vector_tool->cur_anchor; if (anchor) - gimp_vectors_anchor_move_absolute (vector_tool->vectors, - vector_tool->cur_anchor, - coords, 0); + gimp_stroke_anchor_move_absolute (vector_tool->cur_stroke, + vector_tool->cur_anchor, + coords, 0); default: break; @@ -374,7 +377,7 @@ gimp_vector_tool_cursor_update (GimpTool *tool, if (tool->state == ACTIVE && tool->gdisp == gdisp) { - anchor = gimp_vectors_anchor_get (vector_tool->vectors, coords); + anchor = gimp_vectors_anchor_get (vector_tool->vectors, coords, NULL); if (anchor && gimp_draw_tool_on_handle (GIMP_DRAW_TOOL (tool), gdisp, coords->x, @@ -417,7 +420,6 @@ gimp_vector_tool_draw (GimpDrawTool *draw_tool) 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, @@ -426,7 +428,6 @@ gimp_vector_tool_draw (GimpDrawTool *draw_tool) TARGET, GTK_ANCHOR_CENTER, FALSE); - G_BREAKPOINT(); } } diff --git a/app/tools/gimpvectortool.h b/app/tools/gimpvectortool.h index 16092f0b56..ae8e9e1ead 100644 --- a/app/tools/gimpvectortool.h +++ b/app/tools/gimpvectortool.h @@ -59,7 +59,8 @@ struct _GimpVectorTool gdouble angle1; /* first angle */ gdouble angle2; /* second angle */ - GimpAnchor *cur_anchor; /* The current Anchor */ + GimpAnchor *cur_anchor; /* The current Anchor */ + GimpStroke *cur_stroke; /* The current Stroke */ GimpVectors *vectors; /* The current Vector data */ }; diff --git a/app/vectors/gimpbezierstroke.c b/app/vectors/gimpbezierstroke.c index 23b8b77f43..63f73c3bdf 100644 --- a/app/vectors/gimpbezierstroke.c +++ b/app/vectors/gimpbezierstroke.c @@ -37,10 +37,10 @@ static GimpStrokeClass *parent_class = NULL; -static void gimp_bezier_stroke_class_init (GimpStrokeClass *klass); -static void gimp_bezier_stroke_init (GimpBezierStroke *bezier_stroke); +static void gimp_bezier_stroke_class_init (GimpBezierStrokeClass *klass); +static void gimp_bezier_stroke_init (GimpBezierStroke *bezier_stroke); -static void gimp_bezier_stroke_finalize (GObject *object); +static void gimp_bezier_stroke_finalize (GObject *object); GType @@ -72,11 +72,11 @@ gimp_bezier_stroke_get_type (void) } static void -gimp_bezier_stroke_class_init (GimpStrokeClass *klass) +gimp_bezier_stroke_class_init (GimpBezierStrokeClass *klass) { GObjectClass *object_class; - object_class = G_OBJECT_CLASS (klass); + object_class = G_OBJECT_CLASS (klass); parent_class = g_type_class_peek_parent (klass); diff --git a/app/vectors/gimpstroke.c b/app/vectors/gimpstroke.c index 26afd1e92b..7fd0fcf087 100644 --- a/app/vectors/gimpstroke.c +++ b/app/vectors/gimpstroke.c @@ -120,6 +120,7 @@ static void gimp_stroke_init (GimpStroke *stroke) { stroke->anchors = NULL; + stroke->next = NULL; }; static void @@ -134,18 +135,9 @@ GimpAnchor * gimp_stroke_anchor_get (const GimpStroke *stroke, const GimpCoords *coord) { - GimpStrokeClass *stroke_class; - g_return_val_if_fail (GIMP_IS_STROKE (stroke), NULL); - stroke_class = GIMP_STROKE_GET_CLASS (stroke); - - if (stroke_class->anchor_get) - return stroke_class->anchor_get (stroke, coord); - else - g_printerr ("gimp_stroke_anchor_get: default implementation\n"); - - return NULL; + return (GIMP_STROKE_GET_CLASS (stroke))->anchor_get (stroke, coord); } @@ -192,18 +184,9 @@ gimp_stroke_anchor_get_next (const GimpStroke *stroke, GimpStrokeClass *stroke_class; g_return_val_if_fail (GIMP_IS_STROKE (stroke), NULL); - stroke_class = GIMP_STROKE_GET_CLASS (stroke); - if (stroke_class->anchor_get_next) - { - g_printerr ("gimp_stroke_anchor_get_next: calling alien: Intended: %p, actually %p\n", gimp_stroke_real_anchor_get_next, stroke_class->anchor_get_next); - return stroke_class->anchor_get_next (stroke, prev); - } - else - g_printerr ("gimp_stroke_anchor_get_next: default implementation\n"); - - return NULL; + return stroke_class->anchor_get_next (stroke, prev); } @@ -211,24 +194,21 @@ static GimpAnchor * gimp_stroke_real_anchor_get_next (const GimpStroke *stroke, const GimpAnchor *prev) { - static GList *last_shown = NULL; + GList *listitem; - g_printerr ("gimp_stroke_real_anchor_get_next 1\n"); g_return_val_if_fail (GIMP_IS_STROKE (stroke), NULL); - g_printerr ("gimp_stroke_real_anchor_get_next 2\n"); - if (!prev) { - last_shown = stroke->anchors; - } else { - if (last_shown != NULL && last_shown->data != prev) { - last_shown = g_list_find (stroke->anchors, prev); + if (prev) + { + listitem = g_list_find (stroke->anchors, prev); + if (listitem) + listitem = g_list_next (listitem); } - if (last_shown != NULL) - last_shown = last_shown->next; - } + else + listitem = stroke->anchors; - if (last_shown) - return (GimpAnchor *) last_shown->data; + if (listitem) + return (GimpAnchor *) listitem->data; return NULL; } @@ -246,12 +226,7 @@ gimp_stroke_anchor_move_relative (GimpStroke *stroke, stroke_class = GIMP_STROKE_GET_CLASS (stroke); - if (stroke_class->anchor_move_relative) - stroke_class->anchor_move_relative (stroke, anchor, deltacoord, type); - else - g_printerr ("gimp_stroke_anchor_move_relative: default implementation\n"); - - return; + stroke_class->anchor_move_relative (stroke, anchor, deltacoord, type); } @@ -284,12 +259,7 @@ gimp_stroke_anchor_move_absolute (GimpStroke *stroke, stroke_class = GIMP_STROKE_GET_CLASS (stroke); - if (stroke_class->anchor_move_absolute) - stroke_class->anchor_move_absolute (stroke, anchor, coord, type); - else - g_printerr ("gimp_stroke_anchor_move_absolute: default implementation\n"); - - return; + stroke_class->anchor_move_absolute (stroke, anchor, coord, type); } diff --git a/app/vectors/gimpstroke.h b/app/vectors/gimpstroke.h index 1a00fe4523..04c17019a4 100644 --- a/app/vectors/gimpstroke.h +++ b/app/vectors/gimpstroke.h @@ -33,17 +33,18 @@ struct _GimpStroke { - GObject parent_instance; - - GList *anchors; + GObject parent_instance; + + GList *anchors; + GimpStroke *next; /* Stuff missing */ }; struct _GimpStrokeClass { - GObject parent_class; + GObjectClass parent_class; void (* changed) (GimpStroke *stroke); diff --git a/app/vectors/gimpvectors.c b/app/vectors/gimpvectors.c index c69605dc2d..26c35ba6b1 100644 --- a/app/vectors/gimpvectors.c +++ b/app/vectors/gimpvectors.c @@ -102,18 +102,11 @@ gimp_vectors_class_init (GimpVectorsClass *klass) klass->stroke_get_length = NULL; klass->anchor_get = NULL; - klass->anchor_move_relative = NULL; - klass->anchor_move_absolute = NULL; - klass->anchor_delete = NULL; klass->get_length = NULL; klass->get_distance = NULL; klass->interpolate = NULL; - klass->temp_anchor_get = NULL; - klass->temp_anchor_set = NULL; - klass->temp_anchor_fix = NULL; - klass->make_bezier = NULL; } @@ -152,7 +145,8 @@ gimp_vectors_get_image (const GimpVectors *vectors) GimpAnchor * gimp_vectors_anchor_get (const GimpVectors *vectors, - const GimpCoords *coord) + const GimpCoords *coord, + GimpStroke **ret_stroke) { GimpVectorsClass *vectors_class; @@ -161,18 +155,18 @@ gimp_vectors_anchor_get (const GimpVectors *vectors, vectors_class = GIMP_VECTORS_GET_CLASS (vectors); if (vectors_class->anchor_get) - return vectors_class->anchor_get (vectors, coord); + return vectors_class->anchor_get (vectors, coord, ret_stroke); else { gdouble dx, dy, mindist; - GList *list; + GimpStroke *stroke; GimpAnchor *anchor = NULL, *minanchor = NULL; mindist = -1; - for (list = vectors->strokes; list; list = g_list_next (list)) + for (stroke = vectors->strokes; stroke; stroke = stroke->next) { - anchor = gimp_stroke_anchor_get (GIMP_STROKE (list->data), coord); + anchor = gimp_stroke_anchor_get (stroke, coord); if (anchor) { dx = coord->x - anchor->position.x; @@ -181,6 +175,8 @@ gimp_vectors_anchor_get (const GimpVectors *vectors, { mindist = dx * dx + dy * dy; minanchor = anchor; + if (ret_stroke) + *ret_stroke = stroke; } } } @@ -191,69 +187,6 @@ gimp_vectors_anchor_get (const GimpVectors *vectors, } - -void -gimp_vectors_anchor_move_relative (GimpVectors *vectors, - GimpAnchor *anchor, - const GimpCoords *deltacoord, - const gint type) -{ - GimpVectorsClass *vectors_class; - - g_return_if_fail (GIMP_IS_VECTORS (vectors)); - - vectors_class = GIMP_VECTORS_GET_CLASS (vectors); - - if (vectors_class->anchor_move_relative) - vectors_class->anchor_move_relative (vectors, anchor, deltacoord, type); - else - g_printerr ("gimp_vectors_anchor_move_relative: default implementation\n"); - - return; -} - - -void -gimp_vectors_anchor_move_absolute (GimpVectors *vectors, - GimpAnchor *anchor, - const GimpCoords *coord, - const gint type) -{ - GimpVectorsClass *vectors_class; - - g_return_if_fail (GIMP_IS_VECTORS (vectors)); - - vectors_class = GIMP_VECTORS_GET_CLASS (vectors); - - if (vectors_class->anchor_move_absolute) - vectors_class->anchor_move_absolute (vectors, anchor, coord, type); - else - g_printerr ("gimp_vectors_anchor_move_absolute: default implementation\n"); - - return; -} - - -void -gimp_vectors_anchor_delete (GimpVectors *vectors, - GimpAnchor *anchor) -{ - GimpVectorsClass *vectors_class; - - g_return_if_fail (GIMP_IS_VECTORS (vectors)); - - vectors_class = GIMP_VECTORS_GET_CLASS (vectors); - - if (vectors_class->anchor_delete) - vectors_class->anchor_delete (vectors, anchor); - else - g_printerr ("gimp_vectors_anchor_delete: default implementation\n"); - - return; -} - - - void gimp_vectors_stroke_add (GimpVectors *vectors, GimpStroke *stroke) @@ -266,15 +199,15 @@ gimp_vectors_stroke_add (GimpVectors *vectors, vectors_class = GIMP_VECTORS_GET_CLASS (vectors); if (vectors_class->stroke_add) - vectors_class->stroke_add (vectors, stroke); + { + vectors_class->stroke_add (vectors, stroke); + } else { - vectors->strokes = g_list_append (vectors->strokes, stroke); + stroke->next = vectors->strokes; + vectors->strokes = stroke; g_object_ref (G_OBJECT (stroke)); - g_printerr ("gimp_vectors_stroke_add: default implementation\n"); } - - return; } @@ -293,16 +226,16 @@ gimp_vectors_stroke_get (const GimpVectors *vectors, else { gdouble dx, dy, mindist; - GList *list; + GimpStroke *stroke; GimpStroke *minstroke = NULL; GimpAnchor *anchor = NULL; mindist = -1; - list = vectors->strokes; + stroke = GIMP_STROKE (vectors->strokes); - while (list) + while (stroke) { - anchor = gimp_stroke_anchor_get (GIMP_STROKE (list->data), coord); + anchor = gimp_stroke_anchor_get (stroke, coord); if (anchor) { dx = coord->x - anchor->position.x; @@ -310,10 +243,10 @@ gimp_vectors_stroke_get (const GimpVectors *vectors, if (mindist > dx * dx + dy * dy || mindist < 0) { mindist = dx * dx + dy * dy; - minstroke = GIMP_STROKE (list->data); + minstroke = stroke; } } - list = list->next; + stroke = stroke->next; } return minstroke; } @@ -327,7 +260,6 @@ gimp_vectors_stroke_get_next (const GimpVectors *vectors, const GimpStroke *prev) { GimpVectorsClass *vectors_class; - static GList *last_shown = NULL; g_return_val_if_fail (GIMP_IS_VECTORS (vectors), NULL); @@ -337,20 +269,15 @@ gimp_vectors_stroke_get_next (const GimpVectors *vectors, return vectors_class->stroke_get_next (vectors, prev); else { - g_printerr ("gimp_vectors_stroke_get_next: default implementation\n"); - - if (!prev) { - last_shown = vectors->strokes; - } else { - if (last_shown != NULL && last_shown->data != prev) { - last_shown = g_list_find (vectors->strokes, prev); + if (!prev) + { + return vectors->strokes; + } + else + { + g_return_val_if_fail (GIMP_IS_STROKE (prev), NULL); + return prev->next; } - if (last_shown != NULL) - last_shown = last_shown->next; - } - - if (last_shown) - return GIMP_STROKE (last_shown->data); } return NULL; @@ -436,61 +363,6 @@ gimp_vectors_interpolate (const GimpVectors *vectors, } -GimpAnchor * -gimp_vectors_temp_anchor_get (const GimpVectors *vectors) -{ - GimpVectorsClass *vectors_class; - - g_return_val_if_fail (GIMP_IS_VECTORS (vectors), NULL); - - vectors_class = GIMP_VECTORS_GET_CLASS (vectors); - - if (vectors_class->temp_anchor_get) - return vectors_class->temp_anchor_get (vectors); - else - g_printerr ("gimp_vectors_temp_anchor_get: default implementation\n"); - - return NULL; -} - - -GimpAnchor * -gimp_vectors_temp_anchor_set (GimpVectors *vectors, - const GimpCoords *coord) -{ - GimpVectorsClass *vectors_class; - - g_return_val_if_fail (GIMP_IS_VECTORS (vectors), NULL); - - vectors_class = GIMP_VECTORS_GET_CLASS (vectors); - - if (vectors_class->temp_anchor_set) - return vectors_class->temp_anchor_set (vectors, coord); - else - g_printerr ("gimp_vectors_temp_anchor_set: default implementation\n"); - - return NULL; -} - - -gboolean -gimp_vectors_temp_anchor_fix (GimpVectors *vectors) -{ - GimpVectorsClass *vectors_class; - - g_return_val_if_fail (GIMP_IS_VECTORS (vectors), FALSE); - - vectors_class = GIMP_VECTORS_GET_CLASS (vectors); - - if (vectors_class->temp_anchor_fix) - return vectors_class->temp_anchor_fix (vectors); - else - g_printerr ("gimp_vectors_temp_anchor_fix: default implementation\n"); - - return FALSE; -} - - GimpVectors * gimp_vectors_make_bezier (const GimpVectors *vectors) { @@ -508,6 +380,3 @@ gimp_vectors_make_bezier (const GimpVectors *vectors) return NULL; } - - - diff --git a/app/vectors/gimpvectors.h b/app/vectors/gimpvectors.h index 37291892cf..1de7952515 100644 --- a/app/vectors/gimpvectors.h +++ b/app/vectors/gimpvectors.h @@ -42,7 +42,7 @@ struct _GimpVectors gboolean visible; /* controls visibility */ gboolean locked; /* transformation locking */ - GList * strokes; /* The vectors components */ + GimpStroke * strokes; /* The first stroke */ /* Stuff missing */ }; @@ -68,20 +68,10 @@ struct _GimpVectorsClass gdouble (* stroke_get_length) (const GimpVectors *vectors, const GimpStroke *stroke); - GimpAnchor * (* anchor_get) (const GimpVectors *vectors, - const GimpCoords *coord); - - void (* anchor_move_relative) (GimpVectors *vectors, - GimpAnchor *anchor, - const GimpCoords *deltacoord, - const gint type); - - void (* anchor_move_absolute) (GimpVectors *vectors, - GimpAnchor *anchor, const GimpCoords *coord, - const gint type); + GimpStroke **ret_stroke); void (* anchor_delete) (GimpVectors *vectors, GimpAnchor *anchor); @@ -98,13 +88,6 @@ struct _GimpVectorsClass const gint max_points, GimpCoords *ret_coords); - - GimpAnchor * (* temp_anchor_get) (const GimpVectors *vectors); - - GimpAnchor * (* temp_anchor_set) (GimpVectors *vectors, - const GimpCoords *coord); - - gboolean (* temp_anchor_fix) (GimpVectors *vectors); GimpVectors * (* make_bezier) (const GimpVectors *vectors); }; @@ -121,8 +104,9 @@ GimpImage * gimp_vectors_get_image (const GimpVectors *vectors); /* accessing / modifying the anchors */ -GimpAnchor * gimp_vectors_anchor_get (const GimpVectors *vectors, - const GimpCoords *coord); +GimpAnchor * gimp_vectors_anchor_get (const GimpVectors *vectors, + const GimpCoords *coord, + GimpStroke **ret_stroke); /* prev == NULL: "first" anchor */ GimpAnchor * gimp_vectors_anchor_get_next (const GimpVectors *vectors,