[gtksourceview] gtksourceview: fix miss-renderings in the grid background



commit f9bb8a243a51499e40802d7f220c30727bad8d2b
Author: Christian Hergert <christian hergert me>
Date:   Sun Apr 17 21:27:39 2016 -0700

    gtksourceview: fix miss-renderings in the grid background
    
    There were situations where we would miss a line or our positioning was
    slightly off. This caused some funky updates when the pixelcache decided
    to re-render a portion of the visible area.
    
    This uses a more formal "realign" technique that we would use to realign
    data-structures to arbitrary offsets (rather than a ^2) which cleans
    up the offset calculation a bit too.
    
    The comment was no longer relevant since we have a useful clip region
    from the cairo context provided during BELOW_TEXT, so I've removed that
    as well.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=765191

 gtksourceview/gtksourceview.c |   31 +++++++++++++++++++++----------
 1 files changed, 21 insertions(+), 10 deletions(-)
---
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index f027a2a..6b73c02 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -2868,12 +2868,27 @@ gtk_source_view_paint_right_margin (GtkSourceView *view,
        });
 }
 
+static gint
+realign (gint  offset,
+        guint align)
+{
+       if (offset > 0 && align > 0)
+       {
+               gint padding;
+
+               padding = (align - (offset % align)) % align;
+               return offset + padding;
+       }
+
+       return 0;
+}
+
 static void
 gtk_source_view_paint_background_pattern_grid (GtkSourceView *view,
                                               cairo_t       *cr)
 {
        GdkRectangle clip;
-       gdouble x, y, x2, y2;
+       gint x, y, x2, y2;
        PangoContext *context;
        PangoLayout *layout;
        gint grid_width = 16;
@@ -2896,15 +2911,11 @@ gtk_source_view_paint_background_pattern_grid (GtkSourceView *view,
        cairo_set_line_width (cr, 1.0);
        gdk_cairo_set_source_rgba (cr, &view->priv->background_pattern_color);
 
-       /*
-        * The following constants come from gtktextview.c pixel cache
-        * settings. Sadly, they are not exposed in the public API,
-        * just keep them in sync here. 64 for X, height/2 for Y.
-        */
-       x = (grid_width - (clip.x % grid_width)) - (64 / grid_width * grid_width) - grid_width + 2;
-       y = (grid_height - (clip.y % grid_height)) - (clip.height / 2 / grid_height * grid_height) - 
grid_height;
-       x2 = clip.x + clip.width;
-       y2 = clip.y + clip.height;
+       /* Align our drawing position with a multiple of the grid size. */
+       x = realign (clip.x - grid_width, grid_width);
+       y = realign (clip.y - grid_height, grid_height);
+       x2 = realign (x + clip.width + grid_width * 2, grid_width);
+       y2 = realign (y + clip.height + grid_height * 2, grid_height);
 
        for (; x <= x2; x += grid_width)
        {


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