Added internal GdkRGBA support for GtkTextTag::paragraph-background-rgba
Added the remaining implementation bits for rendering paragraph backgrounds with rgba values and updated the test case.
This commit is contained in:
parent
2b2d7aa305
commit
cefb950110
@ -279,11 +279,19 @@ _gtk_text_attributes_fill_from_tags (GtkTextAttributes *dest,
|
|||||||
{
|
{
|
||||||
gdk_rgba_free (dest->pg_bg_rgba);
|
gdk_rgba_free (dest->pg_bg_rgba);
|
||||||
dest->pg_bg_rgba = NULL;
|
dest->pg_bg_rgba = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dest->pg_bg_color)
|
||||||
|
{
|
||||||
|
gdk_color_free (dest->pg_bg_color);
|
||||||
|
dest->pg_bg_color = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vals->pg_bg_rgba)
|
if (vals->pg_bg_rgba)
|
||||||
dest->pg_bg_rgba = gdk_rgba_copy (vals->pg_bg_rgba);
|
dest->pg_bg_rgba = gdk_rgba_copy (vals->pg_bg_rgba);
|
||||||
|
|
||||||
|
if (vals->pg_bg_color)
|
||||||
|
dest->pg_bg_color = gdk_color_copy (vals->pg_bg_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vals->font)
|
if (vals->font)
|
||||||
|
@ -649,13 +649,13 @@ render_para (GtkTextRenderer *text_renderer,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (line_display->pg_bg_color)
|
if (line_display->pg_bg_rgba)
|
||||||
{
|
{
|
||||||
cairo_t *cr = text_renderer->cr;
|
cairo_t *cr = text_renderer->cr;
|
||||||
|
|
||||||
cairo_save (cr);
|
cairo_save (cr);
|
||||||
|
|
||||||
gdk_cairo_set_source_color (cr, line_display->pg_bg_color);
|
gdk_cairo_set_source_rgba (text_renderer->cr, line_display->pg_bg_rgba);
|
||||||
cairo_rectangle (cr,
|
cairo_rectangle (cr,
|
||||||
line_display->left_margin, selection_y,
|
line_display->left_margin, selection_y,
|
||||||
screen_width, selection_height);
|
screen_width, selection_height);
|
||||||
|
@ -1408,7 +1408,12 @@ set_para_values (GtkTextLayout *layout,
|
|||||||
if (style->pg_bg_color)
|
if (style->pg_bg_color)
|
||||||
display->pg_bg_color = gdk_color_copy (style->pg_bg_color);
|
display->pg_bg_color = gdk_color_copy (style->pg_bg_color);
|
||||||
else
|
else
|
||||||
display->pg_bg_color = NULL;
|
display->pg_bg_color = NULL;
|
||||||
|
|
||||||
|
if (style->pg_bg_rgba)
|
||||||
|
display->pg_bg_rgba = gdk_rgba_copy (style->pg_bg_rgba);
|
||||||
|
else
|
||||||
|
display->pg_bg_rgba = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PangoAttribute *
|
static PangoAttribute *
|
||||||
@ -2533,6 +2538,9 @@ gtk_text_layout_free_line_display (GtkTextLayout *layout,
|
|||||||
if (display->pg_bg_color)
|
if (display->pg_bg_color)
|
||||||
gdk_color_free (display->pg_bg_color);
|
gdk_color_free (display->pg_bg_color);
|
||||||
|
|
||||||
|
if (display->pg_bg_rgba)
|
||||||
|
gdk_rgba_free (display->pg_bg_rgba);
|
||||||
|
|
||||||
g_free (display);
|
g_free (display);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -264,7 +264,7 @@ struct _GtkTextLineDisplay
|
|||||||
guint cursor_at_line_end : 1;
|
guint cursor_at_line_end : 1;
|
||||||
guint size_only : 1;
|
guint size_only : 1;
|
||||||
|
|
||||||
gpointer padding1;
|
GdkRGBA *pg_bg_rgba;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef GTK_COMPILATION
|
#ifdef GTK_COMPILATION
|
||||||
|
@ -23,6 +23,9 @@ create_tags (GtkTextBuffer *buffer)
|
|||||||
gtk_text_buffer_create_tag (buffer, "semi_red_background",
|
gtk_text_buffer_create_tag (buffer, "semi_red_background",
|
||||||
"background", "rgba(255,0,0,0.5)", NULL);
|
"background", "rgba(255,0,0,0.5)", NULL);
|
||||||
|
|
||||||
|
gtk_text_buffer_create_tag (buffer, "semi_orange_paragraph_background",
|
||||||
|
"paragraph-background", "rgba(255,165,0,0.5)", NULL);
|
||||||
|
|
||||||
gtk_text_buffer_create_tag (buffer, "word_wrap",
|
gtk_text_buffer_create_tag (buffer, "word_wrap",
|
||||||
"wrap_mode", GTK_WRAP_WORD, NULL);
|
"wrap_mode", GTK_WRAP_WORD, NULL);
|
||||||
}
|
}
|
||||||
@ -31,8 +34,9 @@ create_tags (GtkTextBuffer *buffer)
|
|||||||
static void
|
static void
|
||||||
insert_text (GtkTextBuffer *buffer)
|
insert_text (GtkTextBuffer *buffer)
|
||||||
{
|
{
|
||||||
GtkTextIter iter;
|
GtkTextIter iter;
|
||||||
GtkTextIter start, end;
|
GtkTextIter start, end;
|
||||||
|
GtkTextMark *para_start;
|
||||||
|
|
||||||
/* get start of buffer; each insertion will revalidate the
|
/* get start of buffer; each insertion will revalidate the
|
||||||
* iterator to point to just after the inserted text.
|
* iterator to point to just after the inserted text.
|
||||||
@ -59,35 +63,44 @@ insert_text (GtkTextBuffer *buffer)
|
|||||||
"semi_red_background",
|
"semi_red_background",
|
||||||
"x-large",
|
"x-large",
|
||||||
NULL);
|
NULL);
|
||||||
gtk_text_buffer_insert (buffer, &iter, ".", -1);
|
gtk_text_buffer_insert (buffer, &iter, ".\n\n", -1);
|
||||||
|
|
||||||
|
/* Store the beginning of the other paragraph */
|
||||||
|
para_start = gtk_text_buffer_create_mark (buffer, "para_start", &iter, TRUE);
|
||||||
|
|
||||||
|
gtk_text_buffer_insert (buffer, &iter,
|
||||||
|
"Paragraph background colors can also be set with rgba color values .\n", -1);
|
||||||
|
|
||||||
|
gtk_text_buffer_insert (buffer, &iter, "For instance, you can have ", -1);
|
||||||
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
|
||||||
|
"bold translucent blue text", -1,
|
||||||
|
"bold",
|
||||||
|
"semi_blue_foreground",
|
||||||
|
"x-large",
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
gtk_text_buffer_insert (buffer, &iter, ", or ", -1);
|
||||||
|
|
||||||
|
gtk_text_buffer_insert (buffer, &iter, ", ", -1);
|
||||||
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
|
||||||
|
"italic text with translucent red background", -1,
|
||||||
|
"italic",
|
||||||
|
"semi_red_background",
|
||||||
|
"x-large",
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
gtk_text_buffer_insert (buffer, &iter, " all rendered onto a translucent orange paragraph background.\n", -1);
|
||||||
|
|
||||||
|
gtk_text_buffer_get_bounds (buffer, &start, &end);
|
||||||
|
|
||||||
|
gtk_text_buffer_get_iter_at_mark (buffer, &iter, para_start);
|
||||||
|
gtk_text_buffer_apply_tag_by_name (buffer, "semi_orange_paragraph_background", &iter, &end);
|
||||||
|
|
||||||
/* Apply word_wrap tag to whole buffer */
|
/* Apply word_wrap tag to whole buffer */
|
||||||
gtk_text_buffer_get_bounds (buffer, &start, &end);
|
gtk_text_buffer_get_bounds (buffer, &start, &end);
|
||||||
gtk_text_buffer_apply_tag_by_name (buffer, "word_wrap", &start, &end);
|
gtk_text_buffer_apply_tag_by_name (buffer, "word_wrap", &start, &end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static cairo_pattern_t *
|
|
||||||
get_pattern (void)
|
|
||||||
{
|
|
||||||
static cairo_pattern_t *static_pattern = NULL;
|
|
||||||
|
|
||||||
if (!static_pattern)
|
|
||||||
{
|
|
||||||
cairo_surface_t *surface =
|
|
||||||
cairo_image_surface_create_from_png ("gradient1.png");
|
|
||||||
|
|
||||||
if (surface)
|
|
||||||
{
|
|
||||||
static_pattern = cairo_pattern_create_for_surface (surface);
|
|
||||||
cairo_pattern_set_extend (static_pattern, CAIRO_EXTEND_REFLECT);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
g_warning ("Failed to create surface for gradient1.png\n");
|
|
||||||
}
|
|
||||||
return static_pattern;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
draw_background (GtkWidget *widget, cairo_t *cr)
|
draw_background (GtkWidget *widget, cairo_t *cr)
|
||||||
{
|
{
|
||||||
@ -98,26 +111,14 @@ draw_background (GtkWidget *widget, cairo_t *cr)
|
|||||||
|
|
||||||
cairo_save (cr);
|
cairo_save (cr);
|
||||||
|
|
||||||
#if 0
|
pat = cairo_pattern_create_linear (0.0, 0.0, allocation.width, allocation.height);
|
||||||
pat = cairo_pattern_create_linear (0.0, 0.0, 30.0, 30.0);
|
|
||||||
cairo_pattern_add_color_stop_rgba (pat, 1, 0, 0, 0, 1);
|
cairo_pattern_add_color_stop_rgba (pat, 1, 0, 0, 0, 1);
|
||||||
cairo_pattern_add_color_stop_rgba (pat, 0, 1, 1, 1, 1);
|
cairo_pattern_add_color_stop_rgba (pat, 0, 1, 1, 1, 1);
|
||||||
cairo_pattern_set_extend (pat, CAIRO_EXTEND_REPEAT);
|
|
||||||
cairo_rectangle (cr, 0, 0, allocation.width, allocation.height);
|
cairo_rectangle (cr, 0, 0, allocation.width, allocation.height);
|
||||||
cairo_set_source (cr, pat);
|
cairo_set_source (cr, pat);
|
||||||
cairo_fill (cr);
|
cairo_fill (cr);
|
||||||
cairo_pattern_destroy (pat);
|
cairo_pattern_destroy (pat);
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
if (get_pattern ())
|
|
||||||
{
|
|
||||||
cairo_rectangle (cr, 0, 0, allocation.width, allocation.height);
|
|
||||||
cairo_set_source (cr, get_pattern ());
|
|
||||||
cairo_fill (cr);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
cairo_restore (cr);
|
cairo_restore (cr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,6 +134,8 @@ main (int argc, char **argv)
|
|||||||
textview = gtk_text_view_new ();
|
textview = gtk_text_view_new ();
|
||||||
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview));
|
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview));
|
||||||
|
|
||||||
|
gtk_window_set_default_size (GTK_WINDOW (window), 400, -1);
|
||||||
|
|
||||||
create_tags (buffer);
|
create_tags (buffer);
|
||||||
insert_text (buffer);
|
insert_text (buffer);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user