summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Wood <thomas.wood@intel.com>2009-10-07 11:38:08 +0100
committerThomas Wood <thomas.wood@intel.com>2009-10-07 11:38:08 +0100
commiteb8daac4b0726c1d9925bbbaeed7a8f39007da21 (patch)
tree756af2ce32bd20c56cd185c2aa83a858498ed5e7
parent9e03d9231696160ef7d4d98cf6c1d2f2214c7172 (diff)
downloadclutter-eb8daac4b0726c1d9925bbbaeed7a8f39007da21.tar.gz
[color] allow alpha to omitted when converting from strings
Parse #rgb and #rrggbb in addition to forms with the alpha channel specified. This allows conversion of colour strings from documents such as CSS where the alpha channel is not specified when using '#' notation.
-rw-r--r--clutter/clutter-color.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/clutter/clutter-color.c b/clutter/clutter-color.c
index a190690d1..f1c55f1c8 100644
--- a/clutter/clutter-color.c
+++ b/clutter/clutter-color.c
@@ -430,6 +430,28 @@ clutter_color_from_string (ClutterColor *color,
return TRUE;
}
+ else if (strlen (str) == 7)
+ {
+ /* #rrggbb */
+ color->red = (result >> 24) & 0xff;
+ color->green = (result >> 16) & 0xff;
+ color->blue = (result >> 8) & 0xff;
+
+ color->alpha = 0xff;
+ }
+ else if (strlen (str) == 4)
+ {
+ /* #rgb */
+ color->red = ((result >> 12) & 0xf);
+ color->green = ((result >> 8) & 0xf);
+ color->blue = ((result >> 4) & 0xf);
+
+ color->red = (color->red << 4) | color->red;
+ color->green = (color->green << 4) | color->green;
+ color->blue = (color->blue << 4) | color->blue;
+
+ color->alpha = 0xff;
+ }
}
}