mirror of
https://github.com/brl/mutter.git
synced 2024-11-23 08:30:42 -05:00
Merge remote branch 'elliot/cookbook-animations-looping-new-api'
* elliot/cookbook-animations-looping-new-api: cookbook: Use new API to reverse timeline
This commit is contained in:
commit
b16ea09988
@ -2372,7 +2372,7 @@ clutter_actor_animate_with_timeline (actor,
|
||||
</programlisting>
|
||||
</informalexample>
|
||||
|
||||
<para>One further technique is to swop the timeline's
|
||||
<para>One further technique is to repeatedly reverse the timeline's
|
||||
direction to create a "closed loop" animation (one which returns
|
||||
to its origin at the end of each iteration). See
|
||||
<link linkend="animations-looping-discussion-closed-loop">this
|
||||
@ -2655,12 +2655,23 @@ timeline_completed_cb (ClutterTimeline *timeline,
|
||||
animations, one the inverse of the other, and chaining them together.</para>
|
||||
|
||||
<para>However, a simpler solution is to run forward through the timeline
|
||||
once; then invert its direction when the end of timeline is reached.
|
||||
The animation continues, but in reverse. Once the backward iteration
|
||||
completes, set the timeline to run forward again. Keep changing the
|
||||
timeline's direction each time it completes. This
|
||||
is the approach used in <link linkend="animations-looping-example-1">the
|
||||
example</link>, which results in a smooth, repeated right to left,
|
||||
once, and have the timeline invert itself when its end is reached.
|
||||
The animation then continues, but in reverse. Once the backward iteration
|
||||
completes, the timeline sets itself to run forward again, etc.</para>
|
||||
|
||||
<para>To make a timeline reverse its direction each time it
|
||||
completes, use the <function>clutter_timeline_set_reverse()</function>
|
||||
function:</para>
|
||||
|
||||
<informalexample>
|
||||
<programlisting>
|
||||
clutter_timeline_set_reverse (timeline, TRUE);
|
||||
</programlisting>
|
||||
</informalexample>
|
||||
|
||||
<para>This is the approach used in
|
||||
<link linkend="animations-looping-example-1">the example</link>,
|
||||
which results in a smooth, repeated right to left,
|
||||
left to right motion.</para>
|
||||
|
||||
<para>See <link linkend="animations-inversion">this
|
||||
|
@ -10,20 +10,6 @@ typedef struct
|
||||
ClutterTimeline *timeline;
|
||||
} State;
|
||||
|
||||
static void
|
||||
invert_timeline_cb (ClutterTimeline *timeline,
|
||||
gpointer user_data)
|
||||
{
|
||||
ClutterTimelineDirection direction = clutter_timeline_get_direction (timeline);
|
||||
|
||||
if (direction == CLUTTER_TIMELINE_FORWARD)
|
||||
direction = CLUTTER_TIMELINE_BACKWARD;
|
||||
else
|
||||
direction = CLUTTER_TIMELINE_FORWARD;
|
||||
|
||||
clutter_timeline_set_direction (timeline, direction);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
key_pressed_cb (ClutterActor *actor,
|
||||
ClutterEvent *event,
|
||||
@ -63,21 +49,13 @@ main (int argc,
|
||||
|
||||
state->timeline = clutter_timeline_new (1000);
|
||||
clutter_timeline_set_loop (state->timeline, TRUE);
|
||||
clutter_timeline_set_reverse (state->timeline, TRUE);
|
||||
|
||||
g_signal_connect (stage,
|
||||
"key-press-event",
|
||||
G_CALLBACK (key_pressed_cb),
|
||||
state);
|
||||
|
||||
/* the animation will not emit a "completed" signal,
|
||||
* as it is set to loop; but the timeline emits "completed"
|
||||
* at the end of each iteration of the loop
|
||||
*/
|
||||
g_signal_connect (state->timeline,
|
||||
"completed",
|
||||
G_CALLBACK (invert_timeline_cb),
|
||||
NULL);
|
||||
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), state->actor);
|
||||
|
||||
clutter_actor_show (stage);
|
||||
|
Loading…
Reference in New Issue
Block a user