Commit 0af45763 authored by Alexander Larsson's avatar Alexander Larsson

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
parent b0a6af37
......@@ -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);
......
......@@ -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);
}
}
......
......@@ -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
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment