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

* clutter/clutter-script.c (clutter_script_get_object): Construct
	the requested object if it hasn't been already. This allows
	referencing objects within the same snippet.

	* tests/test-script.c: Declare a timeline and use it inside
	multiple behaviours; apply multiple behaviours to various
	actors, then retrieve the timeline to start it when the test
	runs.
This commit is contained in:
Emmanuele Bassi 2007-10-09 16:21:04 +00:00
parent 0d7184db20
commit b0569d0f27
3 changed files with 52 additions and 21 deletions

View File

@ -1,3 +1,14 @@
2007-10-09 Emmanuele Bassi <ebassi@openedhand.com>
* clutter/clutter-script.c (clutter_script_get_object): Construct
the requested object if it hasn't been already. This allows
referencing objects within the same snippet.
* tests/test-script.c: Declare a timeline and use it inside
multiple behaviours; apply multiple behaviours to various
actors, then retrieve the timeline to start it when the test
runs.
2007-10-09 Emmanuele Bassi <ebassi@openedhand.com> 2007-10-09 Emmanuele Bassi <ebassi@openedhand.com>
* clutter/clutter-script-private.h: * clutter/clutter-script-private.h:

View File

@ -196,12 +196,14 @@ resolve_alpha_func (const gchar *name)
{ {
c = name[i]; c = name[i];
/* skip if uppercase, first or previous is uppercase */ /* skip if uppercase, first or previous is uppercase */
if ((c == g_ascii_toupper (c) && if ((c == '-') ||
(c == g_ascii_toupper (c) &&
i > 0 && name[i-1] != g_ascii_toupper (name[i-1])) || i > 0 && name[i-1] != g_ascii_toupper (name[i-1])) ||
(i > 2 && name[i] == g_ascii_toupper (name[i]) && (i > 2 && name[i] == g_ascii_toupper (name[i]) &&
name[i-1] == g_ascii_toupper (name[i-1]) && name[i-1] == g_ascii_toupper (name[i-1]) &&
name[i-2] == g_ascii_toupper (name[i-2]))) name[i-2] == g_ascii_toupper (name[i-2])))
g_string_append_c (symbol_name, '_'); g_string_append_c (symbol_name, '_');
g_string_append_c (symbol_name, g_ascii_tolower (c)); g_string_append_c (symbol_name, g_ascii_tolower (c));
} }
g_string_append (symbol_name, "_func"); g_string_append (symbol_name, "_func");
@ -210,7 +212,7 @@ resolve_alpha_func (const gchar *name)
if (!g_module_symbol (module, symbol, (gpointer)&func)) if (!g_module_symbol (module, symbol, (gpointer)&func))
func = NULL; func = NULL;
g_free (symbol); g_free (symbol);
return func; return func;
@ -1145,7 +1147,7 @@ clutter_script_get_object (ClutterScript *script,
if (!oinfo) if (!oinfo)
return NULL; return NULL;
return oinfo->object; return clutter_script_construct_object (script, oinfo);
} }
static GList * static GList *

View File

@ -6,17 +6,36 @@
#include <clutter/clutter.h> #include <clutter/clutter.h>
static const gchar *test_behaviour = static const gchar *test_behaviour =
"{" "["
" \"id\" : \"rotate-behaviour\"," " {"
" \"type\" : \"ClutterBehaviourRotate\"," " \"id\" : \"main-timeline\","
" \"angle-begin\" : 0.0," " \"type\" : \"ClutterTimeline\","
" \"angle-end\" : 360.0," " \"num-frames\" : 300,"
" \"axis\" : \"z-axis\"," " \"fps\" : 60,"
" \"alpha\" : {" " \"loop\" : true"
" \"timeline\" : { \"num-frames\" : 300, \"fps\" : 60, \"loop\" : true }," " },"
" \"function\" : \"sine\"" " {"
" \"id\" : \"rotate-behaviour\","
" \"type\" : \"ClutterBehaviourRotate\","
" \"angle-begin\" : 0.0,"
" \"angle-end\" : 360.0,"
" \"axis\" : \"z-axis\","
" \"alpha\" : {"
" \"timeline\" : \"main-timeline\","
" \"function\" : \"sine\""
" }"
" },"
" {"
" \"id\" : \"fade-behaviour\","
" \"type\" : \"ClutterBehaviourOpacity\","
" \"opacity-start\" : 255,"
" \"opacity-end\" : 0,"
" \"alpha\" : {"
" \"timeline\" : \"main-timeline\","
" \"function\" : \"ramp\""
" }"
" }" " }"
"}"; "]";
static const gchar *test_ui = static const gchar *test_ui =
"{" "{"
@ -46,6 +65,7 @@ static const gchar *test_ui =
" \"width\" : 100," " \"width\" : 100,"
" \"height\" : 100," " \"height\" : 100,"
" \"visible\" : true," " \"visible\" : true,"
" \"behaviours\" : [ \"fade-behaviour\" ]"
" }," " },"
" {" " {"
" \"id\" : \"blue-button\"," " \"id\" : \"blue-button\","
@ -65,7 +85,7 @@ static const gchar *test_ui =
" \"y\" : 50," " \"y\" : 50,"
" \"opacity\" : 100," " \"opacity\" : 100,"
" \"visible\" : true," " \"visible\" : true,"
" \"behaviours\" : [ \"rotate-behaviour\" ]" " \"behaviours\" : [ \"rotate-behaviour\", \"fade-behaviour\" ]"
" }" " }"
" ]" " ]"
" }" " }"
@ -74,10 +94,8 @@ static const gchar *test_ui =
int int
main (int argc, char *argv[]) main (int argc, char *argv[])
{ {
ClutterActor *stage;
ClutterActor *texture;
ClutterBehaviour *rotate;
ClutterScript *script; ClutterScript *script;
GObject *stage, *timeline;
GError *error = NULL; GError *error = NULL;
clutter_init (&argc, &argv); clutter_init (&argc, &argv);
@ -105,11 +123,11 @@ main (int argc, char *argv[])
return EXIT_FAILURE; return EXIT_FAILURE;
} }
stage = CLUTTER_ACTOR (clutter_script_get_object (script, "main-stage")); stage = clutter_script_get_object (script, "main-stage");
clutter_actor_show (stage); clutter_actor_show (CLUTTER_ACTOR (stage));
rotate = CLUTTER_BEHAVIOUR (clutter_script_get_object (script, "rotate-behaviour")); timeline = clutter_script_get_object (script, "main-timeline");
clutter_timeline_start (clutter_alpha_get_timeline (clutter_behaviour_get_alpha (rotate))); clutter_timeline_start (CLUTTER_TIMELINE (timeline));
clutter_main (); clutter_main ();