Debian Codegraph @

doc/reference/migrating-ClutterEffect.xml

raw
1 <?xml version="1.0"?>
2 <!DOCTYPE chapter PUBLIC
3 "-//OASIS//DTD DocBook XML V4.3//EN"
4 "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
5 ]>
6 <chapter id="migrating-ClutterEffect">
7
8 <chapterinfo>
9 <author>
10 <firstname>Emmanuele</firstname>
11 <surname>Bassi</surname>
12 <affiliation>
13 <address>
14 <email>[email protected]</email>
15 </address>
16 </affiliation>
17 </author>
18 </chapterinfo>
19
20 <title>Migrating from ClutterEffect</title>
21
22 <para>Since version 1.0, Clutter provides the #ClutterAnimation API
23 and the clutter_actor_animate() family of functions as replacements
24 for the <structname>ClutterEffectTemplate</structname> and
25 clutter_effect_* API for creating simple, one-off animations.</para>
26
27 <section id="using-actor-animate">
28 <title>Using <function>clutter_actor_animate()</function></title>
29
30 <para>Prior to Clutter 1.0, the way to create simple, one-off
31 animations involving a single actor was the ClutterEffect API. The
32 major downside of this API was that to abstract the duration and
33 easing function of the animation the application developer had to
34 create a <structname>ClutterEffectTemplate</structname> and keep it
35 around for the duration of the application.</para>
36
37 <para>The clutter_actor_animate() function performs all of the
38 memory management that was delegated to the
39 <structname>ClutterEffectTemplate</structname>, freeing the developer
40 from having to deal with object bookkeeping.</para>
41
42 <para>Another downside of the ClutterEffect API is that every
43 possible animation has its own function (scaling, opacity, rotation,
44 movement, etc.), and new functions cannot be added outside of
45 Clutter.</para>
46
47 <example id="example-clutter-effect">
48 <title>Effect example</title>
49 <para>The following code shows a simple animation using
50 the ClutterEffect API. It animates an actor linearly in 500
51 milliseconds, by moving it to the (100, 100) coordinates
52 while fading it out.</para>
53 <programlisting>
54 ClutterEffectTemplate *tmpl;
55
56 tmpl = clutter_effect_template_new_for_duration (500, clutter_ramp_inc_func);
57 clutter_effect_move (tmpl, actor, 100, 100, NULL, NULL);
58 clutter_effect_fade (tmpl, actor, 0, NULL, NULL);
59
60 g_object_unref (tmpl);
61 </programlisting>
62 </example>
63
64 <para>The clutter_actor_animate() function will implicitely
65 create a #ClutterAnimation with the passed duration and easing
66 mode, and will bind all the passed properties. All readable and
67 writable properties specified by a #ClutterActor are animatable
68 through clutter_actor_animate().</para>
69
70 <example id="example-actor-animate">
71 <title>Animation example</title>
72 <para>The following code shows the clutter_actor_animate() call
73 equivalent to the previous ClutterEffect example.</para>
74 <programlisting>
75 clutter_actor_animate (actor, CLUTTER_LINEAR, 500,
76 "x", 100.0,
77 "y", 100.0,
78 "opacity", 0,
79 NULL);
80 </programlisting>
81 </example>
82
83 <para>The ClutterEffect API provided a way to be notified of the
84 effect completion. Since the clutter_actor_animate() function creates
85 a #ClutterAnimation instance it's possible to use the
86 #ClutterAnimation::completed signal for the same notification.</para>
87
88 <example id="example-clutter-effect-complete">
89 <title>Effect complete example</title>
90 <para>The following code shows how to receive notification of the
91 completion of the animation.</para>
92 <programlisting>
93 static void
94 on_fade_complete (ClutterActor *actor,
95 gpointer data)
96 {
97 clutter_actor_hide (actor);
98 }
99
100 ClutterEffectTemplate *tmpl;
101
102 tmpl = clutter_effect_template_new_for_duration (500, clutter_ramp_inc_func);
103 clutter_effect_fade (tmpl, actor, 0, on_fade_complete, NULL);
104
105 g_object_unref (tmpl);
106 </programlisting>
107 </example>
108
109 <para>The clutter_actor_animate() function also has a convenience
110 wrapper that allows to inline the signal connection:</para>
111
112 <example id="example-actor-animate-complete">
113 <title>Animation completed example</title>
114 <para>The following code shows how to get the same notification
115 as the example above.</para>
116 <programlisting>
117 ClutterAnimation *animation;
118
119 animation = clutter_actor_animate (actor, CLUTTER_LINEAR, 500,
120 "opacity", 0,
121 NULL);
122 g_signal_connect_swapped (animation,
123 "completed", G_CALLBACK (clutter_actor_hide),
124 actor);
125
126 /* OR */
127
128 clutter_actor_animate (actor, CLUTTER_LINEAR, 500,
129 "opacity", 0,
130 "signal-swapped::completed", clutter_actor_hide, actor,
131 NULL);
132 </programlisting>
133 </example>
134
135 </section>
136
137 </chapter>