From 0d7184db200e4f63e12f12d4ba1ba30aeb531358 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Tue, 9 Oct 2007 15:11:01 +0000 Subject: [PATCH] 2007-10-09 Emmanuele Bassi * clutter/clutter-script-private.h: * clutter/clutter-script.c: Allow applying behaviours directly inside the UI definition data. * tests/test-script.c: Test the "behaviours" member. --- ChangeLog | 8 +++++++ clutter/clutter-script-private.h | 1 + clutter/clutter-script.c | 52 ++++++++++++++++++++++++++++++++++++---- tests/test-script.c | 18 +++++++------- 4 files changed, 64 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 30bbd79..74de879 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2007-10-09 Emmanuele Bassi + + * clutter/clutter-script-private.h: + * clutter/clutter-script.c: Allow applying behaviours directly + inside the UI definition data. + + * tests/test-script.c: Test the "behaviours" member. + 2007-10-09 Rob Bradford * clutter/eglnative/clutter-backend-egl.c: diff --git a/clutter/clutter-script-private.h b/clutter/clutter-script-private.h index ae5a7c7..a8a8637 100644 --- a/clutter/clutter-script-private.h +++ b/clutter/clutter-script-private.h @@ -39,6 +39,7 @@ typedef struct { GList *properties; GList *children; + GList *behaviours; GType gtype; GObject *object; diff --git a/clutter/clutter-script.c b/clutter/clutter-script.c index 817f33a..5fc7ece 100644 --- a/clutter/clutter-script.c +++ b/clutter/clutter-script.c @@ -467,7 +467,8 @@ parse_member_to_property (ClutterScript *script, g_value_init (&retval->value, CLUTTER_TYPE_GEOMETRY); g_value_set_boxed (&retval->value, &geom); } - else if (strcmp (name, "children") == 0) + else if ((strcmp (name, "children") == 0) || + (strcmp (name, "behaviours") == 0)) { JsonArray *array = json_node_get_array (node); JsonNode *val; @@ -504,12 +505,15 @@ parse_member_to_property (ClutterScript *script, break; default: - warn_invalid_value (script, "children", val); + warn_invalid_value (script, name, val); break; } } - - info->children = children; + + if (name[0] == 'c') /* children */ + info->children = children; + else + info->behaviours = children; } break; @@ -783,6 +787,38 @@ translate_properties (ClutterScript *script, } static void +apply_behaviours (ClutterScript *script, + ClutterActor *actor, + GList *behaviours) +{ + GObject *object; + GList *l; + + for (l = behaviours; l != NULL; l = l->next) + { + const gchar *name = l->data; + + object = clutter_script_get_object (script, name); + if (!object) + { + ObjectInfo *oinfo; + + oinfo = g_hash_table_lookup (script->priv->objects, name); + if (oinfo) + object = clutter_script_construct_object (script, oinfo); + else + continue; + } + + CLUTTER_NOTE (SCRIPT, "Applying behaviour `%s' to actor of type `%s'", + name, + g_type_name (G_OBJECT_TYPE (actor))); + + clutter_behaviour_apply (CLUTTER_BEHAVIOUR (object), actor); + } +} + +static void add_children (ClutterScript *script, ClutterContainer *container, GList *children) @@ -915,9 +951,12 @@ clutter_script_construct_object (ClutterScript *script, g_free (params); - if (oinfo->children && CLUTTER_IS_CONTAINER (oinfo->object)) + if (CLUTTER_IS_CONTAINER (oinfo->object) && oinfo->children) add_children (script, CLUTTER_CONTAINER (oinfo->object), oinfo->children); + if (CLUTTER_IS_ACTOR (oinfo->object) && oinfo->behaviours) + apply_behaviours (script, CLUTTER_ACTOR (oinfo->object), oinfo->behaviours); + if (oinfo->id) g_object_set_data_full (oinfo->object, "clutter-script-name", g_strdup (oinfo->id), @@ -971,6 +1010,9 @@ object_info_free (gpointer data) g_list_foreach (oinfo->children, (GFunc) g_free, NULL); g_list_free (oinfo->children); + g_list_foreach (oinfo->behaviours, (GFunc) g_free, NULL); + g_list_free (oinfo->behaviours); + if (oinfo->object) g_object_unref (oinfo->object); diff --git a/tests/test-script.c b/tests/test-script.c index c265111..832d247 100644 --- a/tests/test-script.c +++ b/tests/test-script.c @@ -58,13 +58,14 @@ static const gchar *test_ui = " \"visible\" : true," " }," " {" -" \"id\" : \"red-hand\"," -" \"type\" : \"ClutterTexture\"," -" \"pixbuf\" : \"redhand.png\"," -" \"x\" : 50," -" \"y\" : 50," -" \"opacity\" : 25," -" \"visible\" : true," +" \"id\" : \"red-hand\"," +" \"type\" : \"ClutterTexture\"," +" \"pixbuf\" : \"redhand.png\"," +" \"x\" : 50," +" \"y\" : 50," +" \"opacity\" : 100," +" \"visible\" : true," +" \"behaviours\" : [ \"rotate-behaviour\" ]" " }" " ]" " }" @@ -107,10 +108,7 @@ main (int argc, char *argv[]) stage = CLUTTER_ACTOR (clutter_script_get_object (script, "main-stage")); clutter_actor_show (stage); - texture = CLUTTER_ACTOR (clutter_script_get_object (script, "red-hand")); - rotate = CLUTTER_BEHAVIOUR (clutter_script_get_object (script, "rotate-behaviour")); - clutter_behaviour_apply (rotate, texture); clutter_timeline_start (clutter_alpha_get_timeline (clutter_behaviour_get_alpha (rotate))); clutter_main (); -- 2.7.4