2008-04-24 Emmanuele Bassi <ebassi@openedhand.com>
[clutter-gtk] / examples / gtk-clutter-test.c
index 7ab6df8..937e716 100644 (file)
@@ -3,6 +3,7 @@
 #include <math.h>
 
 #include <clutter-gtk/gtk-clutter-embed.h>
+#include <clutter-gtk/gtk-clutter-util.h>
 
 #define TRAILS 0
 #define NHANDS  2
@@ -28,14 +29,14 @@ input_cb (ClutterStage *stage,
 {
   if (event->type == CLUTTER_BUTTON_PRESS)
     {
-      ClutterActor *actor;
+      ClutterActor *a;
       gint x, y;
 
       clutter_event_get_coords (event, &x, &y);
 
-      actor = clutter_stage_get_actor_at_pos (stage, x, y);
-      if (actor)
-       clutter_actor_hide (actor);
+      a = clutter_stage_get_actor_at_pos (stage, x, y);
+      if (a && (CLUTTER_IS_TEXTURE (a) || CLUTTER_IS_CLONE_TEXTURE (a)))
+       clutter_actor_hide (a);
     }
   else if (event->type == CLUTTER_KEY_PRESS)
     {
@@ -114,8 +115,8 @@ main (int argc, char *argv[])
   SuperOH         *oh;
   gint             i;
 
-  clutter_init (&argc, &argv);
-  gtk_init (&argc, &argv);
+  if (gtk_clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
+    g_error ("Unable to initialize GtkClutter");
 
   pixbuf = gdk_pixbuf_new_from_file ("redhand.png", NULL);
 
@@ -165,7 +166,7 @@ main (int argc, char *argv[])
 #endif
 
   /* create a new group to hold multiple actors in a group */
-  oh->group = CLUTTER_GROUP (clutter_group_new());
+  oh->group = CLUTTER_GROUP (clutter_group_new ());
   
   for (i = 0; i < NHANDS; i++)
     {
@@ -173,9 +174,9 @@ main (int argc, char *argv[])
 #if 1
       /* Create a texture from pixbuf, then clone in to same resources */
       if (i == 0)
-       oh->hand[i] = clutter_texture_new_from_pixbuf (pixbuf);
+       oh->hand[i] = gtk_clutter_texture_new_from_pixbuf (pixbuf);
      else
-       oh->hand[i] = clutter_clone_texture_new (CLUTTER_TEXTURE(oh->hand[0]));
+       oh->hand[i] = clutter_clone_texture_new (CLUTTER_TEXTURE (oh->hand[0]));
 #else
       ClutterColor colour = { 255, 0, 0, 255 };
 
@@ -196,10 +197,8 @@ main (int argc, char *argv[])
     }
 
   /* Add the group to the stage */
-  clutter_group_add (CLUTTER_GROUP (stage), CLUTTER_ACTOR(oh->group));
-
-  /* Show everying ( and map window ) */
-  clutter_actor_show_all (CLUTTER_ACTOR (oh->group));
+  clutter_container_add_actor (CLUTTER_CONTAINER (clutter),
+                               CLUTTER_ACTOR (oh->group));
 
   g_signal_connect (stage, "button-press-event",
                    G_CALLBACK (input_cb), 
@@ -210,6 +209,12 @@ main (int argc, char *argv[])
 
   gtk_widget_show_all (window);
 
+  /* Only show the actors after parent show otherwise it will just be
+   * unrealized when the clutter foreign window is set. widget_show
+   * will call show on the stage.
+   */
+  clutter_actor_show_all (CLUTTER_ACTOR (oh->group));
+
   /* Create a timeline to manage animation */
   timeline = clutter_timeline_new (360, 60); /* num frames, fps */
   g_object_set(timeline, "loop", TRUE, NULL);   /* have it loop */