2 #include <clutter/clutter.h>
5 #include <clutter-gtk/gtk-clutter-embed.h>
6 #include <clutter-gtk/gtk-clutter-util.h>
14 typedef struct SuperOH
16 ClutterActor *hand[NHANDS], *bgtex;
22 gboolean fade = FALSE;
26 input_cb (ClutterStage *stage,
30 if (event->type == CLUTTER_BUTTON_PRESS)
35 clutter_event_get_coords (event, &x, &y);
37 a = clutter_stage_get_actor_at_pos (stage, x, y);
38 if (a && (CLUTTER_IS_TEXTURE (a) || CLUTTER_IS_CLONE_TEXTURE (a)))
39 clutter_actor_hide (a);
41 else if (event->type == CLUTTER_KEY_PRESS)
43 ClutterKeyEvent *kev = (ClutterKeyEvent *) event;
45 g_print ("*** key press event (key:%c) ***\n",
46 clutter_key_event_symbol (kev));
48 if (clutter_key_event_symbol (kev) == CLUTTER_q)
54 /* Timeline handler */
56 frame_cb (ClutterTimeline *timeline,
60 SuperOH *oh = (SuperOH *)data;
64 oh->bgpixb = clutter_stage_snapshot (CLUTTER_STAGE (stage),
68 clutter_texture_set_pixbuf (CLUTTER_TEXTURE (oh->bgtex), oh->bgpixb);
69 g_object_unref (G_OBJECT (oh->bgpixb));
70 g_object_unref (stage);
73 /* Rotate everything clockwise about stage center*/
74 clutter_actor_set_rotation (CLUTTER_ACTOR (oh->group),
77 WINWIDTH / 2, WINHEIGHT / 2, 0);
79 for (i = 0; i < NHANDS; i++)
81 /* rotate each hand around there centers */
82 clutter_actor_set_rotation (oh->hand[i],
85 clutter_actor_get_width (oh->hand[i]) / 2,
86 clutter_actor_get_height (oh->hand[i]) / 2,
89 clutter_actor_set_opacity (oh->hand[i], (255 - (frame_num % 255)));
93 clutter_actor_rotate_x (CLUTTER_ACTOR(oh->group),
100 clickity (GtkButton *button,
107 main (int argc, char *argv[])
109 ClutterTimeline *timeline;
111 ClutterColor stage_color = { 0x61, 0x64, 0x8c, 0xff };
112 GtkWidget *window, *clutter, *socket_box;
113 GtkWidget *label, *button, *vbox;
118 if (gtk_clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
119 g_error ("Unable to initialize GtkClutter");
121 pixbuf = gdk_pixbuf_new_from_file ("redhand.png", NULL);
124 g_error("pixbuf load failed");
126 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
127 g_signal_connect (window, "destroy",
128 G_CALLBACK (gtk_main_quit), NULL);
130 vbox = gtk_vbox_new (FALSE, 6);
131 gtk_container_add (GTK_CONTAINER (window), vbox);
133 clutter = gtk_clutter_embed_new ();
134 gtk_widget_set_size_request (clutter, WINWIDTH, WINHEIGHT);
136 gtk_container_add (GTK_CONTAINER (vbox), clutter);
138 stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (clutter));
140 label = gtk_label_new ("This is a label");
141 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
143 button = gtk_button_new_with_label ("This is a button...clicky");
144 g_signal_connect (button, "clicked",
145 G_CALLBACK (clickity), NULL);
146 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
148 button = gtk_button_new_from_stock (GTK_STOCK_QUIT);
149 g_signal_connect_swapped (button, "clicked",
150 G_CALLBACK (gtk_widget_destroy),
152 gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0);
154 /* and its background color */
156 clutter_stage_set_color (CLUTTER_STAGE (stage),
159 oh = g_new(SuperOH, 1);
162 oh->bgtex = clutter_texture_new();
163 clutter_actor_set_size (oh->bgtex, WINWIDTH, WINHEIGHT);
164 clutter_actor_set_opacity (oh->bgtex, 0x99);
165 clutter_group_add (CLUTTER_GROUP (stage), oh->bgtex);
168 /* create a new group to hold multiple actors in a group */
169 oh->group = CLUTTER_GROUP (clutter_group_new ());
171 for (i = 0; i < NHANDS; i++)
175 /* Create a texture from pixbuf, then clone in to same resources */
177 oh->hand[i] = gtk_clutter_texture_new_from_pixbuf (pixbuf);
179 oh->hand[i] = clutter_clone_texture_new (CLUTTER_TEXTURE (oh->hand[0]));
181 ClutterColor colour = { 255, 0, 0, 255 };
183 oh->hand[i] = clutter_rectangle_new_with_color (&colour);
184 clutter_actor_set_size (oh->hand[i], 50, 50);
186 /* Place around a circle */
187 w = clutter_actor_get_width (oh->hand[0]);
188 h = clutter_actor_get_height (oh->hand[0]);
190 x = WINWIDTH/2 + RADIUS * cos (i * M_PI / (NHANDS/2)) - w/2;
191 y = WINHEIGHT/2 + RADIUS * sin (i * M_PI / (NHANDS/2)) - h/2;
193 clutter_actor_set_position (oh->hand[i], x, y);
195 /* Add to our group group */
196 clutter_group_add (oh->group, oh->hand[i]);
199 /* Add the group to the stage */
200 clutter_container_add_actor (CLUTTER_CONTAINER (clutter),
201 CLUTTER_ACTOR (oh->group));
203 g_signal_connect (stage, "button-press-event",
204 G_CALLBACK (input_cb),
206 g_signal_connect (stage, "key-release-event",
207 G_CALLBACK (input_cb),
210 gtk_widget_show_all (window);
212 /* Only show the actors after parent show otherwise it will just be
213 * unrealized when the clutter foreign window is set. widget_show
214 * will call show on the stage.
216 clutter_actor_show_all (CLUTTER_ACTOR (oh->group));
218 /* Create a timeline to manage animation */
219 timeline = clutter_timeline_new (360, 60); /* num frames, fps */
220 g_object_set(timeline, "loop", TRUE, NULL); /* have it loop */
222 /* fire a callback for frame change */
223 g_signal_connect(timeline, "new-frame", G_CALLBACK (frame_cb), oh);
226 clutter_timeline_start (timeline);