From 82ab00930b63d3860f96ac99da9cdc8128de1aee Mon Sep 17 00:00:00 2001 From: Elliot Smith Date: Thu, 9 Sep 2010 12:02:02 +0100 Subject: [PATCH] cookbook: Simplified and clarified example code Modified the "animation reuse" sample code to provide a simpler example to explain in the recipe. Also modified variable names to mirror the names used for the previous "complex animation" example and added some more comments, to further simplify and support the recipe. --- .../examples/animations-reuse-animation.json | 36 ++++-------------- .../examples/animations-reuse-ui.json | 37 ++++++++++++++++--- doc/cookbook/examples/animations-reuse.c | 20 ++++++++-- 3 files changed, 56 insertions(+), 37 deletions(-) diff --git a/doc/cookbook/examples/animations-reuse-animation.json b/doc/cookbook/examples/animations-reuse-animation.json index 7561bd557..5f16e1ee9 100644 --- a/doc/cookbook/examples/animations-reuse-animation.json +++ b/doc/cookbook/examples/animations-reuse-animation.json @@ -6,11 +6,8 @@ { "type" : "ClutterAnimator", - "id" : "bounce", - "timeline" : { - "type" : "ClutterTimeline", - "duration" : 2500 - }, + "id" : "animator", + "duration" : 2000, "properties" : [ { @@ -18,21 +15,8 @@ "name" : "x", "ease-in" : true, "keys" : [ - [ 0.2, "easeOutCubic", 100.0 ], - [ 0.6, "easeOutCubic", 150.0 ], - [ 0.8, "linear", 350.0 ], - [ 1.0, "linear", 500.0 ] - ] - }, - { - "object" : "rig", - "name" : "y", - "ease-in" : true, - "keys" : [ - [ 0.2, "easeOutCubic", 200.0 ], - [ 0.6, "easeOutBounce", 200.0 ], - [ 0.8, "linear", 200.0 ], - [ 1.0, "linear", 0.0 ] + [ 0.0, "linear", 0.0 ], + [ 1.0, "easeOutCubic", 150.0 ] ] }, { @@ -40,10 +24,8 @@ "name" : "scale-x", "ease-in" : true, "keys" : [ - [ 0.2, "easeOutElastic", 2.0 ], - [ 0.6, "easeOutBounce", 4.0 ], - [ 0.8, "linear", 4.0 ], - [ 1.0, "linear", 1.0 ] + [ 0.5, "linear", 1.0 ], + [ 1.0, "easeOutBack", 2.0 ] ] }, { @@ -51,10 +33,8 @@ "name" : "scale-y", "ease-in" : true, "keys" : [ - [ 0.2, "easeOutElastic", 2.0 ], - [ 0.6, "easeOutBounce", 4.0 ], - [ 0.8, "linear", 4.0 ], - [ 1.0, "linear", 1.0 ] + [ 0.5, "linear", 1.0 ], + [ 1.0, "easeOutBack", 2.0 ] ] } ] diff --git a/doc/cookbook/examples/animations-reuse-ui.json b/doc/cookbook/examples/animations-reuse-ui.json index 0b9e24087..99f50c616 100644 --- a/doc/cookbook/examples/animations-reuse-ui.json +++ b/doc/cookbook/examples/animations-reuse-ui.json @@ -2,8 +2,8 @@ { "type" : "ClutterStage", "id" : "stage", - "width" : 550, - "height" : 400, + "width" : 300, + "height" : 200, "color" : "#333355ff", "signals" : [ @@ -11,13 +11,13 @@ ], "children" : [ - { "type" : "ClutterRectangle", "id" : "rect1", - "color" : "red", + "color" : "white", "width" : 50, "height" : 50, + "y" : 50, "reactive" : true, "signals" : [ { "name" : "button-press-event", "handler" : "foo_button_pressed_cb" } @@ -30,6 +30,7 @@ "color" : "blue", "width" : 50, "height" : 50, + "y" : 50, "reactive" : true, "signals" : [ { "name" : "button-press-event", "handler" : "foo_button_pressed_cb" } @@ -42,12 +43,38 @@ "color" : "green", "width" : 50, "height" : 50, + "y" : 50, + "reactive" : true, + "signals" : [ + { "name" : "button-press-event", "handler" : "foo_button_pressed_cb" } + ] + }, + + { + "type" : "ClutterRectangle", + "id" : "rect4", + "color" : "red", + "width" : 50, + "height" : 50, + "y" : 50, + "reactive" : true, + "signals" : [ + { "name" : "button-press-event", "handler" : "foo_button_pressed_cb" } + ] + }, + + { + "type" : "ClutterRectangle", + "id" : "rect5", + "color" : "grey", + "width" : 50, + "height" : 50, + "y" : 50, "reactive" : true, "signals" : [ { "name" : "button-press-event", "handler" : "foo_button_pressed_cb" } ] } - ] } ] diff --git a/doc/cookbook/examples/animations-reuse.c b/doc/cookbook/examples/animations-reuse.c index ee58020bc..506435a21 100644 --- a/doc/cookbook/examples/animations-reuse.c +++ b/doc/cookbook/examples/animations-reuse.c @@ -32,18 +32,20 @@ foo_button_pressed_cb (ClutterActor *actor, ClutterScript *script; ClutterActor *rig; - ClutterAnimator *bounce; + ClutterAnimator *animator; + /* load the rig and its animator from a JSON file */ script = clutter_script_new (); + /* use a function defined statically in this source file to load the JSON */ load_script_from_file (script, ANIMATION_FILE); clutter_script_get_objects (script, "rig", &rig, - "bounce", &bounce, + "animator", &animator, NULL); - /* remove the button press handler */ + /* remove the button press handler from the rectangle */ g_signal_handlers_disconnect_matched (actor, G_SIGNAL_MATCH_FUNC, 0, @@ -55,11 +57,21 @@ foo_button_pressed_cb (ClutterActor *actor, /* add a callback to clean up the script when the rig is destroyed */ g_object_set_data_full (G_OBJECT (rig), "script", script, g_object_unref); + /* add the rig to the stage */ clutter_container_add_actor (CLUTTER_CONTAINER (stage), rig); + /* place the rig at the same coordinates on the stage as the rectangle */ + clutter_actor_set_position (rig, + clutter_actor_get_x (actor), + clutter_actor_get_y (actor)); + + /* put the rectangle into the top-left corner of the rig */ clutter_actor_reparent (actor, rig); - clutter_animator_start (bounce); + clutter_actor_set_position (actor, 0, 0); + + /* animate the rig */ + clutter_animator_start (animator); return TRUE; }