[Xfce4-commits] <postler:master> Untangle convo renderer colors and match the theme

Christian Dywan noreply at xfce.org
Tue Sep 6 01:22:05 CEST 2011


Updating branch refs/heads/master
         to 779392473bf8a8bad1253d32dfa7dc71fae983fa (commit)
       from 49fd9eb01a8cc100e231609c7db40a05e5465687 (commit)

commit 779392473bf8a8bad1253d32dfa7dc71fae983fa
Author: Christian Dywan <christian at twotoasts.de>
Date:   Wed Aug 17 21:16:50 2011 +0200

    Untangle convo renderer colors and match the theme

 postler/postler-cellrendererconvo.vala |  108 ++++++++++++++------------------
 1 files changed, 48 insertions(+), 60 deletions(-)

diff --git a/postler/postler-cellrendererconvo.vala b/postler/postler-cellrendererconvo.vala
index af862c2..258d19f 100644
--- a/postler/postler-cellrendererconvo.vala
+++ b/postler/postler-cellrendererconvo.vala
@@ -16,10 +16,22 @@ public struct Gdk.RGBA {
     double blue;
     double alpha;
 }
+
 namespace Gdk {
     static void cairo_set_source_rgba (Cairo.Context cr, Gdk.RGBA color) {
         cr.set_source_rgba (color.red, color.green, color.blue, color.alpha);
     }
+
+    static Gdk.RGBA color_to_rgba (Gdk.Color? color)
+    {
+        Gdk.RGBA link_color = Gdk.RGBA ();
+        return_val_if_fail (color != null, link_color);
+        link_color.red = ((double)color.red) / 0xFFFF;
+        link_color.green = ((double)color.green) / 0xFFFF;
+        link_color.blue = ((double)color.blue) / 0xFFFF;
+        link_color.alpha = 1.0;
+        return link_color;
+    }
 }
 #endif
 
