[gnome-control-center] universal-access: Simplify colour reading code
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] universal-access: Simplify colour reading code
- Date: Wed, 21 Sep 2011 18:20:59 +0000 (UTC)
commit ff394b08a1d800844bf291575e3193b1ae74beb2
Author: Bastien Nocera <hadess hadess net>
Date: Wed Sep 21 19:09:14 2011 +0100
universal-access: Simplify colour reading code
Using GdkRGBA directly, and making our own #rrggbb colour.
panels/universal-access/zoom-options.c | 19 ++++++++-----------
1 files changed, 8 insertions(+), 11 deletions(-)
---
diff --git a/panels/universal-access/zoom-options.c b/panels/universal-access/zoom-options.c
index dc89ffc..9151a6c 100644
--- a/panels/universal-access/zoom-options.c
+++ b/panels/universal-access/zoom-options.c
@@ -116,25 +116,22 @@ update_xhairs_opacity_cb (GSettings *settings, gchar *key, GtkColorButton *butto
gtk_color_button_set_alpha (button, opacity * 65535);
}
+#define TO_HEX(x) (int) ((gdouble) x * 255.0)
static void
xhairs_color_opacity_changed_cb (GtkColorButton *button, ZoomOptionsPrivate *priv)
{
GdkRGBA rgba;
- GdkColor rgb;
gchar *color_string;
- gchar gsetting_val[8];
- gtk_color_button_get_color (button, &rgb);
- color_string = gdk_color_to_string (&rgb);
+ gtk_color_button_get_rgba (button, &rgba);
+ color_string = g_strdup_printf ("#%02x%02x%02x",
+ TO_HEX(rgba.red),
+ TO_HEX(rgba.green),
+ TO_HEX(rgba.blue));
- /* color_string is in the form '#rrrrggggbbbb', convert to '#rrggbb'.
- Start by copying the leading '#' */
- g_strlcpy (gsetting_val, color_string, 4);
- g_strlcpy (gsetting_val + 3, color_string + 5, 3);
- g_strlcpy (gsetting_val + 5, color_string + 9, 3);
- g_settings_set_string (priv->settings, "cross-hairs-color", gsetting_val);
+ g_settings_set_string (priv->settings, "cross-hairs-color", color_string);
+ g_free (color_string);
- gtk_color_button_get_rgba (button, &rgba);
g_settings_set_double (priv->settings, "cross-hairs-opacity", rgba.alpha);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]