From 8ba13d6495d00885380db3a23f552633c5c43c0a Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 4 Nov 2009 15:21:03 +0000 Subject: [PATCH] script: Clean up Color parsing rules All the ClutterColor parsing rules should be coalesced inside clutter_script_parse_color(): object, array and string notations are the canonical ways of defining a ClutterColor inside a ClutterScript definition. Having a single function in charge of the parsing cleans up the code. --- clutter/clutter-script-parser.c | 17 +++++++---------- tests/conform/test-script-parser.c | 6 ++++++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/clutter/clutter-script-parser.c b/clutter/clutter-script-parser.c index fad68053c..84279aeff 100644 --- a/clutter/clutter-script-parser.c +++ b/clutter/clutter-script-parser.c @@ -479,6 +479,9 @@ clutter_script_parse_color (ClutterScript *script, case JSON_NODE_OBJECT: return parse_color_from_object (json_node_get_object (node), color); + case JSON_NODE_VALUE: + return clutter_color_from_string (color, json_node_get_string (node)); + default: break; } @@ -1279,17 +1282,11 @@ clutter_script_parse_node (ClutterScript *script, case G_TYPE_BOXED: if (G_VALUE_HOLDS (value, CLUTTER_TYPE_COLOR)) { - if (G_VALUE_HOLDS (&node_value, G_TYPE_STRING)) - { - const gchar *str = g_value_get_string (&node_value); - ClutterColor color = { 0, }; + ClutterColor color = { 0, }; - if (str && str[0] != '\0') - clutter_color_from_string (&color, str); - - g_value_set_boxed (value, &color); - retval = TRUE; - } + retval = clutter_script_parse_color (script, node, &color); + if (retval) + clutter_value_set_color (value, &color); } break; diff --git a/tests/conform/test-script-parser.c b/tests/conform/test-script-parser.c index 929f7bcb1..395308aa8 100644 --- a/tests/conform/test-script-parser.c +++ b/tests/conform/test-script-parser.c @@ -10,6 +10,7 @@ test_script_single (TestConformSimpleFixture *fixture, gconstpointer dummy) { ClutterScript *script = clutter_script_new (); + ClutterColor color = { 0, }; GObject *actor = NULL; GError *error = NULL; ClutterActor *rect; @@ -26,6 +27,11 @@ test_script_single (TestConformSimpleFixture *fixture, g_assert_cmpfloat (clutter_actor_get_width (rect), ==, 50.0); g_assert_cmpfloat (clutter_actor_get_y (rect), ==, 100.0); + clutter_rectangle_get_color (CLUTTER_RECTANGLE (rect), &color); + g_assert_cmpint (color.red, ==, 255); + g_assert_cmpint (color.green, ==, 0xcc); + g_assert_cmpint (color.alpha, ==, 0xff); + g_object_unref (script); clutter_actor_destroy (rect);