summaryrefslogtreecommitdiff
path: root/src/utilities/color.vala
diff options
context:
space:
mode:
Diffstat (limited to 'src/utilities/color.vala')
-rw-r--r--src/utilities/color.vala21
1 files changed, 21 insertions, 0 deletions
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
@@ -77,6 +77,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
/////////////////////////////////////////////////////////////////////
@@ -129,6 +142,14 @@ public class Color: GLib.Object {
}
/////////////////////////////////////////////////////////////////////
+ /// 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.
/////////////////////////////////////////////////////////////////////