File: migrating-ClutterEffect.xml

package info (click to toggle)
clutter-1.0 1.26.4%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 34,352 kB
  • sloc: ansic: 128,533; sh: 5,580; xml: 1,641; makefile: 1,613; ruby: 149; perl: 142; sed: 16
file content (137 lines) | stat: -rw-r--r-- 5,013 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?xml version="1.0"?>
<!DOCTYPE chapter PUBLIC
  "-//OASIS//DTD DocBook XML V4.3//EN"
  "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
]>
<chapter id="migrating-ClutterEffect">

  <chapterinfo>
    <author>
      <firstname>Emmanuele</firstname>
      <surname>Bassi</surname>
      <affiliation>
        <address>
          <email>ebassi@linux.intel.com</email>
        </address>
      </affiliation>
    </author>
  </chapterinfo>

  <title>Migrating from ClutterEffect</title>

  <para>Since version 1.0, Clutter provides the #ClutterAnimation API
  and the clutter_actor_animate() family of functions as replacements
  for the <structname>ClutterEffectTemplate</structname> and
  clutter_effect_* API for creating simple, one-off animations.</para>

  <section id="using-actor-animate">
    <title>Using <function>clutter_actor_animate()</function></title>

    <para>Prior to Clutter 1.0, the way to create simple, one-off
    animations involving a single actor was the ClutterEffect API. The
    major downside of this API was that to abstract the duration and
    easing function of the animation the application developer had to
    create a <structname>ClutterEffectTemplate</structname> and keep it
    around for the duration of the application.</para>

    <para>The clutter_actor_animate() function performs all of the
    memory management that was delegated to the
    <structname>ClutterEffectTemplate</structname>, freeing the developer
    from having to deal with object bookkeeping.</para>

    <para>Another downside of the ClutterEffect API is that every
    possible animation has its own function (scaling, opacity, rotation,
    movement, etc.), and new functions cannot be added outside of
    Clutter.</para>

    <example id="example-clutter-effect">
      <title>Effect example</title>
      <para>The following code shows a simple animation using
      the ClutterEffect API. It animates an actor linearly in 500
      milliseconds, by moving it to the (100, 100) coordinates
      while fading it out.</para>
      <programlisting>
  ClutterEffectTemplate *tmpl;

  tmpl = clutter_effect_template_new_for_duration (500, clutter_ramp_inc_func);
  clutter_effect_move (tmpl, actor, 100, 100, NULL, NULL);
  clutter_effect_fade (tmpl, actor, 0, NULL, NULL);

  g_object_unref (tmpl);
      </programlisting>
    </example>

    <para>The clutter_actor_animate() function will implicitely
    create a #ClutterAnimation with the passed duration and easing
    mode, and will bind all the passed properties. All readable and
    writable properties specified by a #ClutterActor are animatable
    through clutter_actor_animate().</para>

    <example id="example-actor-animate">
      <title>Animation example</title>
      <para>The following code shows the clutter_actor_animate() call
      equivalent to the previous ClutterEffect example.</para>
      <programlisting>
  clutter_actor_animate (actor, CLUTTER_LINEAR, 500,
                         "x", 100.0,
                         "y", 100.0,
                         "opacity", 0,
                         NULL);
      </programlisting>
    </example>

    <para>The ClutterEffect API provided a way to be notified of the
    effect completion. Since the clutter_actor_animate() function creates
    a #ClutterAnimation instance it's possible to use the
    #ClutterAnimation::completed signal for the same notification.</para>

    <example id="example-clutter-effect-complete">
      <title>Effect complete example</title>
      <para>The following code shows how to receive notification of the
      completion of the animation.</para>
      <programlisting>
static void
on_fade_complete (ClutterActor *actor,
                  gpointer      data)
{
  clutter_actor_hide (actor);
}

  ClutterEffectTemplate *tmpl;

  tmpl = clutter_effect_template_new_for_duration (500, clutter_ramp_inc_func);
  clutter_effect_fade (tmpl, actor, 0, on_fade_complete, NULL);

  g_object_unref (tmpl);
      </programlisting>
    </example>

    <para>The clutter_actor_animate() function also has a convenience
    wrapper that allows to inline the signal connection:</para>

    <example id="example-actor-animate-complete">
      <title>Animation completed example</title>
      <para>The following code shows how to get the same notification
      as the example above.</para>
      <programlisting>
  ClutterAnimation *animation;

  animation = clutter_actor_animate (actor, CLUTTER_LINEAR, 500,
                                     "opacity", 0,
                                     NULL);
  g_signal_connect_swapped (animation,
                            "completed", G_CALLBACK (clutter_actor_hide),
                            actor);

  /* OR */

  clutter_actor_animate (actor, CLUTTER_LINEAR, 500,
                         "opacity", 0,
                         "signal-swapped::completed", clutter_actor_hide, actor,
                         NULL);
      </programlisting>
    </example>

  </section>

</chapter>