1 /*
2 * Display multiple rotated copies of an image on top of each other
3 *
4 * Invoke with the path to a file to load a custom image
5 */
6 #include <clutter/clutter.h>
7
8 #define STAGE_SIDE 512
9
10 static const ClutterColor box_color = { 0x33, 0x33, 0x55, 0xff };
11
12 int
main(int argc,char * argv[])13 main (int argc, char *argv[])
14 {
15 ClutterLayoutManager *layout;
16 ClutterActor *box;
17 ClutterActor *stage;
18 ClutterActor *texture;
19 CoglHandle *cogl_texture;
20 GError *error = NULL;
21 gfloat width;
22
23 const gchar *filename = "redhand.png";
24
25 if (argc > 1)
26 filename = argv[1];
27
28 if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
29 return 1;
30
31 stage = clutter_stage_new ();
32 clutter_actor_set_size (stage, STAGE_SIDE, STAGE_SIDE);
33 g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
34
35 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
36 CLUTTER_BIN_ALIGNMENT_CENTER);
37
38 box = clutter_actor_new ();
39 clutter_actor_set_layout_manager (box, layout);
40 clutter_actor_set_background_color (box, &box_color);
41
42 texture = clutter_texture_new_from_file (filename, &error);
43
44 if (error != NULL)
45 g_error ("Error loading file %s; message was:\n%s",
46 filename,
47 error->message);
48
49 /*
50 * get a reference to the underlying Cogl texture
51 * for copying onto each Clutter texture placed into the layout
52 */
53 cogl_texture = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (texture));
54
55 /*
56 * add gradually turning and shrinking textures,
57 * smallest one last; each actor ends up on top
58 * of the one added just before it
59 */
60 for (width = STAGE_SIDE * 0.75; width >= STAGE_SIDE * 0.0625; width -= STAGE_SIDE * 0.0625)
61 {
62 ClutterActor *texture_copy = clutter_texture_new ();
63 clutter_texture_set_cogl_texture (CLUTTER_TEXTURE (texture_copy),
64 cogl_texture);
65 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (texture_copy),
66 TRUE);
67 clutter_actor_set_z_rotation_from_gravity (texture_copy,
68 (gfloat)(width * 0.5) - (STAGE_SIDE * 0.03125),
69 CLUTTER_GRAVITY_CENTER);
70 clutter_actor_set_width (texture_copy, width);
71 clutter_actor_add_child (box, texture_copy);
72 }
73
74 clutter_actor_add_constraint (box, clutter_align_constraint_new (stage, CLUTTER_ALIGN_BOTH, 0.5));
75 clutter_actor_add_child (stage, box);
76
77 clutter_actor_show (stage);
78
79 clutter_main ();
80
81 return 0;
82 }
83