From 9f009d52819c7a7b48a543b0c52946f0b8b79883 Mon Sep 17 00:00:00 2001 From: Michael Dominic Kostrzewa Date: Thu, 21 Sep 2006 09:46:53 +0000 Subject: [PATCH] 2006-09-21 Michael Dominic Kostrzewa * hildon-widgets-plugins/hildon-color-chooser-dialog-hsv.c: Reverting the hex -> color func (hsv not supported by the parse function). Fixing a bug where last character is not appended to the color -> ascii conversion. Fixes #NB40061. --- ChangeLog | 7 ++++++ .../hildon-color-chooser-dialog-hsv.c | 25 +++++++++++++------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index fcfc457..7b17901 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2006-09-21 Michael Dominic Kostrzewa + + * hildon-widgets-plugins/hildon-color-chooser-dialog-hsv.c: Reverting + the hex -> color func (hsv not supported by the parse function). + Fixing a bug where last character is not appended to the color -> + ascii conversion. Fixes #NB40061. + 2006-09-20 Michael Dominic Kostrzewa * hildon-widgets/hildon-get-password-dialog.c: Fixing the way input diff --git a/hildon-widgets-plugins/hildon-color-chooser-dialog-hsv.c b/hildon-widgets-plugins/hildon-color-chooser-dialog-hsv.c index 12bb705..e72d44b 100644 --- a/hildon-widgets-plugins/hildon-color-chooser-dialog-hsv.c +++ b/hildon-widgets-plugins/hildon-color-chooser-dialog-hsv.c @@ -1007,21 +1007,28 @@ static void hildon_color_chooser_dialog_hsv_set_color_num(HildonColorChooserDial static void hildon_color_chooser_dialog_hsv_ascii_hex_to_color(gchar *s, GdkColor *color) { - g_return_if_fail (s != NULL); - g_return_if_fail (color != NULL); + int vals[12], i; - if (s[0] != '#') { - gchar *s_copy = g_strdup_printf ("#%s", s); - gdk_color_parse (s_copy, color); - g_free (s_copy); - } else { - gdk_color_parse (s, color); + + for(i = 0; i < 12; i++) { + if(s[i] >= '0' && s[i] <= '9') { + vals[i] = s[i] - 0x30; + } else if(s[i] >= 'a' && s[i] <= 'f') { + vals[i] = s[i] - 0x57; + } else { + vals[i] = 0; + } } + + + color->red = (vals[0] << 12) | (vals[1] << 8) | (vals[2 ] << 4) | (vals[3 ] ); + color->green = (vals[4] << 12) | (vals[5] << 8) | (vals[6 ] << 4) | (vals[7 ] ); + color->blue = (vals[8] << 12) | (vals[9] << 8) | (vals[10] << 4) | (vals[11] ); } static void hildon_color_chooser_dialog_hsv_color_to_ascii_hex(gchar *s, GdkColor *color) { - g_snprintf(s, 12, "%x%x%x%x%x%x%x%x%x%x%x%x", + g_snprintf(s, 13, "%x%x%x%x%x%x%x%x%x%x%x%x", (color->red >> 12) & 0xf, (color->red >> 8) & 0xf, (color->red >> 4) & 0xf, (color->red ) & 0xf, (color->green >> 12) & 0xf, (color->green >> 8) & 0xf, -- 1.7.9.5