cookbook: Added recipe for fading actors in/out
authorElliot Smith <elliot.smith@intel.com>
Fri, 16 Jul 2010 11:34:44 +0000 (12:34 +0100)
committerElliot Smith <elliot.smith@intel.com>
Fri, 16 Jul 2010 11:44:39 +0000 (12:44 +0100)
Added a recipe showing how to fade actors in/out by
animating their opacity property, using both implicit
animations and ClutterState.

doc/cookbook/Makefile.am
doc/cookbook/animations.xml
doc/cookbook/videos/animations-fading-in-then-out.ogv [new file with mode: 0644]
doc/cookbook/videos/animations-fading-out.ogv [new file with mode: 0644]

index 30f98d6..e294609 100644 (file)
@@ -28,6 +28,10 @@ XSL_XHTML_URI = $(XSL_BASE_URI)/xhtml/docbook.xsl
 HTML_FILES = html/*.html
 CSS_FILES = html/*.css
 IMAGE_FILES = images/clutter-logo.png
+VIDEO_FILES = \
+       videos/animations-fading-out.ogv \
+       videos/animations-fading-in-then-out.ogv \
+       $(NULL)
 
 EXTRA_DIST = clutter-cookbook.xml.in $(IMAGE_FILES) $(XML_FILES)
 
index 17741f9..adc65e7 100644 (file)
@@ -88,7 +88,7 @@
       </itemizedlist>
     </section>
 
-    <section>
+    <section id="animations-introduction-alphas">
       <title>Alphas</title>
 
       <para>An alpha is generated for each frame of the animation.
@@ -379,4 +379,130 @@ _on_click_cb (ClutterActor *actor,
 
   </section>
 
+  <section id="animations-fading">
+    <title>Fading an actor out of or into view</title>
+
+    <section>
+      <title>Problem</title>
+
+      <para>You want to animate an actor so that it fades out of or into
+      view.</para>
+    </section>
+
+    <section>
+      <title>Solution</title>
+
+      <para>Animate the actor's opacity property.</para>
+
+      <para>You can do this using any of the three approaches provided
+      by the animation API. Here's how to fade out an actor (until it's
+      completely transparent) using implicit animations:</para>
+
+      <informalexample>
+        <programlisting>
+<![CDATA[
+/* fade out actor over 4000 milliseconds */
+clutter_actor_animate (actor,
+                       CLUTTER_EASE_OUT_CUBIC,
+                       4000,
+                       "opacity", 0,
+                       NULL);
+]]>
+        </programlisting>
+      </informalexample>
+
+      <para>Here's an example of a rectangle fading out using this
+      animation:</para>
+
+      <inlinemediaobject>
+        <videoobject>
+          <videodata fileref="videos/animations-fading-out.ogv"/>
+        </videoobject>
+        <alt>
+          <para>Video showing an actor fading out using implicit
+          animations</para>
+        </alt>
+      </inlinemediaobject>
+
+      <para><constant>CLUTTER_EASE_OUT_CUBIC</constant> is one of the
+      Clutter easing modes; see
+      <link linkend="animations-introduction-alphas">the introduction</link>
+      for more details about what these are and how to choose one.</para>
+
+      <para>Here's an example of the transitions you could use to
+      fade an actor in and out using <type>ClutterState</type>:</para>
+
+      <informalexample>
+        <programlisting>
+<![CDATA[
+ClutterState *transitions = clutter_state_new ();
+
+/* all transitions last for 2000 milliseconds */
+clutter_state_set_duration (transitions, NULL, NULL, 2000);
+
+/* transition from any state to "fade-out" state */
+clutter_state_set (transitions,
+                   NULL,        /* from state (NULL means "any") */
+                   "fade-out",  /* to state */
+                   actor, "opacity", CLUTTER_EASE_OUT_QUAD, 0,
+                   NULL);
+
+/* transition from any state to "fade-in" state */
+clutter_state_set (transitions, NULL, "fade-in",
+                   actor, "opacity", CLUTTER_EASE_OUT_QUAD, 255,
+                   NULL);
+
+/* put the actor into the "fade-out" state with no animation */
+clutter_state_warp_to_state (transitions, "fade-out");
+]]>
+        </programlisting>
+      </informalexample>
+
+      <para>You would then trigger an animated state change as events
+      occur in the application (e.g. mouse button clicks):</para>
+
+      <informalexample>
+        <programlisting>
+<![CDATA[
+clutter_state_set_state (transitions, "fade-in");
+]]>
+        </programlisting>
+      </informalexample>
+
+      <para>Here's an example of this animation fading in then out again:</para>
+
+      <inlinemediaobject>
+        <videoobject>
+          <videodata fileref="videos/animations-fading-in-then-out.ogv"/>
+        </videoobject>
+        <alt>
+          <para>Video showing an actor fading in then out using
+          <type>ClutterState</type></para>
+        </alt>
+      </inlinemediaobject>
+
+      <note>
+        <para><type>ClutterState</type> is most useful where you
+        need to animate an actor backwards and forwards between multiple
+        states (e.g. fade an actor in and out of view). Where you just
+        want to fade an actor in or out once,
+        <function>clutter_actor_animate()</function> is adequate.</para>
+      </note>
+
+    </section>
+
+    <section>
+      <title>Discussion</title>
+
+      <para>Reducing an actor's transparency to zero does not make it
+      inactive: the actor will still be reactive even if it's not
+      visible (responding to key events, mouse clicks etc.).
+      To make it really "disappear", you could use
+      <function>clutter_actor_hide()</function> once you'd made the actor
+      fully transparent.</para>
+
+    </section>
+
+  </section>
+
 </chapter>
diff --git a/doc/cookbook/videos/animations-fading-in-then-out.ogv b/doc/cookbook/videos/animations-fading-in-then-out.ogv
new file mode 100644 (file)
index 0000000..e8fdc75
Binary files /dev/null and b/doc/cookbook/videos/animations-fading-in-then-out.ogv differ
diff --git a/doc/cookbook/videos/animations-fading-out.ogv b/doc/cookbook/videos/animations-fading-out.ogv
new file mode 100644 (file)
index 0000000..93628ff
Binary files /dev/null and b/doc/cookbook/videos/animations-fading-out.ogv differ