summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Hergert <chergert@redhat.com>2017-07-01 18:00:16 -0700
committerChristian Hergert <chergert@redhat.com>2017-07-01 18:00:16 -0700
commitc1a40ee08e94828d67ab2284b41948bdd8c41a7f (patch)
tree9dcf08951b368d835dd4564ebc00cda2bfa67144
parentedcb3af3790a0d108bf303aca989c24eab675c49 (diff)
downloadlibgd-c1a40ee08e94828d67ab2284b41948bdd8c41a7f.tar.gz
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.
-rw-r--r--libgd/gd-two-lines-renderer.c17
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);
}