[examples] Use different sized stages
[clutter-gtk] / examples / gtk-clutter-multistage.c
index 34abe32..ef4623a 100644 (file)
@@ -1,19 +1,25 @@
 #include <gtk/gtk.h>
 #include <clutter/clutter.h>
 
-#include <clutter-gtk/gtk-clutter-embed.h>
-#include <clutter-gtk/gtk-clutter-util.h>
+#include <clutter-gtk/clutter-gtk.h>
+
+static void
+on_stage2_allocation_changed (ClutterActor           *stage_2,
+                              const ClutterActorBox  *allocation,
+                              ClutterAllocationFlags  flags,
+                              ClutterActor           *texture_2)
+{
+  clutter_actor_set_position (texture_2,
+                              (allocation->x2 - allocation->x1) / 2,
+                              (allocation->y2 - allocation->y1) / 2);
+}
 
 int
 main (int argc, char *argv[])
 {
-  ClutterTimeline *timeline;
   ClutterActor    *stage1, *stage2, *tex1, *tex2;
-  ClutterColor     stage_color = { 0x61, 0x64, 0x8c, 0xff };
   GtkWidget       *window, *clutter1, *clutter2;
-  GtkWidget       *label, *button, *vbox;
-  GdkPixbuf       *pixbuf;
-  gint             i;
+  GtkWidget       *vbox;
   ClutterColor     col1 = { 0xff, 0xff, 0xff, 0xff };
   ClutterColor     col2 = { 0, 0, 0, 0xff };
 
@@ -44,7 +50,7 @@ main (int argc, char *argv[])
   gtk_container_add (GTK_CONTAINER (vbox), clutter1);
 
   clutter2 = gtk_clutter_embed_new ();
-  gtk_widget_set_size_request (clutter2, 320, 240);
+  gtk_widget_set_size_request (clutter2, 320, 120);
   stage2 = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (clutter2));
   clutter_stage_set_color (CLUTTER_STAGE(stage2), &col2);
   tex2 = gtk_clutter_texture_new_from_icon_name (clutter1,
@@ -53,11 +59,15 @@ main (int argc, char *argv[])
   clutter_actor_set_anchor_point (tex2,
                                   clutter_actor_get_width (tex2) / 2,
                                   clutter_actor_get_height (tex2) / 2);
-  clutter_actor_set_position (tex2, 160, 120);
+  clutter_actor_set_position (tex2, 160, 60);
   clutter_stage_add (stage2, tex2);
 
   gtk_container_add (GTK_CONTAINER (vbox), clutter2);
 
+  g_signal_connect (stage2, "allocation-changed",
+                    G_CALLBACK (on_stage2_allocation_changed),
+                    tex2);
+
   gtk_widget_show_all (window);
   clutter_actor_show_all (stage1); 
   clutter_actor_show_all (stage2);