From ed27da6abe593c686b8c1fdae540cb44d777ead5 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 9 Mar 2011 12:05:34 +0000 Subject: [PATCH] docs: Add an ClutterState definition section ClutterState is missing some documentation on how to define transitions using ClutterScript definitions; it is also missing some example code for both the C API and the ClutterScript syntax. --- clutter/clutter-state.c | 143 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) diff --git a/clutter/clutter-state.c b/clutter/clutter-state.c index 58c76b80f..fcb68d6fd 100644 --- a/clutter/clutter-state.c +++ b/clutter/clutter-state.c @@ -30,6 +30,149 @@ * define how the properties are animated. If the source_state_name for a key * is NULL it is used for transition to the target state unless a specific key * exists for transitioning from the current state to the requested state. + * + * + * A ClutterState example + * The following example defines a "base" and a "hover" state in a + * #ClutterState instance. + * + * ClutterState *state = clutter_state_new (); + * ClutterColor color = { 0, }; + * + * /* transition from any state to the "base" state */ + * clutter_color_from_string (&color, "rgb(255, 0, 0)"); + * clutter_state_set (state, NULL, "base", + * actor, "color", CLUTTER_LINEAR, &color, + * actor, "scale-x", CLUTTER_EASE_IN_BOUNCE, 1.0, + * actor, "scale-y", CLUTTER_EASE_IN_BOUNCE, 1.0, + * NULL); + * + * /* transition from the "base" state to the "hover" state */ + * clutter_color_from_string (&color, "rgb(0, 0, 255)"); + * clutter_state_set (state, "base", "hover", + * actor, "color", CLUTTER_LINEAR, &color, + * actor, "scale-x", CLUTTER_EASE_OUT_BOUNCE, 1.7, + * actor, "scale-y", CLUTTER_EASE_OUT_BOUNCE, 1.7, + * NULL); + * + * /* the default duration of any transition */ + * clutter_state_set_duration (state, NULL, NULL, 500); + * + * /* set "base" as the initial state */ + * clutter_state_warp_to_state (state, "base"); + * + * The actor then uses the #ClutterState to animate through the + * two states using callbacks for the #ClutterActor::enter-event and + * #ClutterActor::leave-event signals. + * + * static gboolean + * on_enter (ClutterActor *actor, + * ClutterEvent *event, + * ClutterState *state) + * { + * clutter_state_set_state (state, "hover"); + * + * return TRUE; + * } + * + * static gboolean + * on_leave (ClutterActor *actor, + * ClutterEvent *event, + * ClutterState *state) + * { + * clutter_state_set_state (state, "base"); + * + * return TRUE; + * } + * + * + * + * + * ClutterState description for #ClutterScript + * #ClutterState defines a custom transitions + * property which allows describing the states. + * The transitions property has the following + * syntax: + * + * + * { + * "transitions" : [ + * { + * "source" : "<source-state>", + * "target" : "<target-state>", + * "duration" : <milliseconds>, + * "keys" : [ + * [ + * "<object-id>", + * "<property-name>", + * "<easing-mode>", + * "<final-value>", + * ], + * [ + * "<object-id>", + * "<property-name>", + * "<easing-mode>", + * "<final-value>", + * <pre-delay>, + * <post-delay> + * ], + * ... + * ] + * }, + * { + * "source" : "<source-state>", + * "target" : "<target-state>", + * "duration" : <milliseconds>, + * "animator" : "<animator-definition>" + * }, + * ... + * ] + * } + * + * + * Each element of the transitions array follows + * the same rules as clutter_state_set_key(). + * The source and target + * values control the source and target state of the transition. The + * key and animator are mutually + * exclusive. The pre-delay and + * post-delay values are optional. + * + * ClutterState definition + * The example below is a translation into a #ClutterScript + * definition of the code in the example + * above. + * + * { + * "id" : "button-state", + * "type" : "ClutterState", + * "duration" : 500, + * "transitions" : [ + * { + * "source" : "*", + * "target" : "base", + * "keys" : [ + * [ "button", "color", "linear", "rgb(255, 0, 0)" ], + * [ "button", "scale-x", "easeInBounce", 1.0 ], + * [ "button", "scale-y", "easeInBounce", 1.0 ] + * ] + * }, + * { + * "source" : "base", + * "target" : "hover", + * "keys" : [ + * [ "button", "color", "linear", "rgb(0, 0, 255)" ], + * [ "button", "scale-x", "easeOutBounce", 1.7 ], + * [ "button", "scale-y", "easeOutBounce", 1.7 ] + * ] + * } + * ] + * } + * + * + * + * + * #ClutterState is available since Clutter 1.4. */ #ifdef HAVE_CONFIG_H