[libgd] gd-two-lines-renderer: use Pango alpha attribute
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgd] gd-two-lines-renderer: use Pango alpha attribute
- Date: Sun, 2 Jul 2017 01:01:43 +0000 (UTC)
commit c1a40ee08e94828d67ab2284b41948bdd8c41a7f
Author: Christian Hergert <chergert redhat com>
Date: Sat Jul 1 18:00:16 2017 -0700
gd-two-lines-renderer: use Pango alpha attribute
This code was previously trying to alter the color of the second
line by manipulating the foreground color. Now that gtk+ 3.22
is our stable branch, we can rely on more recent stable features
such as Pango's alpha attribute.
The problem with the code previously is that it would not
respect the GTK_CELL_RENDERER_SELECTED state. It would draw the
altered non-selected state with a dim-level on top of a
selected row.
By simply avoiding the foreground color altogether (and
inheriting it from the PangoLayout state when rendering), we
get the appropriate color and also blend into the selected row
state properly.
libgd/gd-two-lines-renderer.c | 17 +++++------------
1 files changed, 5 insertions(+), 12 deletions(-)
---
diff --git a/libgd/gd-two-lines-renderer.c b/libgd/gd-two-lines-renderer.c
index 9840527..5a029f7 100644
--- a/libgd/gd-two-lines-renderer.c
+++ b/libgd/gd-two-lines-renderer.c
@@ -87,15 +87,13 @@ apply_subtitle_style_to_layout (GtkStyleContext *context,
GtkStateFlags flags)
{
PangoFontDescription *desc;
- GdkRGBA rgba = {0.0, 0.0, 0.0, 0.0};
PangoAttrList *layout_attr;
- PangoAttribute *attr_color;
+ PangoAttribute *attr_alpha;
gtk_style_context_save (context);
gtk_style_context_set_state (context, flags);
gtk_style_context_get (context, gtk_style_context_get_state (context),
"font", &desc,
- "color", &rgba,
NULL);
gtk_style_context_restore (context);
@@ -104,16 +102,11 @@ apply_subtitle_style_to_layout (GtkStyleContext *context,
pango_layout_set_font_description (layout, desc);
pango_font_description_free (desc);
- /* Set the color */
- rgba.red = CLAMP(1.0 - ((1.0 - rgba.red) * SUBTITLE_DIM_PERCENTAGE), 0.0, 1.0);
- rgba.green = CLAMP(1.0 - ((1.0 - rgba.green) * SUBTITLE_DIM_PERCENTAGE), 0.0, 1.0);
- rgba.blue = CLAMP(1.0 - ((1.0 - rgba.blue) * SUBTITLE_DIM_PERCENTAGE), 0.0, 1.0);
-
+ /* Set the font alpha */
layout_attr = pango_attr_list_new ();
- attr_color = pango_attr_foreground_new (rgba.red * 65535,
- rgba.green * 65535,
- rgba.blue * 65535);
- pango_attr_list_insert (layout_attr, attr_color);
+ attr_alpha = pango_attr_foreground_alpha_new (SUBTITLE_DIM_PERCENTAGE * 65535);
+ pango_attr_list_insert (layout_attr, attr_alpha);
+
pango_layout_set_attributes (layout, layout_attr);
pango_attr_list_unref (layout_attr);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]