From a1c05d93bbb3c1bdb0c0fed9d7110804037cfd55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sun, 3 May 2015 07:25:37 +0200 Subject: Imported Upstream version 0.6.2 --- src/utilities/color.vala | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/utilities/color.vala') diff --git a/src/utilities/color.vala b/src/utilities/color.vala index 6bb9d06..a681e02 100644 --- a/src/utilities/color.vala +++ b/src/utilities/color.vala @@ -76,6 +76,19 @@ public class Color: GLib.Object { ); } + ///////////////////////////////////////////////////////////////////// + /// Creates a color from a given widget style + ///////////////////////////////////////////////////////////////////// + + public Color.from_widget_style(Gtk.Widget widget, string style_name) { + var ctx = widget.get_style_context(); + Gdk.RGBA color; + if (!ctx.lookup_color(style_name, out color)) { + warning("Failed to get style color for widget style \"" + style_name + "\"!"); + } + Color.from_gdk(color); + } + ///////////////////////////////////////////////////////////////////// /// Creates a color, parsed from a string, such as #22EE33 ///////////////////////////////////////////////////////////////////// @@ -128,6 +141,14 @@ public class Color: GLib.Object { v = 1.0f; } + ///////////////////////////////////////////////////////////////////// + /// Returns this color as its hex representation. + ///////////////////////////////////////////////////////////////////// + + public string to_hex_string() { + return "#%02X%02X%02X".printf((int)(_r*255), (int)(_g*255), (int)(_b*255)); + } + ///////////////////////////////////////////////////////////////////// /// The reddish part of the color. ///////////////////////////////////////////////////////////////////// -- cgit v1.2.3