return TRUE;
}
+static gboolean
+parse_hsl (ClutterColor *color,
+ gchar *str)
+{
+ gdouble number;
+ gdouble h, l, s;
+
+ skip_whitespace (&str);
+
+ if (*str != '(')
+ return FALSE;
+
+ str += 1;
+
+ /* hue */
+ skip_whitespace (&str);
+ /* we don't do any angle normalization here because
+ * clutter_color_from_hls() will do it for us
+ */
+ number = g_ascii_strtod (str, &str);
+ skip_whitespace (&str);
+ if (*str != ',')
+ return FALSE;
+
+ h = number;
+
+ str += 1;
+
+ /* saturation */
+ skip_whitespace (&str);
+ number = g_ascii_strtod (str, &str);
+ skip_whitespace (&str);
+ if (*str != '%')
+ return FALSE;
+
+ str += 1;
+
+ s = CLAMP (number / 100.0, 0.0, 1.0);
+ skip_whitespace (&str);
+ if (*str != ',')
+ return FALSE;
+
+ str += 1;
+
+ /* luminance */
+ skip_whitespace (&str);
+ number = g_ascii_strtod (str, &str);
+ skip_whitespace (&str);
+ if (*str != '%')
+ return FALSE;
+
+ str += 1;
+
+ l = CLAMP (number / 100.0, 0.0, 1.0);
+ skip_whitespace (&str);
+ if (*str != ')')
+ return FALSE;
+
+ clutter_color_from_hls (color, h, l, s);
+
+ return TRUE;
+}
+
/**
* clutter_color_from_string:
* @color: (out caller-allocates): return location for a #ClutterColor
return res;
}
+ if (strncmp (str, "hsl", 3) == 0)
+ {
+ gchar *s = (gchar *) str;
+
+ return parse_hsl (color, s + 3);
+ }
+
/* if the string contains a color encoded using the hexadecimal
* notations (#rrggbbaa or #rgba) we attempt a rough pass at
* parsing the color ourselves, as we need the alpha channel that
g_assert_cmpint (color.green, ==, 0);
g_assert_cmpint (color.blue, ==, 255);
g_assert_cmpint (color.alpha, ==, 255);
+
+ g_assert (clutter_color_from_string (&color, "hsl( 0, 100%, 50% )"));
+ if (g_test_verbose ())
+ {
+ g_print ("color = { %x, %x, %x, %x }, expected = { 255, 0, 0, 255 }\n",
+ color.red,
+ color.green,
+ color.blue,
+ color.alpha);
+ }
+ g_assert_cmpint (color.red, ==, 255);
+ g_assert_cmpint (color.green, ==, 0);
+ g_assert_cmpint (color.blue, ==, 0);
+ g_assert_cmpint (color.alpha, ==, 255);
}
void