[clutter-tutorial] Adapted examples to latest clutter (0.9.3)



commit 98547438ffbae3561f85e55c543dade70997a7be
Author: Johannes Schmid <jhs gnome org>
Date:   Thu Apr 16 12:06:33 2009 +0200

    Adapted examples to latest clutter (0.9.3)
    
    The examples used methods not available in newer clutter (ClutterEntry, ClutterEffects, several
    old ClutterAlpha things). These are now ported to work with the latest version of clutter. See
    also http://bugzilla.o-hand.com/show_bug.cgi?id=935.
---
 configure.ac                           |    2 +-
 examples/Makefile.am                   |    2 +-
 examples/actor/main.c                  |    2 +-
 examples/actor_group/main.c            |    2 +-
 examples/actor_transformations/main.c  |    2 +-
 examples/animation/main.c              |   87 ++++++++++++++++++++++++++++++++
 examples/behaviour/main.c              |   11 ++---
 examples/custom_actor/triangle_actor.c |   14 +++---
 examples/entry/main.c                  |    8 ++--
 examples/full_example/main.c           |   12 ++--
 10 files changed, 113 insertions(+), 29 deletions(-)

diff --git a/configure.ac b/configure.ac
index bd1ec15..f5513af 100644
--- a/configure.ac
+++ b/configure.ac
@@ -103,7 +103,7 @@ AC_OUTPUT([
     examples/custom_container/Makefile
     examples/behaviour/Makefile
     examples/entry/Makefile
-    examples/effects/Makefile
+    examples/animation/Makefile
     examples/full_example/Makefile
       examples/full_example/images/Makefile
     examples/multiline_text_entry/Makefile
diff --git a/examples/Makefile.am b/examples/Makefile.am
index b9ea53c..db9ce22 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -1,7 +1,7 @@
 include $(top_srcdir)/Makefile_web.am_fragment
 
 example_dirs = actor actor_events actor_group actor_transformations behaviour \
-               custom_actor custom_container effects entry stage stage_widget \
+               custom_actor custom_container animation entry stage stage_widget \
                timeline score full_example \
                scrolling multiline_text_entry
 
diff --git a/examples/actor/main.c b/examples/actor/main.c
index 939379d..f963dc3 100644
--- a/examples/actor/main.c
+++ b/examples/actor/main.c
@@ -38,7 +38,7 @@ int main(int argc, char *argv[])
   clutter_actor_show (rect);
 
   /* Add a label to the stage: */
-  ClutterActor *label = clutter_label_new_full ("Sans 12", "Some Text", &actor_color);
+  ClutterActor *label = clutter_text_new_full ("Sans 12", "Some Text", &actor_color);
   clutter_actor_set_size (label, 500, 500);
   clutter_actor_set_position (label, 20, 150);
   clutter_container_add_actor (CLUTTER_CONTAINER (stage), label);
diff --git a/examples/actor_group/main.c b/examples/actor_group/main.c
index 3a1e91f..9b29c89 100644
--- a/examples/actor_group/main.c
+++ b/examples/actor_group/main.c
@@ -44,7 +44,7 @@ int main(int argc, char *argv[])
   clutter_actor_show (rect);
 
   /* Add a label to the group: */
-  ClutterActor *label = clutter_label_new_full ("Sans 9", "Some Text", &actor_color);
+  ClutterActor *label = clutter_text_new_full ("Sans 9", "Some Text", &actor_color);
   clutter_actor_set_position (label, 0, 60);
   clutter_container_add_actor (CLUTTER_CONTAINER (group), label);
   clutter_actor_show (label);
diff --git a/examples/actor_transformations/main.c b/examples/actor_transformations/main.c
index b504579..bff74de 100644
--- a/examples/actor_transformations/main.c
+++ b/examples/actor_transformations/main.c
@@ -44,7 +44,7 @@ int main(int argc, char *argv[])
 
 
   /* Add a label to the stage: */
-  ClutterActor *label = clutter_label_new_full ("Sans 12", "Some Text", &actor_color);
+  ClutterActor *label = clutter_text_new_full ("Sans 12", "Some Text", &actor_color);
   clutter_actor_set_size (label, 500, 500);
   clutter_actor_set_position (label, 20, 150);
   clutter_container_add_actor (CLUTTER_CONTAINER (stage), label);
diff --git a/examples/animation/main.c b/examples/animation/main.c
new file mode 100644
index 0000000..fd3810c
--- /dev/null
+++ b/examples/animation/main.c
@@ -0,0 +1,87 @@
+/* Copyright 2007 Openismus GmbH
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <clutter/clutter.h>
+#include <stdlib.h>
+
+ClutterActor *rect = NULL;
+
+/* This must return a value between 0 and 1.0
+ *
+ * This will be called as many times per seconds as specified in our call to clutter_timeline_new().
+ *
+ */
+gdouble
+on_alpha (ClutterAlpha *alpha, gpointer data)
+{
+  /* Get the position in the timeline, 
+   *  so we can base our value upon it:
+   */
+  ClutterTimeline *timeline = clutter_alpha_get_timeline (alpha);
+  const int current_frame_num = clutter_timeline_get_current_frame (timeline);
+  const int n_frames = clutter_timeline_get_n_frames (timeline);
+
+  /* Return a value that is simply proportional to the frame position: */
+  return (current_frame_num / n_frames);
+}
+
+
+int main(int argc, char *argv[])
+{
+  ClutterColor stage_color = { 0x00, 0x00, 0x00, 0xff };
+  ClutterColor rect_color = { 0xff, 0xff, 0xff, 0x99 };
+
+  clutter_init (&argc, &argv);
+
+  /* Get the stage and set its size and color: */
+  ClutterActor *stage = clutter_stage_get_default ();
+  clutter_actor_set_size (stage, 200, 200);
+  clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
+
+  /* Add a rectangle to the stage: */
+  rect = clutter_rectangle_new_with_color (&rect_color);
+  clutter_actor_set_size (rect, 40, 40);
+  clutter_actor_set_position (rect, 10, 10);
+  clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect);
+  clutter_actor_show (rect);
+
+  /* Show the stage: */
+  clutter_actor_show (stage);
+
+  ClutterTimeline *timeline = clutter_timeline_new(100 /* frames */, 30 /* frames per second. */);
+  clutter_timeline_set_loop(timeline, TRUE); 
+  clutter_timeline_start(timeline);
+
+  /* Create a clutter alpha for the animation */
+  ClutterAlpha* alpha = clutter_alpha_new_with_func (timeline, &on_alpha, NULL, NULL);
+
+  /* Create an animation to change the properties */
+  ClutterAnimation* animation = 
+    clutter_actor_animate_with_alpha (rect, alpha, 
+                                          "x", 150,
+                                          "y", 150,
+                                          "opactiy", 0,
+                                          NULL);
+
+  g_object_unref (animation);
+  g_object_unref (timeline);
+
+  /* Start the main loop, so we can respond to events: */
+  clutter_main ();
+
+  return EXIT_SUCCESS;
+
+}
diff --git a/examples/behaviour/main.c b/examples/behaviour/main.c
index 2b9bb13..e41936e 100644
--- a/examples/behaviour/main.c
+++ b/examples/behaviour/main.c
@@ -19,15 +19,12 @@
 
 ClutterActor *rect = NULL;
 
-/* This must return a value between 0 and CLUTTER_ALPHA_MAX_ALPHA,
- * where 0 means the start of the path, 
- * and CLUTTER_ALPHA_MAX_ALPHA is the end of the path.
+/* This must return a value between 0 and 1.0
  *
  * This will be called as many times per seconds as specified in our call to clutter_timeline_new().
  *
- * See also, for instance CLUTTER_ALPHA_SINE_HALF for a useful built-in callback.
  */
-guint32
+gdouble
 on_alpha (ClutterAlpha *alpha, gpointer data)
 {
   /* Get the position in the timeline, 
@@ -38,7 +35,7 @@ on_alpha (ClutterAlpha *alpha, gpointer data)
   const int n_frames = clutter_timeline_get_n_frames (timeline);
 
   /* Return a value that is simply proportional to the frame position: */
-  return (CLUTTER_ALPHA_MAX_ALPHA * current_frame_num / n_frames);
+  return (current_frame_num / n_frames);
 }
 
 
@@ -71,7 +68,7 @@ int main(int argc, char *argv[])
   /* Instead of our custom callback, 
    * we could use a standard callback. For instance, CLUTTER_ALPHA_SINE_INC. 
    */
-  ClutterAlpha *alpha = clutter_alpha_new_full (timeline, &on_alpha, NULL, NULL);
+  ClutterAlpha *alpha = clutter_alpha_new_with_func (timeline, &on_alpha, NULL, NULL);
 
   ClutterKnot knot[2];
   knot[0].x = 10;
diff --git a/examples/custom_actor/triangle_actor.c b/examples/custom_actor/triangle_actor.c
index ce8d8b7..2414935 100644
--- a/examples/custom_actor/triangle_actor.c
+++ b/examples/custom_actor/triangle_actor.c
@@ -41,7 +41,7 @@ do_triangle_paint (ClutterActor *self, const CoglColor *color)
   ClutterTriangle        *triangle;
   ClutterTrianglePrivate *priv;
   ClutterGeometry         geom;
-  ClutterFixed            coords[6];
+  float                  coords[6];
 
   triangle = CLUTTER_TRIANGLE(self);
   priv = triangle->priv;
@@ -56,14 +56,14 @@ do_triangle_paint (ClutterActor *self, const CoglColor *color)
    *
    * The parent paint call will have translated us into position so
    * paint from 0, 0 */
-  coords[0] = CLUTTER_INT_TO_FIXED (0);
-  coords[1] = CLUTTER_INT_TO_FIXED (0);
+  coords[0] = 0;
+  coords[1] = 0;
 
-  coords[2] = CLUTTER_INT_TO_FIXED (0);
-  coords[3] = CLUTTER_INT_TO_FIXED (geom.height);
+  coords[2] = 0;
+  coords[3] = geom.height;
 
-  coords[4] = CLUTTER_INT_TO_FIXED (geom.width);
-  coords[5] = CLUTTER_INT_TO_FIXED (geom.height);
+  coords[4] = geom.width;
+  coords[5] = geom.height;
 
   cogl_path_polygon (coords, 3);
   cogl_path_fill ();
diff --git a/examples/entry/main.c b/examples/entry/main.c
index 6e69e6f..60c8546 100644
--- a/examples/entry/main.c
+++ b/examples/entry/main.c
@@ -32,11 +32,11 @@ int main(int argc, char *argv[])
   clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
 
   /* Add an entry to the stage: */
-  entry = clutter_entry_new ();
-  clutter_entry_set_color (CLUTTER_ENTRY (entry), &actor_color);
-  clutter_entry_set_text (CLUTTER_ENTRY (entry), 
+  entry = clutter_text_new ();
+  clutter_text_set_color (CLUTTER_TEXT (entry), &actor_color);
+  clutter_text_set_text (CLUTTER_TEXT (entry), 
     "Wizard imps and sweat sock pimps, interstellar mongrel nymphs.");
-  clutter_entry_set_font_name  (CLUTTER_ENTRY (entry), "Sans 12");
+  clutter_text_set_font_name  (CLUTTER_TEXT (entry), "Sans 12");
   clutter_actor_set_size (entry, 590, 100);
   clutter_actor_set_position (entry, 5, 5);
   clutter_container_add_actor (CLUTTER_CONTAINER (stage), entry);
diff --git a/examples/full_example/main.c b/examples/full_example/main.c
index adfb1e3..e992f55 100644
--- a/examples/full_example/main.c
+++ b/examples/full_example/main.c
@@ -122,7 +122,7 @@ void add_to_ellipse_behaviour(ClutterTimeline *timeline_rotation, gdouble start_
 {
   g_return_if_fail (timeline_rotation);
 
-  ClutterAlpha *alpha = clutter_alpha_new_full (timeline_rotation, &clutter_sine_inc_func, NULL, NULL);
+  ClutterAlpha *alpha = clutter_alpha_new_full (timeline_rotation, CLUTTER_EASE_OUT_SINE);
  
   item->ellipse_behaviour = clutter_behaviour_ellipse_new (alpha, 
     320, ELLIPSE_Y, /* x, y */
@@ -212,7 +212,7 @@ void on_timeline_rotation_completed(ClutterTimeline* timeline, gpointer user_dat
   ClutterActor *actor = item_at_front->actor;
   timeline_moveup = clutter_timeline_new(60 /* frames */, 30 /* fps */);
   ClutterAlpha *alpha =
-    clutter_alpha_new_full (timeline_moveup, &clutter_sine_inc_func, NULL, NULL);
+    clutter_alpha_new_full (timeline_moveup, CLUTTER_EASE_OUT_SINE);
  
   /* Scale the item from its normal scale to approximately twice the normal scale: */
   gdouble scale_start = 0;
@@ -235,7 +235,7 @@ void on_timeline_rotation_completed(ClutterTimeline* timeline, gpointer user_dat
   clutter_behaviour_apply (behaviour_path, actor);
 
   /* Show the filename gradually: */
-  clutter_label_set_text (CLUTTER_LABEL (label_filename), item_at_front->filepath);
+  clutter_text_set_text (CLUTTER_TEXT (label_filename), item_at_front->filepath);
   behaviour_opacity = clutter_behaviour_opacity_new (alpha, 0, 255);
   clutter_behaviour_apply (behaviour_opacity, label_filename);
 
@@ -378,10 +378,10 @@ int main(int argc, char *argv[])
   clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
 
   /* Create and add a label actor, hidden at first: */
-  label_filename = clutter_label_new ();
+  label_filename = clutter_text_new ();
   ClutterColor label_color = { 0x60, 0x60, 0x90, 0xff }; /* blueish */
-  clutter_label_set_color (CLUTTER_LABEL (label_filename), &label_color);
-  clutter_label_set_font_name (CLUTTER_LABEL (label_filename), "Sans 24");
+  clutter_text_set_color (CLUTTER_TEXT (label_filename), &label_color);
+  clutter_text_set_font_name (CLUTTER_TEXT (label_filename), "Sans 24");
   clutter_actor_set_position (label_filename, 10, 10);
   clutter_actor_set_opacity (label_filename, 0);
   clutter_container_add_actor (CLUTTER_CONTAINER (stage), label_filename);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]