2007-07-26 10:00:20 -04:00
|
|
|
<chapter id="clutter-animations">
|
|
|
|
<chapterinfo>
|
|
|
|
<author>
|
|
|
|
<firstname>Matthew</firstname>
|
|
|
|
<surname>Allum</surname>
|
|
|
|
<affiliation>
|
|
|
|
<address>
|
|
|
|
<email>mallum@openedhand.com</email>
|
|
|
|
</address>
|
|
|
|
</affiliation>
|
|
|
|
</author>
|
|
|
|
</chapterinfo>
|
|
|
|
|
|
|
|
<title>Creating Animations with Clutter</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
|
2008-02-14 10:03:21 -05:00
|
|
|
With Clutter using hardware accelration for graphics rendering,
|
|
|
|
complex and fast animations are possible. This chapter describes basic
|
2008-02-15 06:27:34 -05:00
|
|
|
techniques and the utilities Clutter provides in aiding animation
|
2008-02-14 10:03:21 -05:00
|
|
|
creation.
|
|
|
|
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<section id="clutter-animation-basic">
|
|
|
|
<title>Basic Animations</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
|
|
|
|
The most basic way to create animations with Clutter is via the use of
|
2008-02-15 06:27:34 -05:00
|
|
|
g_timeout_add(). This enables a callback function to be called at a
|
|
|
|
defined interval. The callback function can then modify actors visual
|
|
|
|
properties as to produce an animation.
|
2008-02-14 10:03:21 -05:00
|
|
|
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<example id="clutter-timeout-example">
|
|
|
|
<para>
|
|
|
|
Simple Rotation...
|
|
|
|
</para>
|
|
|
|
<programlisting>
|
2008-02-15 06:27:34 -05:00
|
|
|
struct RotationClosure {
|
|
|
|
ClutterActor *actor;
|
|
|
|
ClutterFixed final_angle;
|
|
|
|
ClutterFixed current_angle;
|
|
|
|
};
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
rotate_actor (gpointer data)
|
|
|
|
{
|
|
|
|
RotationClosure *clos = data;
|
|
|
|
|
|
|
|
clutter_actor_set_rotationx (clos->actor, clos->current_angle, 0, 0, 0);
|
|
|
|
|
|
|
|
clos->current_angle += CFX_ONE;
|
2008-02-14 10:03:21 -05:00
|
|
|
|
2008-02-15 06:27:34 -05:00
|
|
|
if (clos->current_angle == clos->final_angle)
|
|
|
|
return FALSE;
|
2008-02-14 10:03:21 -05:00
|
|
|
|
2008-02-15 06:27:34 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
...
|
|
|
|
RotationClosure clos = { NULL, }
|
2008-02-14 10:03:21 -05:00
|
|
|
|
2008-02-15 06:27:34 -05:00
|
|
|
clos.actor = an_actor;
|
|
|
|
clos.final_angle = CLUTTER_FLOAT_TO_FIXED (360.0);
|
|
|
|
clos.current_angle = 0;
|
2008-02-14 10:03:21 -05:00
|
|
|
|
2008-02-15 06:27:34 -05:00
|
|
|
g_timeout_add (1000 / 360, /* fps to interval in milliseconds */
|
|
|
|
rotate_actor,
|
|
|
|
&clos);
|
2008-02-14 10:03:21 -05:00
|
|
|
</programlisting>
|
|
|
|
</example>
|
|
|
|
|
2008-02-15 06:27:34 -05:00
|
|
|
<note><title>Priorities</title>
|
2008-02-14 10:03:21 -05:00
|
|
|
<para>
|
|
|
|
|
2008-02-15 06:27:34 -05:00
|
|
|
%G_PRIORITY_DEFAULT should always be used as the timeouts priority
|
|
|
|
(in case of g_timeout_add_full()) as not to intefere with Clutter's
|
|
|
|
scheduling of repaints and input event handling.
|
2008-02-14 10:03:21 -05:00
|
|
|
|
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
|
|
|
|
</section>
|
|
|
|
<section id="clutter-animation-timelines">
|
|
|
|
<title>Timelines</title>
|
|
|
|
<para>
|
2008-02-15 10:50:21 -05:00
|
|
|
#ClutterTimeline<!-- -->s abstract a set period of time with a set frame
|
|
|
|
rate at which to call a provided callback.
|
2008-02-14 10:03:21 -05:00
|
|
|
</para>
|
2008-02-15 10:50:21 -05:00
|
|
|
|
2008-02-14 10:03:21 -05:00
|
|
|
<para>
|
2008-02-15 10:50:21 -05:00
|
|
|
#ClutterTimeline<!-- -->s also extend the timeout sources functionality
|
|
|
|
further by:
|
2008-02-14 10:03:21 -05:00
|
|
|
</para>
|
2008-02-15 10:50:21 -05:00
|
|
|
|
2008-02-14 10:03:21 -05:00
|
|
|
<orderedlist>
|
2008-02-15 10:50:21 -05:00
|
|
|
<listitem><para>Having a set duration (in milliseconds) and a set
|
|
|
|
'frame rate' - that is, the rate at which the callback is
|
|
|
|
called</para></listitem>
|
|
|
|
<listitem><para>Passing current progress information to the
|
|
|
|
callback</para></listitem>
|
|
|
|
<listitem><para>Handling 'dropped frames' and guarenteeing the set
|
|
|
|
duration by skipping over frames if the callback cannot keep up with
|
|
|
|
the set frame rate</para></listitem>
|
|
|
|
<listitem><para>Querying the number of milliseconds elapsed between
|
|
|
|
the current and previous callback.</para></listitem>
|
|
|
|
<listitem><para>Allowing the timeline to be modified on the fly as
|
|
|
|
well as being stopped, started, looped, rewound and
|
|
|
|
reversed</para></listitem>
|
|
|
|
<listitem><para>Using a #ClutterTimeoutPool to more efficiently
|
|
|
|
schedule multiple timeout sources without incurring in potential
|
|
|
|
starvation of the main loop slices</para></listitem>
|
2008-02-14 10:03:21 -05:00
|
|
|
</orderedlist>
|
2008-02-15 10:50:21 -05:00
|
|
|
|
2008-02-14 10:03:21 -05:00
|
|
|
<para>
|
|
|
|
A Timeline is created with;
|
|
|
|
</para>
|
2008-02-15 10:50:21 -05:00
|
|
|
|
2008-02-14 10:03:21 -05:00
|
|
|
<programlisting>
|
2008-02-15 10:50:21 -05:00
|
|
|
clutter_timeline_new (n_frames, frames_per_seconds);
|
2008-02-14 10:03:21 -05:00
|
|
|
</programlisting>
|
2008-02-15 10:50:21 -05:00
|
|
|
|
2008-02-14 10:03:21 -05:00
|
|
|
<para>
|
|
|
|
Taking a number of frames and a frames per second, or by;
|
|
|
|
</para>
|
2008-02-15 10:50:21 -05:00
|
|
|
|
2008-02-14 10:03:21 -05:00
|
|
|
<programlisting>
|
2008-02-15 10:50:21 -05:00
|
|
|
clutter_timeline_new_for_duration (msecs);
|
2008-02-14 10:03:21 -05:00
|
|
|
</programlisting>
|
|
|
|
|
2008-02-15 10:50:21 -05:00
|
|
|
<para>
|
2008-02-14 10:03:21 -05:00
|
|
|
Which takes the duration of the timeline in milliseconds with a
|
2008-02-15 10:50:21 -05:00
|
|
|
default frame rate (See clutter_get_default_frame_rate()).
|
2008-02-14 10:03:21 -05:00
|
|
|
</para>
|
2008-02-15 10:50:21 -05:00
|
|
|
|
2008-02-14 10:03:21 -05:00
|
|
|
<para>
|
|
|
|
|
|
|
|
The speed, duration and number of frames of the timeline then be
|
|
|
|
modifed via the objects properties and API calls. The timeline can
|
2008-02-15 10:50:21 -05:00
|
|
|
be made to loop by settings it "loop" property to %TRUE.
|
2008-02-14 10:03:21 -05:00
|
|
|
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
|
2008-02-15 10:50:21 -05:00
|
|
|
The timelines is started via clutter_timeline_start() and its
|
|
|
|
playback further manipulated by the clutter_timeline_pause(),
|
|
|
|
clutter_timeline_stop(), clutter_timeline_rewind() and
|
|
|
|
clutter_timeline_skip() calls.
|
2008-02-14 10:03:21 -05:00
|
|
|
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
|
2008-02-15 10:50:21 -05:00
|
|
|
By attaching a handler to the timeline's ClutterTimeline::new-frame
|
|
|
|
signal a timeline can then be used to drive an animation by altering
|
|
|
|
an actor's visual properties in this callback. The callback looks like:
|
2008-02-14 10:03:21 -05:00
|
|
|
|
|
|
|
</para>
|
|
|
|
<programlisting>
|
2008-02-15 10:50:21 -05:00
|
|
|
void
|
|
|
|
on_new_frame (ClutterTimeline *timeline,
|
|
|
|
gint frame_num,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2008-02-14 10:03:21 -05:00
|
|
|
|
2008-02-15 10:50:21 -05:00
|
|
|
}
|
2008-02-14 10:03:21 -05:00
|
|
|
</programlisting>
|
|
|
|
<para>
|
|
|
|
|
2008-02-15 10:50:21 -05:00
|
|
|
The <literal>frame_num</literal> parameter is set to the timeline's
|
|
|
|
current frame number (which is between 0 and the "num-frames" property).
|
|
|
|
This value can be used to compute the state of a particular animation
|
|
|
|
that is dependant on the frame numer. The clutter_timeline_get_progress()
|
|
|
|
function can also be used to get a normalised value of the timeline's
|
|
|
|
current position between 0 and 1.
|
2008-02-14 10:03:21 -05:00
|
|
|
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
|
2008-02-15 10:50:21 -05:00
|
|
|
Timelines can also be played in reverse by setting the direction using
|
|
|
|
clutter_timeline_set_direction(), and can also have a one-time delay set
|
|
|
|
before they begin playing by using clutter_timeline_set_delay().
|
2008-02-14 10:03:21 -05:00
|
|
|
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
|
2008-02-15 10:50:21 -05:00
|
|
|
Timelines can also control a pyshical simulation; the
|
|
|
|
clutter_timeline_get_delta() function allows retrieving the number of
|
|
|
|
frames and milliseconds elapsed since the previous callback to ensure
|
|
|
|
the physics engine to be able to take the actual time elapsed between
|
2008-02-14 10:03:21 -05:00
|
|
|
iterations into account.
|
|
|
|
|
2007-07-26 10:00:20 -04:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<example id="clutter-timeline-example">
|
|
|
|
<para>
|
|
|
|
The following example demonstrates rotating an actor with a timeline.
|
|
|
|
</para>
|
|
|
|
<programlisting>
|
|
|
|
#include <clutter/clutter.h>
|
|
|
|
|
|
|
|
void
|
|
|
|
on_new_frame (ClutterTimeline *timeline,
|
|
|
|
gint frame_num,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
ClutterActor *actor = CLUTTER_ACTOR(data);
|
|
|
|
|
2008-02-15 10:50:21 -05:00
|
|
|
clutter_actor_set_rotation (actor, CLUTTER_Z_AXIS,
|
|
|
|
(gdouble) frame_num,
|
|
|
|
clutter_actor_get_width (actor) / 2,
|
|
|
|
clutter_actor_get_height (actor) / 2,
|
|
|
|
0);
|
2007-07-26 10:00:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
ClutterTimeline *timeline;
|
|
|
|
|
|
|
|
ClutterActor *stage, *actor;
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
|
|
|
|
clutter_init (&argc, &argv);
|
|
|
|
|
|
|
|
stage = clutter_stage_get_default ();
|
|
|
|
|
|
|
|
pixbuf = gdk_pixbuf_new_from_file ("an-image.png", NULL);
|
|
|
|
|
|
|
|
actor = clutter_texture_new_from_pixbuf (pixbuf);
|
|
|
|
|
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), actor);
|
|
|
|
|
|
|
|
clutter_actor_set_position (actor, 100, 100);
|
|
|
|
|
2008-02-15 10:50:21 -05:00
|
|
|
timeline = clutter_timeline_new_for (360, 60); /* a degree per frame */
|
|
|
|
clutter_timeline_set_loop (timeline, TRUE);
|
2007-07-26 10:00:20 -04:00
|
|
|
|
|
|
|
g_signal_connect (timeline, "new-frame", G_CALLBACK (on_new_frame), actor);
|
|
|
|
|
|
|
|
clutter_actor_show_all (stage);
|
|
|
|
|
|
|
|
clutter_timeline_start (timeline);
|
|
|
|
|
|
|
|
clutter_main();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
</programlisting>
|
|
|
|
</example>
|
2008-02-14 10:03:21 -05:00
|
|
|
|
|
|
|
<note><para>
|
|
|
|
Multiple timelines can be sequenced in order by means of the
|
|
|
|
#ClutterScore. See the #ClutterScore documentation for more details on
|
|
|
|
using this.
|
|
|
|
</para></note>
|
|
|
|
|
|
|
|
</section>
|
|
|
|
<section id="clutter-animation-behaviours">
|
2008-02-15 06:27:34 -05:00
|
|
|
<title>Behaviours</title>
|
2007-07-26 10:00:20 -04:00
|
|
|
<para>
|
|
|
|
|
2008-02-14 10:03:21 -05:00
|
|
|
With a large application containing many animations, the use of just
|
|
|
|
timelines can become unweldy and difficult to manage with much code
|
|
|
|
duplication in the new-frame handlers that can require over complex
|
|
|
|
code changes for minor animation modifications. To ease these
|
|
|
|
problems the #ClutterAlpha and #ClutterBehaviour classes were created.
|
2007-07-26 10:00:20 -04:00
|
|
|
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
|
2008-02-14 10:03:21 -05:00
|
|
|
#ClutterAlpha and #ClutterBehaviour attempt to generalise the
|
|
|
|
new-frame function by defining common actions or behaviours that can
|
|
|
|
be quickly modified, applied to multiple actors or mixed on a single
|
|
|
|
actor.
|
2007-07-26 10:00:20 -04:00
|
|
|
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
|
2008-02-14 10:03:21 -05:00
|
|
|
A ClutterAlpha is simply a 'function of time' (not pixel alpha!). It
|
|
|
|
is created by referencing a source timeline and a function which
|
|
|
|
produces a value between 0 and %CLUTTER_ALPHA_MAX dependant on the
|
|
|
|
timeline position. Various prebuilt alpha functions are included
|
|
|
|
with Clutter these include
|
2007-07-26 10:00:20 -04:00
|
|
|
|
|
|
|
</para>
|
2008-02-14 10:03:21 -05:00
|
|
|
<para>
|
2007-07-26 10:00:20 -04:00
|
|
|
|
2008-02-15 10:50:21 -05:00
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term>%CLUTTER_ALPHA_RAMP_INC</term>
|
|
|
|
<listitem><simpara>Increasing ramp function</simpara></listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term>%CLUTTER_ALPHA_RAMP_DEC</term>
|
|
|
|
<listitem><simpara>Decreasing ramp function</simpara></listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term>%CLUTTER_ALPHA_RAMP</term>
|
|
|
|
<listitem><simpara>Full ramp function</simpara></listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term>%CLUTTER_ALPHA_SINE_INC</term>
|
|
|
|
<listitem><simpara>Increasing sine function</simpara></listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term>%CLUTTER_ALPHA_SINE_DEC</term>
|
|
|
|
<listitem><simpara>Decreasing sine function</simpara></listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term>%CLUTTER_ALPHA_SINE_HALF</term>
|
|
|
|
<listitem><simpara>Half sine function</simpara></listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term>%CLUTTER_ALPHA_SINE</term>
|
|
|
|
<listitem><simpara>Full sine function</simpara></listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term>%CLUTTER_ALPHA_SQUARE</term>
|
|
|
|
<listitem><simpara>Square waveform ("step") function</simpara></listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term>%CLUTTER_ALPHA_SMOOTHSTEP_INC</term>
|
|
|
|
<listitem><simpara>Increasing smooth transition step
|
|
|
|
function</simpara></listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term>%CLUTTER_ALPHA_SMOOTHSTEP_DEC</term>
|
|
|
|
<listitem><simpara>Decreasing smooth transition step
|
|
|
|
function</simpara></listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term>%CLUTTER_ALPHA_EXP_INC</term>
|
|
|
|
<listitem><simpara>Increasing exponential function</simpara></listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term>%CLUTTER_ALPHA_EXP_DEC</term>
|
|
|
|
<listitem><simpara>Decreasing exponential function</simpara></listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
2008-02-14 10:03:21 -05:00
|
|
|
</para>
|
2007-07-26 10:00:20 -04:00
|
|
|
<para>
|
|
|
|
|
2008-02-14 10:03:21 -05:00
|
|
|
A Behaviour is created with a #ClutterAlpha and a set of limits for
|
|
|
|
whatever the behaviour modifys actor wise. The current #ClutterAlpha
|
|
|
|
value is then mapped to a value between these limits and this value
|
|
|
|
set on any applied actors. With the #ClutterAlpha's underlying
|
|
|
|
timeline playing the produced value will change and the behaviour
|
|
|
|
will animate the actor.
|
2007-07-26 10:00:20 -04:00
|
|
|
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
|
2008-02-14 10:03:21 -05:00
|
|
|
A #ClutterBehaviour is effectively 'driven' by a supplied #ClutterAlpha and
|
2007-07-26 10:00:20 -04:00
|
|
|
when then applied to an actor it will modify a visual property or
|
|
|
|
feature of the actor dependant on the Alpha's value. For example a
|
|
|
|
path based behaviour applied to an actor will alter its position
|
|
|
|
along the path dependant on the current alpha value over time. The
|
|
|
|
actual motion will depend on the chosen #ClutterAlphaFunc - a
|
|
|
|
#CLUTTER_ALPHA_RAMP_INC making it to move at constant speed along the
|
|
|
|
path, a #CLUTTER_ALPHA_SINE making it alternate from one end of the
|
|
|
|
path to the other with non constant speed.
|
|
|
|
|
2008-02-14 10:03:21 -05:00
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
|
|
|
|
Multiple behaviours can of course be applied to an actor as well as
|
|
|
|
a single behaviour being applied to multiple actors. The separation
|
|
|
|
of timelines, alphas and behaviours allows for a single timeline to
|
|
|
|
drive many behaviours each potentially using different alpha
|
|
|
|
functions. Behaviour parameters can also be changed on the fly.
|
|
|
|
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
|
|
|
|
<figure id="behaviour-path-alpha">
|
|
|
|
<title>Effects of alpha functions on a path</title>
|
|
|
|
<graphic fileref="path-alpha-func.png" format="PNG"/>
|
|
|
|
<blockquote>
|
|
|
|
The actors position between the path's end points directly correlates
|
|
|
|
to the #ClutterAlpha's current alpha value driving the behaviour. With
|
|
|
|
the #ClutterAlpha's function set to %CLUTTER_ALPHA_RAMP_INC the actor
|
|
|
|
will follow the path at a constant velocity, but when changing to
|
|
|
|
%CLUTTER_ALPHA_SINE_INC the actor initially accelerates before quickly
|
|
|
|
decelerating.
|
|
|
|
</blockquote>
|
|
|
|
</figure>
|
|
|
|
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
|
2008-02-15 10:50:21 -05:00
|
|
|
The behaviours included in Clutter are
|
2008-02-14 10:03:21 -05:00
|
|
|
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
|
2008-02-15 10:50:21 -05:00
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term>#ClutterBehaviourBspline</term>
|
|
|
|
<listitem><simpara>Moves actors along a B-spline path</simpara></listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term>#ClutterBehaviourDepth</term>
|
|
|
|
<listitem><simpara>Changes the depth of actors</simpara></listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term>#ClutterBehaviourEllipse</term>
|
|
|
|
<listitem><simpara>Moves actors along an ellipsis</simpara></listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term>#ClutterBehaviourOpacity</term>
|
|
|
|
<listitem><simpara>Changes the opacity of actors</simpara></listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term>#ClutterBehaviourPath</term>
|
|
|
|
<listitem><simpara>Moves actors along a path</simpara></listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term>#ClutterBehaviourRotate</term>
|
|
|
|
<listitem><simpara>Rotates actors along an axis</simpara></listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term>#ClutterBehaviourScale</term>
|
|
|
|
<listitem><simpara>Changes the scaling factors of
|
|
|
|
actors</simpara></listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
2008-02-14 10:03:21 -05:00
|
|
|
|
2007-07-26 10:00:20 -04:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<example id="clutter-timeline-example">
|
|
|
|
<para>
|
|
|
|
The following example demonstrates an ellipse behaviour in action.
|
|
|
|
</para>
|
|
|
|
<programlisting>
|
|
|
|
#include <clutter/clutter.h>
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
ClutterTimeline *timeline;
|
|
|
|
ClutterBehaviour *behave;
|
|
|
|
ClutterAlpha *alpha;
|
|
|
|
ClutterActor *stage, *actor;
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
|
|
|
|
clutter_init (&argc, &argv);
|
|
|
|
|
|
|
|
stage = clutter_stage_get_default ();
|
|
|
|
|
|
|
|
pixbuf = gdk_pixbuf_new_from_file ("ohpowers.png", NULL);
|
|
|
|
|
|
|
|
actor = clutter_texture_new_from_pixbuf (pixbuf);
|
|
|
|
|
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), actor);
|
|
|
|
|
2008-02-15 10:50:21 -05:00
|
|
|
timeline = clutter_timeline_new_for_duration (4000); /* milliseconds */
|
|
|
|
clutter_timeline_set_loop (timeline, TRUE);
|
2007-07-26 10:00:20 -04:00
|
|
|
|
2008-02-15 10:50:21 -05:00
|
|
|
/* Set an alpha func to power the behaviour */
|
2007-07-26 10:00:20 -04:00
|
|
|
alpha = clutter_alpha_new_full (timeline,
|
|
|
|
CLUTTER_ALPHA_SINE,
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
behave = clutter_behaviour_ellipse_new (alpha,
|
2008-02-15 10:50:21 -05:00
|
|
|
200, /* center x */
|
|
|
|
200, /* center y */
|
|
|
|
400, /* width */
|
|
|
|
300, /* height */
|
2007-10-28 18:01:25 -04:00
|
|
|
CLUTTER_ROTATE_CW, /* direction */
|
2008-02-15 10:50:21 -05:00
|
|
|
0.0, /* initial angle */
|
|
|
|
360.0); /* final angle */
|
2007-07-26 10:00:20 -04:00
|
|
|
|
|
|
|
clutter_behaviour_apply (behave, actor);
|
|
|
|
|
|
|
|
clutter_actor_show_all (stage);
|
|
|
|
|
|
|
|
clutter_timeline_start (timeline);
|
|
|
|
|
|
|
|
clutter_main();
|
|
|
|
|
2008-02-15 10:50:21 -05:00
|
|
|
/* clean up */
|
|
|
|
g_object_unref (behave);
|
|
|
|
g_object_unref (timeline);
|
|
|
|
|
2007-07-26 10:00:20 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
</programlisting>
|
|
|
|
</example>
|
2008-02-14 10:03:21 -05:00
|
|
|
|
|
|
|
<note>Behaviour parameters can be changed whilst a animation is running</note>
|
|
|
|
|
2008-02-15 10:50:21 -05:00
|
|
|
<para>
|
|
|
|
There can be many #ClutterAlpha's attached to a single timeline. There
|
|
|
|
can be many behaviours for a #ClutterAlpha. There can be many behaviours
|
|
|
|
applied to an actor. A #ClutterScore can be used to chain many behaviour
|
|
|
|
together.
|
2008-02-14 10:03:21 -05:00
|
|
|
</para>
|
|
|
|
|
2008-02-18 04:40:52 -05:00
|
|
|
<warning><para>Combining behaviours that effect the same actor properties
|
2008-02-15 10:50:21 -05:00
|
|
|
(i.e two separate paths) will cause unexpected results. The values
|
|
|
|
will not be merged in any way with essentially a the last applied
|
2008-02-18 04:40:52 -05:00
|
|
|
behaviour taking precedence.</para></warning>
|
2008-02-14 10:03:21 -05:00
|
|
|
|
2008-02-15 10:50:21 -05:00
|
|
|
<para>
|
|
|
|
Tips for implementing a new behaviour can be found <link
|
|
|
|
linkend="creating-your-own-behaviours">here</link>.
|
|
|
|
</para>
|
2008-02-14 10:03:21 -05:00
|
|
|
|
|
|
|
</section>
|
|
|
|
<section id="clutter-animation-effects">
|
|
|
|
<title>Effects</title>
|
|
|
|
|
2007-07-26 10:00:20 -04:00
|
|
|
<para>
|
2008-02-14 10:03:21 -05:00
|
|
|
|
2008-02-15 10:50:21 -05:00
|
|
|
Clutter effects API provide a simplified abstraction for firing simple
|
|
|
|
transitions from code. Clutter effects are created from a
|
|
|
|
#ClutterEffectTemplate which is an abstraction of a timeline and
|
|
|
|
an alpha function. An effect template can be created with:
|
2007-07-26 10:00:20 -04:00
|
|
|
|
2008-02-14 10:03:21 -05:00
|
|
|
</para>
|
|
|
|
<programlisting>
|
2008-02-15 10:50:21 -05:00
|
|
|
ClutterEffectTemplate *etemplate =
|
|
|
|
clutter_effect_template_new_for_duration (2000, CLUTTER_ALPHA_RAMP_INC);
|
2008-02-14 10:03:21 -05:00
|
|
|
</programlisting>
|
|
|
|
<para>
|
|
|
|
|
|
|
|
This will create an effect template lasting 2000 milliseconds (2
|
2008-02-15 10:50:21 -05:00
|
|
|
seconds) and use an alpha function of %CLUTTER_ALPHA_RAMP_INC, there
|
2008-02-14 10:03:21 -05:00
|
|
|
are other more advanced forms for creating effect templates from
|
|
|
|
existing timelines, as well as attaching a callback to be called
|
2008-02-15 10:50:21 -05:00
|
|
|
with user_data when the effect template is destroyed.
|
2007-07-26 10:00:20 -04:00
|
|
|
|
|
|
|
</para>
|
2008-02-14 10:03:21 -05:00
|
|
|
<para>
|
|
|
|
|
2008-02-15 10:50:21 -05:00
|
|
|
When we have an effect template we can create a temporary behaviour
|
2008-02-14 10:03:21 -05:00
|
|
|
animating an actor simply by issuing:
|
2007-07-26 10:00:20 -04:00
|
|
|
|
2008-02-14 10:03:21 -05:00
|
|
|
</para>
|
|
|
|
<programlisting>
|
2008-02-15 10:50:21 -05:00
|
|
|
clutter_effect_move (etemplate, actor, 23, 42, NULL, NULL);
|
2008-02-14 10:03:21 -05:00
|
|
|
</programlisting>
|
|
|
|
<para>
|
2008-02-15 10:50:21 -05:00
|
|
|
and the actor will move from its current position to the coordinates
|
|
|
|
(23, 42) in 2 seconds. Effects can also be stacked, so calling:
|
2008-02-14 10:03:21 -05:00
|
|
|
</para>
|
|
|
|
<programlisting>
|
2008-02-15 10:50:21 -05:00
|
|
|
clutter_effect_move (etemplate, actor, 23, 42, NULL, NULL);
|
|
|
|
clutter_effect_fade (etemplate, actor, 0, NULL, NULL);
|
2008-02-14 10:03:21 -05:00
|
|
|
</programlisting>
|
|
|
|
<para>
|
2008-02-15 10:50:21 -05:00
|
|
|
The actor will move and fade out at the same time.
|
2008-02-14 10:03:21 -05:00
|
|
|
</para>
|
2007-07-26 10:00:20 -04:00
|
|
|
<para>
|
|
|
|
|
2008-02-15 10:50:21 -05:00
|
|
|
Since effects return a #ClutterTimeline, you can stop an effect from
|
2008-02-14 10:03:21 -05:00
|
|
|
immediatly happening by calling clutter_timeline_stop () on the
|
2008-02-15 10:50:21 -05:00
|
|
|
returned timeline.
|
|
|
|
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
|
|
|
|
The timeline and all the effect infrastructure is unreferenced as soon
|
|
|
|
as the timeline emits the ClutterTimeline::completed signal.
|
2007-07-29 19:24:13 -04:00
|
|
|
|
|
|
|
</para>
|
2008-02-14 10:03:21 -05:00
|
|
|
</section>
|
2008-02-15 10:50:21 -05:00
|
|
|
|
2008-02-14 10:03:21 -05:00
|
|
|
<section id="clutter-animation-conclusion">
|
|
|
|
<title>Conclusion</title>
|
2007-07-29 19:24:13 -04:00
|
|
|
<para>
|
|
|
|
|
2008-02-14 10:03:21 -05:00
|
|
|
Clutter provides a number of utility classes to aid animations and
|
|
|
|
complex animations can be produced by combining the various features
|
|
|
|
provided.
|
2007-07-26 10:00:20 -04:00
|
|
|
|
|
|
|
</para>
|
2008-02-14 10:03:21 -05:00
|
|
|
<para>
|
|
|
|
|
|
|
|
Of course animations can be created outside of Clutter Utilities,
|
|
|
|
they are not expected to cover every kind of possible animation
|
|
|
|
scenario.
|
|
|
|
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
|
2008-02-15 10:50:21 -05:00
|
|
|
The animation functionality in Clutter is primarily suited to
|
|
|
|
building animations with a set or finite running time - i.e transitions
|
|
|
|
and the like. For animations involving variable input (such as touchscreen
|
|
|
|
handling) physical simulations may be more suited.
|
2008-02-14 10:03:21 -05:00
|
|
|
|
|
|
|
</para>
|
2007-07-26 10:00:20 -04:00
|
|
|
|
2008-02-14 10:03:21 -05:00
|
|
|
</section>
|
2007-07-26 10:00:20 -04:00
|
|
|
</chapter>
|