[planner: 46/61] relation-arrow: Port to cairo drawing




commit ac1d7ac5e124a9fc8071520977db85a1b4d911bf
Author: Mart Raudsepp <leio gentoo org>
Date:   Fri Jan 1 20:24:49 2021 +0200

    relation-arrow: Port to cairo drawing
    
    The actual arrow triangle drawing setup is fully rewritten to look nice
    and crisp with anti-aliased drawing from cairo.

 src/planner-relation-arrow.c | 96 +++++++++++++++-----------------------------
 1 file changed, 32 insertions(+), 64 deletions(-)
---
diff --git a/src/planner-relation-arrow.c b/src/planner-relation-arrow.c
index e19f774d..1c93ba28 100644
--- a/src/planner-relation-arrow.c
+++ b/src/planner-relation-arrow.c
@@ -658,52 +658,34 @@ relation_arrow_update (GnomeCanvasItem *item,
 
 static void
 relation_arrow_setup_arrow (PlannerArrowDir dir,
-                           GdkPoint        points[4],
-                           gdouble         cx1,
-                           gdouble         cy1,
-                           gdouble         cx2,
-                           gdouble         cy2)
+                           cairo_t        *cr,
+                           gdouble         x,
+                           gdouble         y)
 {
        switch (dir) {
        case PLANNER_ARROW_DOWN:
-               points[0].x = cx2;
-               points[0].y = cy2;
-               points[1].x = cx2 - ARROW_SIZE / 2;
-               points[1].y = cy2 - ARROW_SIZE;
-               points[2].x = cx2 + ARROW_SIZE / 2;
-               points[2].y = cy2 - (ARROW_SIZE - 1);
-               points[3].x = cx2;
-               points[3].y = cy2 + 1;
+               cairo_move_to (cr, x, y + 0.5);
+               cairo_rel_line_to (cr, - (ARROW_SIZE / 2 + 0.5), - (ARROW_SIZE + 1.0));
+               cairo_rel_line_to (cr, ARROW_SIZE + 1.0, 0.0);
+               cairo_close_path (cr);
                break;
        case PLANNER_ARROW_UP:
-               points[0].x = cx2;
-               points[0].y = cy2 + 1;
-               points[1].x = cx2 + ARROW_SIZE / 2;
-               points[1].y = cy2 + ARROW_SIZE;
-               points[2].x = cx2 - ARROW_SIZE / 2;
-               points[2].y = cy2 + ARROW_SIZE;
-               points[3].x = cx2 + 1;
-               points[3].y = cy2;
+               cairo_move_to (cr, x, y - 0.5);
+               cairo_rel_line_to (cr, - (ARROW_SIZE / 2 + 0.5), ARROW_SIZE + 1.0);
+               cairo_rel_line_to (cr, ARROW_SIZE + 1.0, 0.0);
+               cairo_close_path (cr);
                break;
        case PLANNER_ARROW_RIGHT:
-               points[0].x = cx2;
-               points[0].y = cy2;
-               points[1].x = cx2 - ARROW_SIZE;
-               points[1].y = cy2 + ARROW_SIZE / 2;
-               points[2].x = cx2 - ARROW_SIZE;
-               points[2].y = cy2 - ARROW_SIZE / 2;
-               points[3].x = cx2;
-               points[3].y = cy2;
+               cairo_move_to (cr, x + 0.5, y);
+               cairo_rel_line_to (cr, -(ARROW_SIZE + 1.0), - (ARROW_SIZE / 2 + 0.5));
+               cairo_rel_line_to (cr, 0.0, ARROW_SIZE + 1.0);
+               cairo_close_path (cr);
                break;
        case PLANNER_ARROW_LEFT:
-               points[0].x = cx2;
-               points[0].y = cy2;
-               points[1].x = cx2 + (ARROW_SIZE - 0);
-               points[1].y = cy2 + ARROW_SIZE / 2;
-               points[2].x = cx2 + (ARROW_SIZE - 0);
-               points[2].y = cy2 - ARROW_SIZE / 2;
-               points[3].x = cx2;
-               points[3].y = cy2;
+               cairo_move_to (cr, x - 0.5, y);
+               cairo_rel_line_to (cr, ARROW_SIZE + 1.0, - (ARROW_SIZE / 2 + 0.5));
+               cairo_rel_line_to (cr, 0.0, ARROW_SIZE + 1.0);
+               cairo_close_path (cr);
                break;
        default:
                g_assert_not_reached ();
@@ -725,19 +707,16 @@ relation_arrow_draw (GnomeCanvasItem *item,
        gdouble                   i2w_dy;
        gdouble                   dx1, dy1, dx2, dy2;
        gint                      cx1, cy1, cx2, cy2;
-       GdkGC                    *gc;
-       GdkPoint                  points[4];
+       cairo_t                  *cr;
        gint                      i;
 
        arrow = PLANNER_RELATION_ARROW (item);
        priv = arrow->priv;
 
-       gc = gdk_gc_new (drawable);
-       gdk_gc_set_line_attributes (gc,
-                                   1,
-                                   GDK_LINE_SOLID,
-                                   GDK_CAP_BUTT,
-                                   GDK_JOIN_MITER);
+       cr = gdk_cairo_create (drawable);
+       cairo_set_line_width (cr, 1.0);
+       cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
+       cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
 
        /* Silence warning. */
        cx1 = 0;
@@ -772,28 +751,17 @@ relation_arrow_draw (GnomeCanvasItem *item,
                cx2 -= x;
                cy2 -= y;
 
-               gdk_draw_line (drawable,
-                              gc,
-                              cx1,
-                              cy1,
-                              cx2,
-                              cy2);
+               cairo_move_to (cr, cx1 + 0.5, cy1 + 0.5);
+               cairo_line_to (cr, cx2 + 0.5, cy2 + 0.5);
+               cairo_stroke (cr);
        }
 
        relation_arrow_setup_arrow (priv->arrow_dir,
-                                       points,
-                                       cx1,
-                                       cy1,
-                                       cx2,
-                                       cy2);
-
-       gdk_draw_polygon (drawable,
-                         gc,
-                         TRUE,
-                         (GdkPoint *) &points,
-                         4);
-
-       g_object_unref (gc);
+                                   cr,
+                                   cx2 + 0.5, cy2 + 0.5);
+       cairo_fill (cr);
+
+       cairo_destroy (cr);
 }
 
 static double


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]