@@ -99,45 +111,6 @@ public class Postler.CellRendererConvo : Gtk.CellRenderer {
     }
 
     /**
-     * Utility function to get the system link color, which is a Gdk.Color,
-     * we convert it to Gdk.RGBA to use it easily with cairo.
-     *
-     * @param style a valid StyleContext, we'll extract the Gdk.Color of the
-     * link from it.
-     *
-     * @return a Gdk.RGBA, which contains the link color
-     **/
-#if HAVE_GTK3
-    static Gdk.RGBA get_link_color (Gtk.StyleContext style) {
-#else
-    static Gdk.RGBA get_link_color (Gtk.Style style) {
-#endif
-        Gdk.Color? link_color_ = Gdk.Color();
-#if HAVE_GTK3
-        Value g_value = Value (typeof (Gdk.Color));
-        style.get_style_property ("link-color", g_value);
-        link_color_ = (Gdk.Color?)g_value.get_boxed ();
-#else
-        style.lookup_color ("link_color", out link_color_);
-#endif
-        if (link_color_ == null)
-            Gdk.Color.parse ("#00e", out link_color_);
-        Gdk.RGBA link_color = gdk_color_to_rgba (link_color_);
-        return link_color;
-    }
-
-    static Gdk.RGBA gdk_color_to_rgba (Gdk.Color? color)
-    {
-        Gdk.RGBA link_color = Gdk.RGBA ();
-        return_val_if_fail (color != null, link_color);
-        link_color.red = ((double)color.red) / 0xFFFF;
-        link_color.green = ((double)color.green) / 0xFFFF;
-        link_color.blue = ((double)color.blue) / 0xFFFF;
-        link_color.alpha = 1.0;
-        return link_color;
-    }
-
-    /**
      * Function called by gtk to draw the cell content.
      **/
 #if HAVE_GTK3
@@ -150,18 +123,41 @@ public class Postler.CellRendererConvo : Gtk.CellRenderer {
                                  Gdk.Rectangle expose_area, Gtk.CellRendererState flags) {
 #endif
         Pango.Layout? layout = null;
+        Gdk.RGBA color_normal, color_inverse, color_insensitive;
 #if HAVE_GTK3
-        Gtk.StyleContext style = widget.get_style_context();
-#else
-        Gtk.Style style = widget.get_style();
-#endif
-        Gdk.RGBA link_color = get_link_color(style);
-#if HAVE_GTK3
-        Gdk.RGBA color_normal = style.get_color((flags & Gtk.CellRendererState.FOCUSED) > 0 ? Gtk.StateFlags.SELECTED : Gtk.StateFlags.NORMAL);
-        Gdk.RGBA color_insensitive = style.get_color(Gtk.StateFlags.INSENSITIVE);
+        Gtk.StyleContext style = widget.get_style_context ();
+        if ((flags & Gtk.CellRendererState.SELECTED) > 0) {
+            color_normal = style.get_color (Gtk.StateFlags.SELECTED);
+            color_inverse = style.get_color (Gtk.StateFlags.NORMAL);
+            color_insensitive = style.get_color (Gtk.StateFlags.INSENSITIVE);
+        }
+        else if (replies > 0) {
+            color_normal = style.get_background_color (Gtk.StateFlags.SELECTED);
+            color_inverse = style.get_background_color (Gtk.StateFlags.NORMAL);
+            color_insensitive = style.get_color (Gtk.StateFlags.INSENSITIVE);
+        }
+        else {
+            color_normal = style.get_color (Gtk.StateFlags.NORMAL);
+            color_inverse = style.get_color (Gtk.StateFlags.SELECTED);
+            color_insensitive = style.get_color (Gtk.StateFlags.INSENSITIVE);
+        }
 #else
-        Gdk.RGBA color_normal = gdk_color_to_rgba(style.fg[(flags & Gtk.CellRendererState.FOCUSED) > 0 ? Gtk.StateType.SELECTED : Gtk.StateType.NORMAL]);
-        Gdk.RGBA color_insensitive = gdk_color_to_rgba(style.fg[Gtk.StateType.INSENSITIVE]);
+        Gtk.Style style = widget.get_style ();
+        if ((flags & Gtk.CellRendererState.SELECTED) > 0) {
+            color_normal = Gdk.color_to_rgba (style.text[Gtk.StateType.SELECTED]);
+            color_inverse = Gdk.color_to_rgba (style.fg[Gtk.StateType.NORMAL]);
+            color_insensitive = Gdk.color_to_rgba (style.text[Gtk.StateType.INSENSITIVE]);
+        }
+        else if (replies > 0) {
+            color_normal = Gdk.color_to_rgba (style.base[Gtk.StateType.SELECTED]);
+            color_inverse = Gdk.color_to_rgba (style.base[Gtk.StateType.NORMAL]);
+            color_insensitive = Gdk.color_to_rgba (style.fg[Gtk.StateType.INSENSITIVE]);
+        }
+        else {
+            color_normal = Gdk.color_to_rgba (style.fg[Gtk.StateType.NORMAL]);
+            color_inverse = Gdk.color_to_rgba (style.fg[Gtk.StateType.SELECTED]);
+            color_insensitive = Gdk.color_to_rgba (style.fg[Gtk.StateType.INSENSITIVE]);
+        }
 
         Cairo.Context cr = Gdk.cairo_create(draw);
 #endif
@@ -181,16 +177,8 @@ public class Postler.CellRendererConvo : Gtk.CellRenderer {
             color_normal.blue -= 0.2;
         }
 
-        /* Replies */
-        if (replies > 0) {
-            color_normal.blue += 0.5;
-            color_normal.green -= 0.2;
-            color_normal.red -= 0.2;
-        }
-
         /* Show date */
-        Gdk.cairo_set_source_rgba (cr,
-            (flags & Gtk.CellRendererState.FOCUSED) > 0 ? color_normal  : link_color);
+        Gdk.cairo_set_source_rgba (cr, color_normal);
         layout = widget.create_pango_layout (date);
         layout.set_font_description (font_small);
         double date_width = get_layout_width (layout);
@@ -209,12 +197,12 @@ public class Postler.CellRendererConvo : Gtk.CellRenderer {
             rounded (cr, area.x + area.width - rect_width - 5,
                          area.y + area.height / 2 - rect_height / 2 + margin,
                          rect_width, rect_height);
-            Gdk.cairo_set_source_rgba (cr, link_color);
+            Gdk.cairo_set_source_rgba (cr, color_normal);
             cr.fill ();
             /* Real text */
             cr.move_to (area.x + area.width - get_layout_width (layout) - margin - 5,
                         area.y + area.height / 2 - get_layout_height (layout) / 2);
-            Gdk.cairo_set_source_rgba (cr, {1, 1, 1, 1});
+            Gdk.cairo_set_source_rgba (cr, color_inverse);
             Pango.cairo_show_layout (cr, layout);
         }
 


More information about the Xfce4-commits mailing list