[gtk-clutter-test] Update for the clutter timeline changes
[clutter-gtk] / examples / gtk-clutter-test.c
index f80acf1..83e7c2d 100644 (file)
@@ -2,13 +2,13 @@
 #include <clutter/clutter.h>
 #include <math.h>
 
-#include <clutter-gtk/gtk-clutter-embed.h>
+#include <clutter-gtk/clutter-gtk.h>
 
 #define TRAILS 0
 #define NHANDS  2
-#define WINWIDTH   800
-#define WINHEIGHT  800
-#define RADIUS     250
+#define WINWIDTH   400
+#define WINHEIGHT  400
+#define RADIUS     150
 
 typedef struct SuperOH
 {
@@ -18,7 +18,8 @@ typedef struct SuperOH
 
 } SuperOH; 
 
-gboolean fade = FALSE;
+static gboolean fade = FALSE;
+static gboolean fullscreen = FALSE;
 
 /* input handler */
 void 
@@ -28,14 +29,14 @@ input_cb (ClutterStage *stage,
 {
   if (event->type == CLUTTER_BUTTON_PRESS)
     {
-      ClutterActor *actor;
-      gint x, y;
+      ClutterActor *a;
+      gfloat 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, CLUTTER_PICK_ALL, x, y);
+      if (a && (CLUTTER_IS_TEXTURE (a) || CLUTTER_IS_CLONE (a)))
+       clutter_actor_hide (a);
     }
   else if (event->type == CLUTTER_KEY_PRESS)
     {
@@ -53,11 +54,12 @@ input_cb (ClutterStage *stage,
 /* Timeline handler */
 void
 frame_cb (ClutterTimeline *timeline, 
-         gint             frame_num, 
+         gint             msecs,
          gpointer         data)
 {
   SuperOH        *oh = (SuperOH *)data;
   gint            i;
+  guint           rotation = clutter_timeline_get_progress (timeline) * 360.0f;
 
 #if TRAILS
   oh->bgpixb = clutter_stage_snapshot (CLUTTER_STAGE (stage),
@@ -72,7 +74,7 @@ frame_cb (ClutterTimeline *timeline,
   /* Rotate everything clockwise about stage center*/
   clutter_actor_set_rotation (CLUTTER_ACTOR (oh->group),
                               CLUTTER_Z_AXIS,
-                              frame_num,
+                              rotation,
                               WINWIDTH / 2, WINHEIGHT / 2, 0);
 
   for (i = 0; i < NHANDS; i++)
@@ -80,12 +82,12 @@ frame_cb (ClutterTimeline *timeline,
       /* rotate each hand around there centers */
       clutter_actor_set_rotation (oh->hand[i],
                                   CLUTTER_Z_AXIS,
-                                  - 6.0 * frame_num,
+                                  - 6.0 * rotation,
                                   clutter_actor_get_width (oh->hand[i]) / 2,
                                   clutter_actor_get_height (oh->hand[i]) / 2,
                                   0);
       if (fade == TRUE)
-        clutter_actor_set_opacity (oh->hand[i], (255 - (frame_num % 255)));
+        clutter_actor_set_opacity (oh->hand[i], (255 - (rotation % 255)));
     }
 
   /*
@@ -102,20 +104,36 @@ clickity (GtkButton *button,
         fade = !fade;
 }
 
+static void
+on_fullscreen (GtkButton *button,
+               GtkWindow *window)
+{
+  if (!fullscreen)
+    {
+      gtk_window_fullscreen (window);
+      fullscreen = TRUE;
+    }
+  else
+    {
+      gtk_window_unfullscreen (window);
+      fullscreen = FALSE;
+    }
+}
+
 int
 main (int argc, char *argv[])
 {
   ClutterTimeline *timeline;
   ClutterActor    *stage;
   ClutterColor     stage_color = { 0x61, 0x64, 0x8c, 0xff };
-  GtkWidget       *window, *clutter, *socket_box;
+  GtkWidget       *window, *clutter;
   GtkWidget       *label, *button, *vbox;
   GdkPixbuf       *pixbuf;
   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);
 
@@ -130,6 +148,7 @@ main (int argc, char *argv[])
   gtk_container_add (GTK_CONTAINER (window), vbox);
 
   clutter = gtk_clutter_embed_new ();
+  gtk_widget_set_size_request (clutter, WINWIDTH, WINHEIGHT);
 
   gtk_container_add (GTK_CONTAINER (vbox), clutter);
 
@@ -143,6 +162,15 @@ main (int argc, char *argv[])
                     G_CALLBACK (clickity), NULL);
   gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
 
+  button = gtk_button_new_with_label ("Fullscreen");
+  gtk_button_set_image (GTK_BUTTON (button),
+                        gtk_image_new_from_stock (GTK_STOCK_FULLSCREEN,
+                                                  GTK_ICON_SIZE_BUTTON));
+  g_signal_connect (button, "clicked",
+                    G_CALLBACK (on_fullscreen),
+                    window);
+  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+
   button = gtk_button_new_from_stock (GTK_STOCK_QUIT);
   g_signal_connect_swapped (button, "clicked",
                             G_CALLBACK (gtk_widget_destroy),
@@ -164,7 +192,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++)
     {
@@ -172,9 +200,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_new (oh->hand[0]);
 #else
       ClutterColor colour = { 255, 0, 0, 255 };
 
@@ -195,10 +223,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 (stage),
+                               CLUTTER_ACTOR (oh->group));
 
   g_signal_connect (stage, "button-press-event",
                    G_CALLBACK (input_cb), 
@@ -209,8 +235,14 @@ 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 */
+  timeline = clutter_timeline_new (6000);
   g_object_set(timeline, "loop", TRUE, NULL);   /* have it loop */
 
   /* fire a callback for frame change */