update to 1.10.4
[profile/ivi/clutter.git] / doc / reference / clutter / html / clutter-animations.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <title>Creating Animations with Clutter</title>
6 <meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
7 <link rel="home" href="index.html" title="Clutter Reference Manual">
8 <link rel="up" href="additionaldocs.html" title="Part VIII. Additional Documentation">
9 <link rel="prev" href="additionaldocs.html" title="Part VIII. Additional Documentation">
10 <link rel="next" href="clutter-animation-timelines.html" title="Timelines">
11 <meta name="generator" content="GTK-Doc V1.18.1 (XML mode)">
12 <link rel="stylesheet" href="style.css" type="text/css">
13 </head>
14 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
15 <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle">
16 <td><a accesskey="p" href="additionaldocs.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
17 <td><a accesskey="u" href="additionaldocs.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
18 <td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
19 <th width="100%" align="center">Clutter Reference Manual</th>
20 <td><a accesskey="n" href="clutter-animation-timelines.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
21 </tr></table>
22 <div class="chapter">
23 <div class="titlepage"><div>
24 <div><h2 class="title">
25 <a name="clutter-animations"></a>Creating Animations with Clutter</h2></div>
26 <div><div class="author">
27 <h3 class="author">
28 <span class="firstname">Matthew</span> <span class="surname">Allum</span>
29 </h3>
30 <div class="affiliation"><div class="address"><p><br>
31           <code class="email">&lt;<a class="email" href="mailto:mallumopenedhand.com">mallum<em class="parameter"><code>openedhand.com</code></em></a>&gt;</code><br>
32         </p></div></div>
33 </div></div>
34 <div><div class="author">
35 <h3 class="author">
36 <span class="firstname">Emmanuele</span> <span class="surname">Bassi</span>
37 </h3>
38 <div class="affiliation"><div class="address"><p><br>
39           <code class="email">&lt;<a class="email" href="mailto:ebassilinux.intel.com">ebassi<em class="parameter"><code>linux.intel.com</code></em></a>&gt;</code><br>
40         </p></div></div>
41 </div></div>
42 </div></div>
43 <div class="toc"><dl>
44 <dt><span class="section"><a href="clutter-animations.html#clutter-animation-basic">Basic Animations</a></span></dt>
45 <dt><span class="section"><a href="clutter-animation-timelines.html">Timelines</a></span></dt>
46 <dt><span class="section"><a href="clutter-animation-implicit.html">Implicit Animations</a></span></dt>
47 <dt><span class="section"><a href="clutter-animation-conclusion.html">Conclusion</a></span></dt>
48 </dl></div>
49 <p>With Clutter using hardware accelration for graphics rendering,
50   complex and fast animations are possible. This chapter describes basic
51   techniques and the utilities Clutter provides in aiding animation
52   creation.</p>
53 <div class="section">
54 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
55 <a name="clutter-animation-basic"></a>Basic Animations</h2></div></div></div>
56 <p>The most basic way to create animations with Clutter is via the use
57     of <a class="link" href="clutter-General.html#clutter-threads-add-timeout" title="clutter_threads_add_timeout ()"><code class="function">clutter_threads_add_timeout()</code></a>. This enables a callback function to be
58     called at a defined interval. The callback function can then modify actors
59     visual properties as to produce an animation.</p>
60 <div class="example">
61 <a name="clutter-timeout-example"></a><p class="title"><b>Example 18. Simple timeout example</b></p>
62 <div class="example-contents">
63 <p>Implement a rotating actor using 360 "frames"</p>
64 <pre class="programlisting">
65 struct RotationClosure {
66   ClutterActor *actor;
67
68   gdouble final_angle;
69   gdouble current_angle;
70 };
71
72 static gboolean
73 rotate_actor (gpointer data)
74 {
75   struct RotationClosure *clos = data;
76
77   clutter_actor_set_rotation (clos-&gt;actor, clos-&gt;current_angle, 0, 0, 0);
78
79   /* add one degree */
80   clos-&gt;current_angle += 1.0
81
82   /* if we reached the target angle, stop */
83   if (clos-&gt;current_angle == clos-&gt;final_angle)
84     return G_SOURCE_REMOVE;
85
86   return G_SOURCE_CONTINUE;
87 }
88
89 static void
90 rotate_actor_cleanup (gpointer data)
91 {
92   struct RotationClosure *clos = data;
93
94   g_object_unref (clos-&gt;actor);
95   g_free (clos);
96 }
97
98 ...
99   struct RotationClosure *clos = NULL;
100
101   clos = g_new (struct RotationClosure, 1);
102   clos-&gt;actor = g_object_ref (an_actor);
103   clos-&gt;final_angle = 360.0;
104   clos-&gt;current_angle = 0;
105
106   clutter_threads_add_timeout_full (G_PRIORITY_DEFAULT,
107                                     1000 / 360, /* 360 updates in one second */
108                                     rotate_actor,
109                                     clos,
110                                     rotate_actor_cleanup);
111       </pre>
112 </div>
113 </div>
114 <br class="example-break"><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
115 <h3 class="title">Priorities</h3>
116 <p><a href="../glib/glib-The-Main-Event-Loop.html#G-PRIORITY-DEFAULT:CAPS"><code class="literal">G_PRIORITY_DEFAULT</code></a> should always be used as the timeouts priority
117       (in case of <a class="link" href="clutter-General.html#clutter-threads-add-timeout-full" title="clutter_threads_add_timeout_full ()"><code class="function">clutter_threads_add_timeout_full()</code></a>) as not to intefere with
118       Clutter's scheduling of repaints and input event handling.</p>
119 </div>
120 </div>
121 </div>
122 <div class="footer">
123 <hr>
124           Generated by GTK-Doc V1.18.1</div>
125 </body>
126 </html>