From 5ab83e72ac2e4e0be5ef8b98edf870e60419ff67 Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Sun, 12 Sep 2010 00:08:17 +0200 Subject: [PATCH] app: don't let the vectors tool draw the active vectors Let the display shell deal with drawing the vectors. The vectors tool only draws the handles on the active vectors object. --- app/display/gimpdisplayshell-draw.c | 54 ++++++++++++++++-- app/display/gimpdisplayshell-handlers.c | 18 ++++++ app/tools/gimpdrawtool.h | 2 - app/tools/gimpvectortool.c | 75 +++---------------------- 4 files changed, 74 insertions(+), 75 deletions(-) diff --git a/app/display/gimpdisplayshell-draw.c b/app/display/gimpdisplayshell-draw.c index 65daa94883..b93607bd0d 100644 --- a/app/display/gimpdisplayshell-draw.c +++ b/app/display/gimpdisplayshell-draw.c @@ -584,10 +584,40 @@ gimp_display_shell_draw_selection_in (GimpDisplayShell *shell, } static void -gimp_display_shell_draw_one_vectors (GimpDisplayShell *shell, - cairo_t *cr, - GimpVectors *vectors, - gdouble width) +gimp_display_shell_draw_active_vectors (GimpDisplayShell *shell, + cairo_t *cr, + GimpVectors *vectors, + gdouble width) +{ + GimpStroke *stroke = NULL; + + while ((stroke = gimp_vectors_stroke_get_next (vectors, stroke))) + { + GimpBezierDesc *desc = gimp_vectors_make_bezier (vectors); + + if (desc) + { + cairo_append_path (cr, (cairo_path_t *) desc); + + cairo_set_line_width (cr, 1.6 * width); + cairo_set_source_rgb (cr, 0.0, 0.7, 1.0); + cairo_stroke_preserve (cr); + + cairo_set_line_width (cr, width); + cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); + cairo_stroke (cr); + + g_free (desc->data); + g_free (desc); + } + } +} + +static void +gimp_display_shell_draw_inactive_vectors (GimpDisplayShell *shell, + cairo_t *cr, + GimpVectors *vectors, + gdouble width) { GimpStroke *stroke = NULL; @@ -612,6 +642,7 @@ gimp_display_shell_draw_one_vectors (GimpDisplayShell *shell, } } } + void gimp_display_shell_draw_vectors (GimpDisplayShell *shell, cairo_t *cr) @@ -625,6 +656,7 @@ gimp_display_shell_draw_vectors (GimpDisplayShell *shell, if (image && TRUE /* gimp_display_shell_get_show_vectors (shell) */) { GList *all_vectors = gimp_image_get_vectors_list (image); + GimpVectors *active = gimp_image_get_active_vectors (image); const GList *list; gdouble xscale; gdouble yscale; @@ -646,8 +678,18 @@ gimp_display_shell_draw_vectors (GimpDisplayShell *shell, { GimpVectors *vectors = list->data; - if (gimp_item_get_visible (GIMP_ITEM (vectors))) - gimp_display_shell_draw_one_vectors (shell, cr, vectors, width); + if (vectors != active && + gimp_item_get_visible (GIMP_ITEM (vectors))) + { + gimp_display_shell_draw_inactive_vectors (shell, cr, + vectors, width); + } + } + + /* the active vector is always rendered on top */ + if (active) + { + gimp_display_shell_draw_active_vectors (shell, cr, active, width); } g_list_free (all_vectors); diff --git a/app/display/gimpdisplayshell-handlers.c b/app/display/gimpdisplayshell-handlers.c index 9e03122c4d..cf80fa3134 100644 --- a/app/display/gimpdisplayshell-handlers.c +++ b/app/display/gimpdisplayshell-handlers.c @@ -104,6 +104,9 @@ static void gimp_display_shell_exported_handler (GimpImage *i const gchar *uri, GimpDisplayShell *shell); +static void gimp_display_shell_active_vectors_handler (GimpImage *image, + GimpDisplayShell *shell); + static void gimp_display_shell_vectors_freeze_handler (GimpVectors *vectors, GimpDisplayShell *shell); static void gimp_display_shell_vectors_thaw_handler (GimpVectors *vectors, @@ -202,6 +205,10 @@ gimp_display_shell_connect (GimpDisplayShell *shell) G_CALLBACK (gimp_display_shell_exported_handler), shell); + g_signal_connect (image, "active-vectors-changed", + G_CALLBACK (gimp_display_shell_active_vectors_handler), + shell); + shell->vectors_freeze_handler = gimp_tree_handler_connect (vectors, "freeze", G_CALLBACK (gimp_display_shell_vectors_freeze_handler), @@ -345,6 +352,10 @@ gimp_display_shell_disconnect (GimpDisplayShell *shell) gimp_tree_handler_disconnect (shell->vectors_freeze_handler); shell->vectors_freeze_handler = NULL; + g_signal_handlers_disconnect_by_func (image, + gimp_display_shell_active_vectors_handler, + shell); + g_signal_handlers_disconnect_by_func (image, gimp_display_shell_exported_handler, shell); @@ -603,6 +614,13 @@ gimp_display_shell_exported_handler (GimpImage *image, g_free (filename); } +static void +gimp_display_shell_active_vectors_handler (GimpImage *image, + GimpDisplayShell *shell) +{ + gimp_display_shell_expose_full (shell); +} + static void gimp_display_shell_vectors_freeze_handler (GimpVectors *vectors, GimpDisplayShell *shell) diff --git a/app/tools/gimpdrawtool.h b/app/tools/gimpdrawtool.h index 0b7894b256..f4616e68f2 100644 --- a/app/tools/gimpdrawtool.h +++ b/app/tools/gimpdrawtool.h @@ -78,8 +78,6 @@ void gimp_draw_tool_resume (GimpDrawTool *draw_tool) gboolean gimp_draw_tool_is_drawn (GimpDrawTool *draw_tool); -void gimp_draw_tool_set_vectors (GimpDrawTool *draw_tool, - GList *vectors); void gimp_draw_tool_set_transform (GimpDrawTool *draw_tool, GimpMatrix3 *transform); diff --git a/app/tools/gimpvectortool.c b/app/tools/gimpvectortool.c index 5a57a68186..5b870db4c1 100644 --- a/app/tools/gimpvectortool.c +++ b/app/tools/gimpvectortool.c @@ -118,8 +118,6 @@ static void gimp_vector_tool_vectors_changed (GimpImage *image, GimpVectorTool *vector_tool); static void gimp_vector_tool_vectors_removed (GimpVectors *vectors, GimpVectorTool *vector_tool); -static void gimp_vector_tool_vectors_visible (GimpVectors *vectors, - GimpVectorTool *vector_tool); static void gimp_vector_tool_vectors_freeze (GimpVectors *vectors, GimpVectorTool *vector_tool); static void gimp_vector_tool_vectors_thaw (GimpVectors *vectors, @@ -1399,18 +1397,15 @@ 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); + GimpVectors *vectors = vector_tool->vectors; + GimpAnchor *cur_anchor = NULL; + GimpStroke *cur_stroke = NULL; + GArray *coords; + GList *draw_anchors; + GList *list; - vectors = vector_tool->vectors; - - if (!vectors) + if (! vectors) return; while ((cur_stroke = gimp_vectors_stroke_get_next (vectors, cur_stroke))) @@ -1483,23 +1478,6 @@ gimp_vector_tool_draw (GimpDrawTool *draw_tool) g_array_free (coords, TRUE); } } - - /* 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_draw_strokes (draw_tool, - &g_array_index (coords, - GimpCoords, 0), - coords->len, FALSE, FALSE); - - g_array_free (coords, TRUE); - } - } } } @@ -1518,37 +1496,6 @@ gimp_vector_tool_vectors_removed (GimpVectors *vectors, gimp_vector_tool_set_vectors (vector_tool, NULL); } -static void -gimp_vector_tool_vectors_visible (GimpVectors *vectors, - GimpVectorTool *vector_tool) -{ - GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (vector_tool); - - if (gimp_draw_tool_is_active (draw_tool) && draw_tool->paused_count == 0) - { - GimpStroke *stroke = NULL; - - while ((stroke = gimp_vectors_stroke_get_next (vectors, stroke))) - { - GArray *coords; - gboolean closed; - - coords = gimp_stroke_interpolate (stroke, 1.0, &closed); - - if (coords) - { - if (coords->len) - gimp_draw_tool_draw_strokes (draw_tool, - &g_array_index (coords, - GimpCoords, 0), - coords->len, FALSE, FALSE); - - g_array_free (coords, TRUE); - } - } - } -} - static void gimp_vector_tool_vectors_freeze (GimpVectors *vectors, GimpVectorTool *vector_tool) @@ -1610,9 +1557,6 @@ gimp_vector_tool_set_vectors (GimpVectorTool *vector_tool, g_signal_handlers_disconnect_by_func (vector_tool->vectors, gimp_vector_tool_vectors_removed, vector_tool); - g_signal_handlers_disconnect_by_func (vector_tool->vectors, - gimp_vector_tool_vectors_visible, - vector_tool); g_signal_handlers_disconnect_by_func (vector_tool->vectors, gimp_vector_tool_vectors_freeze, vector_tool); @@ -1665,9 +1609,6 @@ gimp_vector_tool_set_vectors (GimpVectorTool *vector_tool, g_signal_connect_object (vectors, "removed", G_CALLBACK (gimp_vector_tool_vectors_removed), vector_tool, 0); - g_signal_connect_object (vectors, "visibility-changed", - G_CALLBACK (gimp_vector_tool_vectors_visible), - vector_tool, 0); g_signal_connect_object (vectors, "freeze", G_CALLBACK (gimp_vector_tool_vectors_freeze), vector_tool, 0);