mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-29 06:51:10 +00:00
gtk: Port selection drawing to new apis
Preserve color state information when drawing selections or block cursors in GtkTextView.
This commit is contained in:
parent
51768d0e16
commit
ed119ae246
@ -3867,7 +3867,7 @@ render_para (GskPangoRenderer *crenderer,
|
||||
GtkTextLineDisplay *line_display,
|
||||
int selection_start_index,
|
||||
int selection_end_index,
|
||||
const GdkRGBA *selection,
|
||||
const GdkColor *selection_color,
|
||||
gboolean draw_selection_text,
|
||||
float cursor_alpha)
|
||||
{
|
||||
@ -3921,10 +3921,10 @@ render_para (GskPangoRenderer *crenderer,
|
||||
*/
|
||||
if (selection_start_index < byte_offset &&
|
||||
selection_end_index > pango_layout_line_get_length (line) + byte_offset &&
|
||||
selection->alpha >= 1)
|
||||
gdk_color_is_opaque (selection_color))
|
||||
{
|
||||
gtk_snapshot_append_color (crenderer->snapshot,
|
||||
selection,
|
||||
gtk_snapshot_append_color2 (crenderer->snapshot,
|
||||
selection_color,
|
||||
&GRAPHENE_RECT_INIT (line_display->left_margin,
|
||||
selection_y,
|
||||
screen_width,
|
||||
@ -3990,7 +3990,7 @@ render_para (GskPangoRenderer *crenderer,
|
||||
PANGO_PIXELS (line_rect.width) -
|
||||
bounds.origin.x);
|
||||
|
||||
gtk_snapshot_append_color (crenderer->snapshot, selection, &bounds);
|
||||
gtk_snapshot_append_color2 (crenderer->snapshot, selection_color, &bounds);
|
||||
|
||||
if (draw_selection_text)
|
||||
{
|
||||
@ -4009,8 +4009,8 @@ render_para (GskPangoRenderer *crenderer,
|
||||
if (line_rect.x > line_display->left_margin * PANGO_SCALE &&
|
||||
((line_display->direction == GTK_TEXT_DIR_LTR && selection_start_index < byte_offset) ||
|
||||
(line_display->direction == GTK_TEXT_DIR_RTL && selection_end_index > byte_offset + pango_layout_line_get_length (line))))
|
||||
gtk_snapshot_append_color (crenderer->snapshot,
|
||||
selection,
|
||||
gtk_snapshot_append_color2 (crenderer->snapshot,
|
||||
selection_color,
|
||||
&GRAPHENE_RECT_INIT (line_display->left_margin,
|
||||
selection_y,
|
||||
PANGO_PIXELS (line_rect.x) - line_display->left_margin,
|
||||
@ -4025,8 +4025,8 @@ render_para (GskPangoRenderer *crenderer,
|
||||
+ screen_width
|
||||
- PANGO_PIXELS (line_rect.x)
|
||||
- PANGO_PIXELS (line_rect.width);
|
||||
gtk_snapshot_append_color (crenderer->snapshot,
|
||||
selection,
|
||||
gtk_snapshot_append_color2 (crenderer->snapshot,
|
||||
selection_color,
|
||||
&GRAPHENE_RECT_INIT (PANGO_PIXELS (line_rect.x) + PANGO_PIXELS (line_rect.width),
|
||||
selection_y,
|
||||
nonlayout_width,
|
||||
@ -4042,7 +4042,7 @@ render_para (GskPangoRenderer *crenderer,
|
||||
{
|
||||
GtkCssNode *node;
|
||||
GtkCssStyle *style;
|
||||
const GdkRGBA *cursor_color;
|
||||
GdkColor cursor_color;
|
||||
graphene_rect_t bounds = {
|
||||
.origin.x = line_display->x_offset + line_display->block_cursor.x,
|
||||
.origin.y = line_display->block_cursor.y + line_display->top_margin,
|
||||
@ -4056,10 +4056,11 @@ render_para (GskPangoRenderer *crenderer,
|
||||
node = gtk_widget_get_css_node (crenderer->widget);
|
||||
style = gtk_css_node_get_style (node);
|
||||
|
||||
cursor_color = gtk_css_color_value_get_rgba (style->used->caret_color);
|
||||
gtk_css_color_to_color (gtk_css_color_value_get_color (style->used->caret_color),
|
||||
&cursor_color);
|
||||
|
||||
gtk_snapshot_push_opacity (crenderer->snapshot, cursor_alpha);
|
||||
gtk_snapshot_append_color (crenderer->snapshot, cursor_color, &bounds);
|
||||
gtk_snapshot_append_color2 (crenderer->snapshot, &cursor_color, &bounds);
|
||||
|
||||
/* draw text under the cursor if any */
|
||||
if (!line_display->cursor_at_line_end)
|
||||
@ -4114,8 +4115,7 @@ gtk_text_layout_snapshot (GtkTextLayout *layout,
|
||||
int selection_end_line;
|
||||
gboolean have_selection;
|
||||
gboolean draw_selection_text;
|
||||
const GdkRGBA *selection;
|
||||
const GdkRGBA *color;
|
||||
GdkColor selection_color;
|
||||
GtkSnapshot *cursor_snapshot;
|
||||
GtkTextBTree *btree;
|
||||
GtkTextLine *first_line;
|
||||
@ -4146,8 +4146,6 @@ gtk_text_layout_snapshot (GtkTextLayout *layout,
|
||||
node = gtk_widget_get_css_node (widget);
|
||||
style = gtk_css_node_get_style (node);
|
||||
|
||||
color = gtk_css_color_value_get_rgba (style->used->color);
|
||||
|
||||
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (0, offset_y));
|
||||
offset_y = 0;
|
||||
|
||||
@ -4159,7 +4157,8 @@ gtk_text_layout_snapshot (GtkTextLayout *layout,
|
||||
|
||||
crenderer->widget = widget;
|
||||
crenderer->snapshot = snapshot;
|
||||
gdk_color_init_from_rgba (&crenderer->fg_color, color);
|
||||
gtk_css_color_to_color (gtk_css_color_value_get_color (style->used->color),
|
||||
&crenderer->fg_color);
|
||||
|
||||
have_selection = gtk_text_buffer_get_selection_bounds (layout->buffer,
|
||||
&selection_start,
|
||||
@ -4167,7 +4166,6 @@ gtk_text_layout_snapshot (GtkTextLayout *layout,
|
||||
if (have_selection)
|
||||
{
|
||||
GtkCssNode *selection_node;
|
||||
const GdkRGBA *text_color;
|
||||
|
||||
selection_start_line = gtk_text_iter_get_line (&selection_start);
|
||||
selection_end_line = gtk_text_iter_get_line (&selection_end);
|
||||
@ -4175,16 +4173,16 @@ gtk_text_layout_snapshot (GtkTextLayout *layout,
|
||||
selection_node = gtk_text_view_get_selection_node ((GtkTextView*)widget);
|
||||
style = gtk_css_node_get_style (selection_node);
|
||||
|
||||
selection = gtk_css_color_value_get_rgba (style->used->background_color);
|
||||
text_color = gtk_css_color_value_get_rgba (style->used->color);
|
||||
gtk_css_color_to_color (gtk_css_color_value_get_color (style->used->background_color),
|
||||
&selection_color);
|
||||
|
||||
draw_selection_text = text_color->alpha > 0;
|
||||
draw_selection_text = !gdk_color_is_clear (&crenderer->fg_color);
|
||||
}
|
||||
else
|
||||
{
|
||||
selection_start_line = -1;
|
||||
selection_end_line = -1;
|
||||
selection = NULL;
|
||||
gdk_color_init (&selection_color, GDK_COLOR_STATE_SRGB, (float[]) { 0, 0, 0, 0 });
|
||||
draw_selection_text = FALSE;
|
||||
}
|
||||
|
||||
@ -4260,7 +4258,7 @@ gtk_text_layout_snapshot (GtkTextLayout *layout,
|
||||
gtk_snapshot_push_collect (snapshot);
|
||||
render_para (crenderer, line_display,
|
||||
selection_start_index, selection_end_index,
|
||||
selection,
|
||||
&selection_color,
|
||||
draw_selection_text,
|
||||
cursor_alpha);
|
||||
line_display->node = gtk_snapshot_pop_collect (snapshot);
|
||||
|
Loading…
Reference in New Issue
Block a user