1
0
Fork 0

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

@ -1,3 +1,11 @@
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.
2007-10-09 Rob Bradford <rob@openedhand.com>
* clutter/eglnative/clutter-backend-egl.c:

View file

@ -39,6 +39,7 @@ typedef struct {
GList *properties;
GList *children;
GList *behaviours;
GType gtype;
GObject *object;

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);

View file

@ -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 ();