2007-10-09 Emmanuele Bassi <ebassi@openedhand.com>

* 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.
This commit is contained in:
Emmanuele Bassi
2007-10-09 15:11:01 +00:00
parent 9e3f1e0d4c
commit 0d7184db20
4 changed files with 64 additions and 15 deletions

View File

@ -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;
@ -782,6 +786,38 @@ translate_properties (ClutterScript *script,
g_type_class_unref (oclass);
}
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,
@ -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);