[gtk+] TextView: Use saner coordinate space in draw_layer.



commit 0af457639dc5eb14a060183fbd3051870055c9ab
Author: Alexander Larsson <alexl redhat com>
Date:   Mon Nov 9 22:18:05 2015 +0100

    TextView: Use saner coordinate space in draw_layer.
    
    When I added the draw_layer vfunc it accidentally got passed a cairo_t
    that was configured with to draw in the viewport coordinate space (rather
    than the buffer coordinate space). This makes things unnecessary complex,
    because you have to convert between the two.
    
    The pixel cache is shared between the text and the layers, so there is
    no way to use draw_layer to get a stationary overlay effect. Thus it makes
    much more sense for the draw_layer vfunc to draw in the buffer space.
    
    Just changing this would break ABI for existing code, so this is fixed
    by adding new layer types and deprecating the old ones.
    
    Also, we use the new layer types to fix gtk3-widget-factory.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=757856

 demos/widget-factory/widget-factory.c |    2 +-
 gtk/gtktextview.c                     |   10 ++++++++++
 gtk/gtktextview.h                     |   15 +++++++++++----
 3 files changed, 22 insertions(+), 5 deletions(-)
---
diff --git a/demos/widget-factory/widget-factory.c b/demos/widget-factory/widget-factory.c
index 573f266..ee2ae5a 100644
--- a/demos/widget-factory/widget-factory.c
+++ b/demos/widget-factory/widget-factory.c
@@ -1034,7 +1034,7 @@ my_tv_draw_layer (GtkTextView      *widget,
 {
   MyTextView *tv = (MyTextView *)widget;
 
-  if (layer == GTK_TEXT_VIEW_LAYER_BELOW && tv->surface)
+  if (layer == GTK_TEXT_VIEW_LAYER_BELOW_TEXT && tv->surface)
     {
       cairo_save (cr);
       cairo_set_source_surface (cr, tv->surface, 0.0, 0.0);
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index 3b8f16e..773a87f 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -5813,6 +5813,11 @@ draw_text (cairo_t  *cr,
       cairo_save (cr);
       GTK_TEXT_VIEW_GET_CLASS (text_view)->draw_layer (text_view, GTK_TEXT_VIEW_LAYER_BELOW, cr);
       cairo_restore (cr);
+
+      cairo_save (cr);
+      cairo_translate (cr, -text_view->priv->xoffset, -text_view->priv->yoffset);
+      GTK_TEXT_VIEW_GET_CLASS (text_view)->draw_layer (text_view, GTK_TEXT_VIEW_LAYER_BELOW_TEXT, cr);
+      cairo_restore (cr);
     }
 
   gtk_text_view_paint (widget, cr);
@@ -5822,6 +5827,11 @@ draw_text (cairo_t  *cr,
       cairo_save (cr);
       GTK_TEXT_VIEW_GET_CLASS (text_view)->draw_layer (text_view, GTK_TEXT_VIEW_LAYER_ABOVE, cr);
       cairo_restore (cr);
+
+      cairo_save (cr);
+      cairo_translate (cr, -text_view->priv->xoffset, -text_view->priv->yoffset);
+      GTK_TEXT_VIEW_GET_CLASS (text_view)->draw_layer (text_view, GTK_TEXT_VIEW_LAYER_ABOVE_TEXT, cr);
+      cairo_restore (cr);
     }
 }
 
diff --git a/gtk/gtktextview.h b/gtk/gtktextview.h
index 41a54ba..203fcfb 100644
--- a/gtk/gtktextview.h
+++ b/gtk/gtktextview.h
@@ -69,8 +69,10 @@ typedef enum
 
 /**
  * GtkTextViewLayer:
- * @GTK_TEXT_VIEW_LAYER_BELOW: The layer rendered below the text (but above the background).
- * @GTK_TEXT_VIEW_LAYER_ABOVE: The layer rendered above the text.
+ * @GTK_TEXT_VIEW_LAYER_BELOW: Old deprecated layer, use %GTK_TEXT_VIEW_LAYER_BELOW_TEXT instead
+ * @GTK_TEXT_VIEW_LAYER_ABOVE: Old deprecated layer, use %GTK_TEXT_VIEW_LAYER_ABOVE_TEXT instead
+ * @GTK_TEXT_VIEW_LAYER_BELOW_TEXT: The layer rendered below the text (but above the background).  Since: 
3.20
+ * @GTK_TEXT_VIEW_LAYER_ABOVE_TEXT: The layer rendered above the text.  Since: 3.20
  *
  * Used to reference the layers of #GtkTextView for the purpose of customized
  * drawing with the ::draw_layer vfunc.
@@ -78,7 +80,9 @@ typedef enum
 typedef enum
 {
   GTK_TEXT_VIEW_LAYER_BELOW,
-  GTK_TEXT_VIEW_LAYER_ABOVE
+  GTK_TEXT_VIEW_LAYER_ABOVE,
+  GTK_TEXT_VIEW_LAYER_BELOW_TEXT,
+  GTK_TEXT_VIEW_LAYER_ABOVE_TEXT
 } GtkTextViewLayer;
 
 /**
@@ -149,7 +153,10 @@ struct _GtkTextView
  * @draw_layer: The draw_layer vfunc is called before and after the text
  *   view is drawing its own text. Applications can override this vfunc
  *   in a subclass to draw customized content underneath or above the
- *   text. Since: 3.14
+ *   text. In the %GTK_TEXT_VIEW_LAYER_BELOW_TEXT and %GTK_TEXT_VIEW_LAYER_ABOVE_TEXT
+ *   the drawing is done in the buffer coordinate space, but the older (deprecated)
+ *   layers %GTK_TEXT_VIEW_LAYER_BELOW and %GTK_TEXT_VIEW_LAYER_ABOVE work in viewport
+ *   coordinates, which makes them unnecessarily hard to use. Since: 3.14
  * @extend_selection: The class handler for the #GtkTextView::extend-selection
  *   signal. Since 3.16
  */


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