From 54a65fa9c34a00e52c757f46643490cbdd7256f4 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Thu, 7 Oct 2010 14:10:57 +0200 Subject: [PATCH] app: add gimp_draw_tool_add_path() and use it in the vector tool Also clean up gimp_vector_tool_draw() a bit. --- app/tools/gimpdrawtool.c | 19 +++++++++++++++++ app/tools/gimpdrawtool.h | 2 ++ app/tools/gimpvectortool.c | 42 ++++++++++++++------------------------ 3 files changed, 36 insertions(+), 27 deletions(-) diff --git a/app/tools/gimpdrawtool.c b/app/tools/gimpdrawtool.c index 9e9db004a2..433f37ca78 100644 --- a/app/tools/gimpdrawtool.c +++ b/app/tools/gimpdrawtool.c @@ -40,6 +40,7 @@ #include "display/gimpcanvasguide.h" #include "display/gimpcanvashandle.h" #include "display/gimpcanvasline.h" +#include "display/gimpcanvaspath.h" #include "display/gimpcanvaspen.h" #include "display/gimpcanvaspolygon.h" #include "display/gimpcanvasrectangle.h" @@ -706,6 +707,24 @@ gimp_draw_tool_add_strokes (GimpDrawTool *draw_tool, return item; } +GimpCanvasItem * +gimp_draw_tool_add_path (GimpDrawTool *draw_tool, + const GimpBezierDesc *desc) +{ + GimpCanvasItem *item; + + g_return_val_if_fail (GIMP_IS_DRAW_TOOL (draw_tool), NULL); + g_return_val_if_fail (desc != NULL, NULL); + + item = gimp_canvas_path_new (gimp_display_get_shell (draw_tool->display), + desc, FALSE, FALSE); + + gimp_draw_tool_add_item (draw_tool, item); + g_object_unref (item); + + return item; +} + GimpCanvasItem * gimp_draw_tool_add_pen (GimpDrawTool *draw_tool, const GimpVector2 *points, diff --git a/app/tools/gimpdrawtool.h b/app/tools/gimpdrawtool.h index 22327e446d..caf6102885 100644 --- a/app/tools/gimpdrawtool.h +++ b/app/tools/gimpdrawtool.h @@ -150,6 +150,8 @@ GimpCanvasItem * gimp_draw_tool_add_strokes (GimpDrawTool *draw_too const GimpCoords *points, gint n_points, gboolean filled); +GimpCanvasItem * gimp_draw_tool_add_path (GimpDrawTool *draw_tool, + const GimpBezierDesc *desc); GimpCanvasItem * gimp_draw_tool_add_pen (GimpDrawTool *draw_tool, const GimpVector2 *points, diff --git a/app/tools/gimpvectortool.c b/app/tools/gimpvectortool.c index e372b71606..e8e2640959 100644 --- a/app/tools/gimpvectortool.c +++ b/app/tools/gimpvectortool.c @@ -1400,45 +1400,33 @@ gimp_vector_tool_cursor_update (GimpTool *tool, static void gimp_vector_tool_draw (GimpDrawTool *draw_tool) { - GimpVectorTool *vector_tool = GIMP_VECTOR_TOOL (draw_tool); - GimpAnchor *cur_anchor = NULL; - GimpStroke *cur_stroke = NULL; - GimpVectors *vectors; - GArray *coords; - gboolean closed; - GList *draw_anchors; - GList *list; + GimpVectorTool *vector_tool = GIMP_VECTOR_TOOL (draw_tool); + GimpStroke *cur_stroke; + GimpVectors *vectors; vectors = vector_tool->vectors; if (!vectors) return; - while ((cur_stroke = gimp_vectors_stroke_get_next (vectors, cur_stroke))) + /* the stroke itself */ + if (! gimp_item_get_visible (GIMP_ITEM (vectors))) + gimp_draw_tool_add_path (draw_tool, gimp_vectors_get_bezier (vectors)); + + for (cur_stroke = gimp_vectors_stroke_get_next (vectors, NULL); + cur_stroke; + cur_stroke = gimp_vectors_stroke_get_next (vectors, cur_stroke)) { - /* the stroke itself */ - if (! gimp_item_get_visible (GIMP_ITEM (vectors))) - { - coords = gimp_stroke_interpolate (cur_stroke, 1.0, &closed); - - if (coords) - { - if (coords->len) - gimp_draw_tool_add_strokes (draw_tool, - &g_array_index (coords, - GimpCoords, 0), - coords->len, FALSE); - - g_array_free (coords, TRUE); - } - } + GArray *coords; + GList *draw_anchors; + GList *list; /* anchor handles */ draw_anchors = gimp_stroke_get_draw_anchors (cur_stroke); for (list = draw_anchors; list; list = g_list_next (list)) { - cur_anchor = GIMP_ANCHOR (list->data); + GimpAnchor *cur_anchor = GIMP_ANCHOR (list->data); if (cur_anchor->type == GIMP_ANCHOR_ANCHOR) { @@ -1490,7 +1478,7 @@ gimp_vector_tool_draw (GimpDrawTool *draw_tool) for (list = draw_anchors; list; list = g_list_next (list)) { - cur_anchor = GIMP_ANCHOR (list->data); + GimpAnchor *cur_anchor = GIMP_ANCHOR (list->data); gimp_draw_tool_add_handle (draw_tool, GIMP_HANDLE_SQUARE,