Debian Codegraph @

tests/interactive/test-cogl-primitives.c

raw
1 #include <glib.h>
2 #include <gmodule.h>
3 #include <stdlib.h>
4
5 #undef COGL_ENABLE_EXPERIMENTAL_2_0_API
6 #include <cogl/cogl.h>
7 #include <clutter/clutter.h>
8
9 typedef void (*PaintFunc) (void);
10
11 static void
12 test_paint_line (void)
13 {
14 cogl_path_line (-50, -25, 50, 25);
15 }
16
17 static void
18 test_paint_rect (void)
19 {
20 cogl_path_rectangle (-50, -25, 50, 25);
21 }
22
23 static void
24 test_paint_rndrect(void)
25 {
26 cogl_path_round_rectangle (-50, -25, 50, 25, 10, 5);
27 }
28
29 static void
30 test_paint_polyl (void)
31 {
32 gfloat poly_coords[] = {
33 -50, -50,
34 +50, -30,
35 +30, +30,
36 -30, +40
37 };
38
39 cogl_path_polyline (poly_coords, 4);
40 }
41
42 static void
43 test_paint_polyg (void)
44 {
45 gfloat poly_coords[] = {
46 -50, -50,
47 +50, -30,
48 +30, +30,
49 -30, +40
50 };
51
52 cogl_path_polygon (poly_coords, 4);
53 }
54
55 static void
56 test_paint_elp (void)
57 {
58 cogl_path_ellipse (0, 0, 60, 40);
59 }
60
61 static void
62 test_paint_curve (void)
63 {
64 cogl_path_move_to (-50, +50);
65
66 cogl_path_curve_to (+100, -50,
67 -100, -50,
68 +50, +50);
69 }
70
71 static PaintFunc paint_func []=
72 {
73 test_paint_line,
74 test_paint_rect,
75 test_paint_rndrect,
76 test_paint_polyl,
77 test_paint_polyg,
78 test_paint_elp,
79 test_paint_curve
80 };
81
82 static void
83 paint_cb (ClutterActor *self, ClutterTimeline *tl)
84 {
85 gint paint_index = (clutter_timeline_get_progress (tl)
86 * G_N_ELEMENTS (paint_func));
87
88 cogl_push_matrix ();
89
90 paint_func[paint_index] ();
91
92 cogl_translate (100, 100, 0);
93 cogl_set_source_color4ub (0, 160, 0, 255);
94 cogl_path_stroke_preserve ();
95
96 cogl_translate (150, 0, 0);
97 cogl_set_source_color4ub (200, 0, 0, 255);
98 cogl_path_fill ();
99
100 cogl_pop_matrix();
101 }
102
103 G_MODULE_EXPORT int
104 test_cogl_primitives_main (int argc, char *argv[])
105 {
106 ClutterActor *stage;
107 ClutterActor *coglbox;
108 ClutterTimeline *tl;
109
110 if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
111 return 1;
112
113 tl = clutter_timeline_new (G_N_ELEMENTS (paint_func) * 1000);
114 clutter_timeline_set_loop (tl, TRUE);
115 clutter_timeline_start (tl);
116
117 stage = clutter_stage_new ();
118 clutter_actor_set_size (stage, 400, 400);
119 clutter_stage_set_title (CLUTTER_STAGE (stage), "Cogl Path Primitives");
120 g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
121
122 coglbox = clutter_group_new ();
123 clutter_container_add_actor (CLUTTER_CONTAINER (stage), coglbox);
124 g_signal_connect (coglbox, "paint", G_CALLBACK (paint_cb), tl);
125 /* Redraw every frame of the timeline */
126 g_signal_connect_swapped (tl, "new-frame",
127 G_CALLBACK (clutter_actor_queue_redraw), coglbox);
128
129 clutter_actor_set_rotation (coglbox, CLUTTER_Y_AXIS, -30, 200, 0, 0);
130 clutter_actor_set_position (coglbox, 0, 100);
131
132 clutter_actor_show (stage);
133
134 clutter_main ();
135
136 g_object_unref (tl);
137
138 return 0;
139 }
140
141 G_MODULE_EXPORT const char *
142 test_cogl_primitives (void)
143 {
144 return "2D Path primitives support in Cogl.";
145 }