| 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-ClutterAnimation"> |
| 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 ClutterAnimation</title> |
| 21 |
|
| 22 |
<para>The #ClutterAnimation class, along with the #ClutterActor wrappers |
| 23 |
clutter_actor_animate(), clutter_actor_animate_with_timeline() and |
| 24 |
clutter_actor_animate_with_alpha(), has been deprecated in Clutter 1.12, |
| 25 |
and should not be used in newly written code.</para> |
| 26 |
|
| 27 |
<para>The direct replacement for a #ClutterAnimation is the |
| 28 |
#ClutterPropertyTransition class, which allows the transition of a |
| 29 |
single #GObject property from an initial value to a final value over a |
| 30 |
user-defined time using a user-defined easing curve.</para> |
| 31 |
|
| 32 |
<para>The #ClutterPropertyTransition class inherits from #ClutterTransition, |
| 33 |
which allows setting the transition interval, as well as the animatable |
| 34 |
instance to be transitioned; and from #ClutterTimeline, which allows setting |
| 35 |
the duration and easing curve of the transition.</para> |
| 36 |
|
| 37 |
<para>For instance, the following #ClutterAnimation set up:</para> |
| 38 |
|
| 39 |
<informalexample><programlisting language="C"><![CDATA[ |
| 40 |
ClutterAnimation *animation = clutter_animation_new (); |
| 41 |
|
| 42 |
clutter_animation_set_mode (animation, CLUTTER_EASE_OUT_CUBIC); |
| 43 |
clutter_animation_set_duration (animation, 2500); |
| 44 |
|
| 45 |
/* object_to_animate is set elsewhere */ |
| 46 |
clutter_animation_set_object (animation, object_to_animate); |
| 47 |
|
| 48 |
ClutterInterval *interval = clutter_interval_new (G_TYPE_FLOAT, 0.0, 100.0); |
| 49 |
|
| 50 |
/* property_name is set elsewhere */ |
| 51 |
clutter_animation_bind_interval (animation, property_name, interval); |
| 52 |
|
| 53 |
ClutterTimeline *timeline = clutter_animation_get_timeline (animation); |
| 54 |
clutter_timeline_start (timeline); |
| 55 |
]]></programlisting></informalexample> |
| 56 |
|
| 57 |
<para>Can be replaced by #ClutterPropertyTransition:</para> |
| 58 |
|
| 59 |
<informalexample><programlisting language="C"><![CDATA[ |
| 60 |
ClutterTransition *transition = clutter_property_transition_new (property_name); |
| 61 |
|
| 62 |
clutter_timeline_set_progress_mode (CLUTTER_TIMELINE (transition), |
| 63 |
CLUTTER_EASE_OUT_CUBIC); |
| 64 |
clutter_timeline_set_duration (CLUTTER_TIMELINE (transition), 2000); |
| 65 |
|
| 66 |
clutter_transition_set_animatable (transition, object_to_animate); |
| 67 |
|
| 68 |
clutter_transition_set_from (transition, G_TYPE_FLOAT, 0.0); |
| 69 |
clutter_transition_set_to (transition, G_TYPE_FLOAT, 100.0); |
| 70 |
|
| 71 |
clutter_timeline_start (CLUTTER_TIMELINE (transition)); |
| 72 |
]]></programlisting></informalexample> |
| 73 |
|
| 74 |
<para>It is important to note that only #ClutterAnimatable implementations |
| 75 |
can be used directly with #ClutterTransition.</para> |
| 76 |
|
| 77 |
<para>A #ClutterPropertyTransition can only animate a single property; if |
| 78 |
more than one property transition is required, you can use the |
| 79 |
#ClutterTransitionGroup class to group the transitions together.</para> |
| 80 |
|
| 81 |
<section> |
| 82 |
<title>Migrating clutter_actor_animate()</title> |
| 83 |
|
| 84 |
<para>#ClutterActor animatable properties can use implicit transitions |
| 85 |
through their setter functions. The duration and easing curve of the |
| 86 |
animation is controlled by clutter_actor_set_easing_duration() and by |
| 87 |
clutter_actor_set_easing_mode(), respectively; for instance, the |
| 88 |
equivalent of the following clutter_actor_animate() call:</para> |
| 89 |
|
| 90 |
<informalexample><programlisting language="C"><![CDATA[ |
| 91 |
clutter_actor_animate (actor, CLUTTER_EASE_OUT_BOUNCE, 500, |
| 92 |
"x", new_x_position, |
| 93 |
"y", new_y_position, |
| 94 |
"opacity", 255, |
| 95 |
NULL); |
| 96 |
]]></programlisting></informalexample> |
| 97 |
|
| 98 |
<para>Can be replaced by the following:</para> |
| 99 |
|
| 100 |
<informalexample><programlisting language="C"><![CDATA[ |
| 101 |
clutter_actor_set_easing_mode (actor, CLUTTER_EASE_OUT_BOUNCE); |
| 102 |
clutter_actor_set_easing_duration (actor, 500); |
| 103 |
clutter_actor_set_position (actor, new_x_position, new_y_position); |
| 104 |
clutter_actor_set_opacity (actor, 255); |
| 105 |
]]></programlisting></informalexample> |
| 106 |
|
| 107 |
<para>The default easing duration for the 1.0 API series is set to 0, |
| 108 |
which means no transition at all.</para> |
| 109 |
|
| 110 |
<para>It is possible to set the easing state of a #ClutterActor to its |
| 111 |
default values by using clutter_actor_save_easing_state(), and return |
| 112 |
to the previous values by calling clutter_actor_restore_easing_state() |
| 113 |
instead. The easing state affects all the animatable properties that |
| 114 |
are modified after changing it; so, for instance:</para> |
| 115 |
|
| 116 |
<informalexample><programlisting language="C"><![CDATA[ |
| 117 |
clutter_actor_save_easing_state (actor); |
| 118 |
clutter_actor_set_easing_duration (actor, 500); |
| 119 |
clutter_actor_set_opacity (actor, 255); |
| 120 |
|
| 121 |
clutter_actor_save_easing_state (actor); |
| 122 |
clutter_actor_set_easing_delay (actor, 500); |
| 123 |
clutter_actor_set_easing_duration (actor, 500); |
| 124 |
clutter_actor_set_size (actor, width, height); |
| 125 |
clutter_actor_restore_easing_state (actor); |
| 126 |
|
| 127 |
clutter_actor_restore_easing_state (actor); |
| 128 |
]]></programlisting></informalexample> |
| 129 |
|
| 130 |
<para>The animation above will implicitly transition the opacity from |
| 131 |
its current value to 255 in 500 milliseconds using the default easing |
| 132 |
curve; at the same time, the size of the actor will be transitioned in |
| 133 |
500 milliseconds after a delay of 500 milliseconds to the new size |
| 134 |
stored in the variables <emphasis>width</emphasis> and |
| 135 |
<emphasis>height</emphasis>.</para> |
| 136 |
|
| 137 |
</section> |
| 138 |
|
| 139 |
</chapter> |