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;
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;
}
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)
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),
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);
" \"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\" ]"
" }"
" ]"
" }"
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 ();