[gtk/wip/exalm/textview-selection: 4/4] textlayout: Support fully transparent selection text
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/exalm/textview-selection: 4/4] textlayout: Support fully transparent selection text
- Date: Mon, 3 May 2021 17:08:36 +0000 (UTC)
commit 375455a189b62cfac19fafb385e263981b9735d6
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Mon May 3 22:05:44 2021 +0500
textlayout: Support fully transparent selection text
Pang treats 0 alpha value as a unset alpha, so we have to special case it.
gtk/gtktextlayout.c | 38 +++++++++++++++++++++++++++-----------
1 file changed, 27 insertions(+), 11 deletions(-)
---
diff --git a/gtk/gtktextlayout.c b/gtk/gtktextlayout.c
index aad63f6333..8b4a52b013 100644
--- a/gtk/gtktextlayout.c
+++ b/gtk/gtktextlayout.c
@@ -3840,6 +3840,7 @@ render_para (GskPangoRenderer *crenderer,
int selection_start_index,
int selection_end_index,
const GdkRGBA *selection,
+ gboolean draw_selection_text,
float cursor_alpha)
{
PangoLayout *layout = line_display->layout;
@@ -3899,11 +3900,15 @@ render_para (GskPangoRenderer *crenderer,
selection_y,
screen_width,
selection_height));
- gsk_pango_renderer_set_state (crenderer, GSK_PANGO_RENDERER_SELECTED);
- pango_renderer_draw_layout_line (PANGO_RENDERER (crenderer),
- line,
- line_rect.x,
- baseline);
+
+ if (draw_selection_text)
+ {
+ gsk_pango_renderer_set_state (crenderer, GSK_PANGO_RENDERER_SELECTED);
+ pango_renderer_draw_layout_line (PANGO_RENDERER (crenderer),
+ line,
+ line_rect.x,
+ baseline);
+ }
}
else
{
@@ -3946,12 +3951,16 @@ render_para (GskPangoRenderer *crenderer,
bounds.size.height = selection_height;
gtk_snapshot_append_color (crenderer->snapshot, selection, &bounds);
- gtk_snapshot_push_clip (crenderer->snapshot, &bounds);
- pango_renderer_draw_layout_line (PANGO_RENDERER (crenderer),
- line,
- line_rect.x,
- baseline);
- gtk_snapshot_pop (crenderer->snapshot);
+
+ if (draw_selection_text)
+ {
+ gtk_snapshot_push_clip (crenderer->snapshot, &bounds);
+ pango_renderer_draw_layout_line (PANGO_RENDERER (crenderer),
+ line,
+ line_rect.x,
+ baseline);
+ gtk_snapshot_pop (crenderer->snapshot);
+ }
}
g_free (ranges);
@@ -4033,6 +4042,7 @@ gtk_text_layout_snapshot (GtkTextLayout *layout,
int selection_start_line;
int selection_end_line;
gboolean have_selection;
+ gboolean draw_selection_text;
const GdkRGBA *selection;
GdkRGBA color;
GtkSnapshot *cursor_snapshot;
@@ -4082,6 +4092,7 @@ gtk_text_layout_snapshot (GtkTextLayout *layout,
if (have_selection)
{
GtkCssNode *selection_node;
+ GdkRGBA text_color;
selection_start_line = gtk_text_iter_get_line (&selection_start);
selection_end_line = gtk_text_iter_get_line (&selection_end);
@@ -4091,6 +4102,9 @@ gtk_text_layout_snapshot (GtkTextLayout *layout,
selection = gtk_css_color_value_get_rgba (_gtk_style_context_peek_property (context,
GTK_CSS_PROPERTY_BACKGROUND_COLOR));
+ gtk_style_context_get_color (context, &text_color);
+ draw_selection_text = text_color.alpha > 0;
+
gtk_style_context_restore (context);
}
else
@@ -4098,6 +4112,7 @@ gtk_text_layout_snapshot (GtkTextLayout *layout,
selection_start_line = -1;
selection_end_line = -1;
selection = NULL;
+ draw_selection_text = FALSE;
}
gtk_text_layout_wrap_loop_start (layout);
@@ -4166,6 +4181,7 @@ gtk_text_layout_snapshot (GtkTextLayout *layout,
render_para (crenderer, line_display,
selection_start_index, selection_end_index,
selection,
+ draw_selection_text,
cursor_alpha);
line_display->node = gtk_snapshot_pop_collect (snapshot);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]