From 99b449b7e39f0a74b04f37c4abd74f20d05d87b2 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 22 Feb 2015 00:39:53 +0000 Subject: Improve appearance of graphs with circle nodes. git-svn-id: http://svn.drobilla.net/lad/trunk/ganv@5596 a436a847-0d15-0410-975c-d299462d15a1 --- NEWS | 3 ++- src/circle.c | 15 ++++++++++----- src/edge.c | 32 ++++++++++++++++++++------------ 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/NEWS b/NEWS index b20cc3a..bbd0472 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,7 @@ ganv (1.5.2) unstable; * Distinguish edge color from port color slighly. * Add support for PDF and PS export. * Improve text rendering at high zoom. + * Improve appearance of graphs with circle nodes. * Improve update performance. * Add API to specify module port order. * Fix various minor visual alignment/sizing issues. @@ -14,7 +15,7 @@ ganv (1.5.2) unstable; * Fix compilation with --no-fdgl (patch from Vlad Glagolev). * Fix crash when destroying canvas. - -- David Robillard Sat, 21 Feb 2015 17:21:25 -0500 + -- David Robillard Sat, 21 Feb 2015 19:39:35 -0500 ganv (1.4.2) stable; diff --git a/src/circle.c b/src/circle.c index fe2a54b..2863e7d 100644 --- a/src/circle.c +++ b/src/circle.c @@ -189,12 +189,13 @@ ganv_circle_vector(const GanvNode* self, const double other_x = GANV_ITEM(other)->impl->x; const double other_y = GANV_ITEM(other)->impl->y; + const double border = circle->node.impl->border_width; const double xdist = other_x - cx; const double ydist = other_y - cy; const double h = sqrt((xdist * xdist) + (ydist * ydist)); const double theta = asin(xdist / (h + DBL_EPSILON)); const double y_mod = (cy < other_y) ? 1 : -1; - const double ret_h = h - circle->impl->coords.radius; + const double ret_h = h - circle->impl->coords.radius - border / 2.0; const double ret_x = other_x - sin(theta) * ret_h; const double ret_y = other_y - cos(theta) * ret_h * y_mod; @@ -296,19 +297,23 @@ ganv_circle_draw(GanvItem* item, ganv_node_get_draw_properties( &circle->node, &dash_length, &border_color, &fill_color); + // Fill cairo_new_path(cr); cairo_arc(cr, x, y, - impl->coords.radius, + impl->coords.radius + (impl->coords.width / 2.0), 0, 2 * G_PI); - - // Fill color_to_rgba(fill_color, &r, &g, &b, &a); cairo_set_source_rgba(cr, r, g, b, a); - cairo_fill_preserve(cr); + cairo_fill(cr); // Border + cairo_arc(cr, + x, + y, + impl->coords.radius, + 0, 2 * G_PI); color_to_rgba(border_color, &r, &g, &b, &a); cairo_set_source_rgba(cr, r, g, b, a); cairo_set_line_width(cr, impl->coords.width); diff --git a/src/edge.c b/src/edge.c index d2833e4..6b91d97 100644 --- a/src/edge.c +++ b/src/edge.c @@ -375,12 +375,6 @@ ganv_edge_draw(GanvItem* item, cairo_curve_to(cr, src_x1, src_y1, src_x2, src_y2, join_x, join_y); cairo_curve_to(cr, dst_x2, dst_y2, dst_x1, dst_y1, dst_x, dst_y); - if (impl->coords.arrowhead) { - cairo_line_to(cr, dst_x - 12, dst_y - 4); - cairo_move_to(cr, dst_x, dst_y); - cairo_line_to(cr, dst_x - 12, dst_y + 4); - } - #ifdef GANV_DEBUG_CURVES cairo_stroke(cr); cairo_save(cr); @@ -413,28 +407,42 @@ ganv_edge_draw(GanvItem* item, cairo_restore(cr); #endif + cairo_stroke(cr); + if (impl->coords.arrowhead) { + cairo_move_to(cr, dst_x - 12, dst_y - 4); + cairo_line_to(cr, dst_x, dst_y); + cairo_line_to(cr, dst_x - 12, dst_y + 4); + cairo_close_path(cr); + cairo_stroke_preserve(cr); + cairo_fill(cr); + } + } else { // Straight line from (x1, y1) to (x2, y2) cairo_move_to(cr, src_x, src_y); cairo_line_to(cr, dst_x, dst_y); + cairo_stroke(cr); if (impl->coords.arrowhead) { const double ah = sqrt(dx * dx + dy * dy); - const double adx = dx / ah * 10.0; - const double ady = dy / ah * 10.0; + const double adx = dx / ah * 8.0; + const double ady = dy / ah * 8.0; - cairo_line_to(cr, + cairo_move_to(cr, dst_x + adx - ady/1.5, dst_y + ady + adx/1.5); - cairo_move_to(cr, dst_x, dst_y); + cairo_set_line_join(cr, CAIRO_LINE_JOIN_BEVEL); + cairo_line_to(cr, dst_x, dst_y); + cairo_set_line_join(cr, CAIRO_LINE_JOIN_MITER); cairo_line_to(cr, dst_x + adx + ady/1.5, dst_y + ady - adx/1.5); + cairo_close_path(cr); + cairo_stroke_preserve(cr); + cairo_fill(cr); } } - cairo_stroke(cr); - if (impl->coords.handle_radius > 0.0) { cairo_move_to(cr, join_x, join_y); cairo_arc(cr, join_x, join_y, impl->coords.handle_radius, 0, 2 * G_PI); -- cgit v1.2.1