[planner: 31/32] libgnomecanvas: Fix cairo port of GnomeCanvasLine




commit 653e3286b88a2eb9ce07739b6443c26e31436ac7
Author: Mart Raudsepp <leio gentoo org>
Date:   Sun Jun 20 12:22:36 2021 +0300

    libgnomecanvas: Fix cairo port of GnomeCanvasLine
    
    The cairo port of GnomeCanvasLine done in evolution history had
    a bug where it ended up always drawing a line from 0x0 to 0x0,
    instead of the correct thing due to some variable confusion in
    porting. This is understandable, as it probably was never tested,
    as evolution didn't use GnomeCanvasLine, so it got deleted there
    very soon after the initial port, and we are fortunate that the
    inbetween state was available in their history as a great starting
    point.
    Fix it to be the same in the math as before the cairo port in this
    aspect.
    
    As the code was deleted before gtk3 adaptations were done, it still
    had an extra cairo_translate for adjusting to the drawing point,
    which moved to the GnomeCanvasItem core instead with the changes
    from `expose_event` vfunc to `draw` vfunc. Delete this to avoid
    double coordinate translation, which now leads to blinking when
    dragging mouse and shifted drawing when canvas is scrolled down.

 src/libgnomecanvas/gnome-canvas-line.c | 47 ++++++++++++++++------------------
 1 file changed, 22 insertions(+), 25 deletions(-)
---
diff --git a/src/libgnomecanvas/gnome-canvas-line.c b/src/libgnomecanvas/gnome-canvas-line.c
index 562368d6..640ba605 100644
--- a/src/libgnomecanvas/gnome-canvas-line.c
+++ b/src/libgnomecanvas/gnome-canvas-line.c
@@ -793,29 +793,27 @@ gnome_canvas_line_update (GnomeCanvasItem *item, const cairo_matrix_t *i2c, gint
 }
 
 static void
-item_to_canvas (GnomeCanvas *canvas, gdouble *item_coords, GdkPoint *canvas_coords, gint num_points,
-               gint *num_drawn_points, const cairo_matrix_t *matrix)
+item_to_canvas (GnomeCanvas          *canvas,
+                gdouble              *item_coords,
+                GdkPoint             *canvas_coords,
+                gint                  num_points,
+                gint                 *num_drawn_points,
+                const cairo_matrix_t *matrix,
+                gint                  x,
+                gint                  y)
 {
        gint i;
        gint old_cx, old_cy;
        gint cx, cy;
-       double x, y;
-
-#ifdef VERBOSE
-       {
-               gchar str[128];
-               art_affine_to_string (str, i2c);
-               g_print ("line item_to_canvas %s\n", str);
-       }
-#endif
+       double px, py;
 
        /* the first point is always drawn */
 
-       x = item_coords[0];
-       y = item_coords[1];
-       cairo_matrix_transform_point (matrix, &x, &y);
-       cx = floor (x + 0.5);
-       cy = floor (y + 0.5);
+       px = item_coords[0];
+       py = item_coords[1];
+       cairo_matrix_transform_point (matrix, &px, &py);
+       cx = floor (px + 0.5);
+       cy = floor (py + 0.5);
        canvas_coords->x = cx - x;
        canvas_coords->y = cy - y;
        canvas_coords++;
@@ -824,11 +822,11 @@ item_to_canvas (GnomeCanvas *canvas, gdouble *item_coords, GdkPoint *canvas_coor
        *num_drawn_points = 1;
 
        for (i = 1; i < num_points; i++) {
-               x = item_coords[i * 2];
-               y = item_coords[i * 2 + 1];
-               cairo_matrix_transform_point (matrix, &x, &y);
-               cx = floor (x + 0.5);
-               cy = floor (y + 0.5);
+               px = item_coords[i * 2];
+               py = item_coords[i * 2 + 1];
+               cairo_matrix_transform_point (matrix, &px, &py);
+               cx = floor (px + 0.5);
+               cy = floor (py + 0.5);
                if (old_cx != cx || old_cy != cy) {
                        canvas_coords->x = cx - x;
                        canvas_coords->y = cy - y;
@@ -857,7 +855,6 @@ gnome_canvas_line_draw (GnomeCanvasItem *item, cairo_t *cr,
                return;
 
         cairo_save (cr);
-        cairo_translate (cr, -x, -y);
 
         /* points are always centered */
         cairo_translate (cr, 0.5, 0.5);
@@ -886,7 +883,7 @@ gnome_canvas_line_draw (GnomeCanvasItem *item, cairo_t *cr,
                points = g_new (GdkPoint, line->num_points);
 
        item_to_canvas (item->canvas, line->coords, points, line->num_points,
-                       &actual_num_points_drawn, &matrix);
+                       &actual_num_points_drawn, &matrix, x, y);
 
         cairo_move_to (cr, points[0].x, points[0].y);
         for (i = 1; i < actual_num_points_drawn; i++)
@@ -902,7 +899,7 @@ gnome_canvas_line_draw (GnomeCanvasItem *item, cairo_t *cr,
 
        if (line->first_arrow) {
                item_to_canvas (item->canvas, line->first_coords, points, NUM_ARROW_POINTS,
-                               &actual_num_points_drawn, &matrix);
+                               &actual_num_points_drawn, &matrix, x, y);
                 cairo_move_to (cr, points[0].x, points[0].y);
                 for (i = 1; i < actual_num_points_drawn; i++)
                         cairo_line_to (cr, points[i].x, points[i].y);
@@ -911,7 +908,7 @@ gnome_canvas_line_draw (GnomeCanvasItem *item, cairo_t *cr,
 
        if (line->last_arrow) {
                item_to_canvas (item->canvas, line->last_coords, points, NUM_ARROW_POINTS,
-                               &actual_num_points_drawn, &matrix);
+                               &actual_num_points_drawn, &matrix, x, y);
                 cairo_move_to (cr, points[0].x, points[0].y);
                 for (i = 1; i < actual_num_points_drawn; i++)
                         cairo_line_to (cr, points[i].x, points[i].y);


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