From c0aa72a04259564d462ca4b80e080eacac885ecd Mon Sep 17 00:00:00 2001 From: Elliot Smith Date: Wed, 1 Sep 2010 18:02:07 +0100 Subject: [PATCH] cookbook: Added complex animations example To support recipe about using ClutterAnimator to create complex animations. --- doc/cookbook/examples/Makefile.am | 2 + doc/cookbook/examples/animations-complex.c | 64 +++++++++++++++ doc/cookbook/examples/animations-complex.json | 80 +++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 doc/cookbook/examples/animations-complex.c create mode 100644 doc/cookbook/examples/animations-complex.json diff --git a/doc/cookbook/examples/Makefile.am b/doc/cookbook/examples/Makefile.am index 28db1fe00..4995c0e76 100644 --- a/doc/cookbook/examples/Makefile.am +++ b/doc/cookbook/examples/Makefile.am @@ -3,6 +3,7 @@ include $(top_srcdir)/build/autotools/Makefile.am.silent NULL = noinst_PROGRAMS = \ + animations-complex \ animations-rotating \ text-shadow \ textures-reflection \ @@ -41,6 +42,7 @@ AM_CFLAGS = \ AM_LDFLAGS = $(CLUTTER_LIBS) -export-dynamic +animations_complex_SOURCES = animations-complex.c animations_rotating_SOURCES = animations-rotating.c text_shadow_SOURCES = text-shadow.c textures_reflection_SOURCES = textures-reflection.c diff --git a/doc/cookbook/examples/animations-complex.c b/doc/cookbook/examples/animations-complex.c new file mode 100644 index 000000000..3121ef5a2 --- /dev/null +++ b/doc/cookbook/examples/animations-complex.c @@ -0,0 +1,64 @@ +#include +#include + +#define UI_FILE "animations-complex.json" + +/* + * start the animation when a key is pressed; + * see the signals recipe in the Script chapter for more details + */ +gboolean +foo_key_pressed_cb (ClutterActor *actor, + ClutterEvent *event, + gpointer user_data) +{ + ClutterScript *script = CLUTTER_SCRIPT (user_data); + + ClutterAnimator *animator; + clutter_script_get_objects (script, + "animator", &animator, + NULL); + + if (clutter_timeline_is_playing (clutter_animator_get_timeline (animator))) + return FALSE; + + clutter_animator_start (animator); + + return TRUE; +} + +int +main (int argc, char *argv[]) +{ + ClutterScript *script; + ClutterActor *stage; + + GError *error = NULL; + + clutter_init (&argc, &argv); + + script = clutter_script_new (); + clutter_script_load_from_file (script, UI_FILE, &error); + + if (error != NULL) + { + g_critical ("Error loading ClutterScript file %s\n%s", UI_FILE, error->message); + g_error_free (error); + exit (EXIT_FAILURE); + } + + /* connect signal handlers as defined in the script */ + clutter_script_connect_signals (script, script); + + clutter_script_get_objects (script, + "stage", &stage, + NULL); + + clutter_actor_show (stage); + + clutter_main (); + + g_object_unref (script); + + return EXIT_SUCCESS; +} diff --git a/doc/cookbook/examples/animations-complex.json b/doc/cookbook/examples/animations-complex.json new file mode 100644 index 000000000..39636f899 --- /dev/null +++ b/doc/cookbook/examples/animations-complex.json @@ -0,0 +1,80 @@ +[ + { + "type" : "ClutterStage", + "id" : "stage", + "width" : 400, + "height" : 400, + "color" : "#333355ff", + + "signals" : [ + { "name" : "destroy", "handler" : "clutter_main_quit" }, + { "name" : "key-press-event", "handler" : "foo_key_pressed_cb" } + ], + + "children" : [ + { + "type" : "ClutterRectangle", + "id" : "rectangle", + "color" : "red", + "width" : 100, + "height" : 100, + "x" : 0, + "y" : 0, + "scale-gravity" : "center" + } + ] + }, + + { + "type" : "ClutterAnimator", + "id" : "animator", + "duration" : 3000, + + "properties" : [ + { + "object" : "rectangle", + "name" : "x", + "ease-in" : true, + "keys" : [ + [ 0.0, "linear", 0.0 ], + [ 0.1, "easeInCubic", 150.0 ], + [ 0.8, "linear", 150.0 ], + [ 1.0, "easeInCubic", 0.0 ] + ] + }, + { + "object" : "rectangle", + "name" : "y", + "ease-in" : true, + "keys" : [ + [ 0.0, "linear", 0.0 ], + [ 0.1, "easeInCubic", 150.0 ], + [ 0.8, "linear", 150.0 ], + [ 1.0, "easeInCubic", 300.0 ] + ] + }, + { + "object" : "rectangle", + "name" : "scale-x", + "ease-in" : true, + "keys" : [ + [ 0.1, "linear", 1.0 ], + [ 0.3, "easeOutBounce", 2.0 ], + [ 0.8, "linear", 2.0 ], + [ 1.0, "linear", 1.0 ] + ] + }, + { + "object" : "rectangle", + "name" : "scale-y", + "ease-in" : true, + "keys" : [ + [ 0.1, "linear", 1.0 ], + [ 0.3, "easeOutBounce", 2.0 ], + [ 0.8, "linear", 2.0 ], + [ 1.0, "linear", 1.0 ] + ] + } + ] + } +]