c6df3968608ab3b4eb1406d044cd61c379f66da8
[platform/core/graphics/tizenvg.git] / test / testCapi.c
1 #include <Elementary.h>\r
2 #include <thorvg_capi.h>\r
3 \r
4 #define WIDTH 800\r
5 #define HEIGHT 800\r
6 \r
7 \r
8 /************************************************************************/\r
9 /* Capi Test Code                                                       */\r
10 /************************************************************************/\r
11 \r
12 static uint32_t buffer[WIDTH * HEIGHT];\r
13 \r
14 void testCapi()\r
15 {\r
16     tvg_engine_init(TVG_ENGINE_SW | TVG_ENGINE_GL);\r
17 \r
18     Tvg_Canvas* canvas = tvg_swcanvas_create();\r
19     tvg_swcanvas_set_target(canvas, buffer, WIDTH, WIDTH, HEIGHT, TVG_COLORSPACE_ARGB8888);\r
20 \r
21     Tvg_Paint* shape = tvg_shape_new();\r
22     tvg_shape_append_rect(shape, 0, 0, 200, 200, 0, 0);\r
23     tvg_shape_append_circle(shape, 200, 200, 100, 100);\r
24     tvg_shape_append_rect(shape, 100, 100, 300, 300, 100, 100);\r
25     Tvg_Gradient* grad = tvg_linear_gradient_new();\r
26     tvg_linear_gradient_set(grad, 0, 0, 300, 300);\r
27     Tvg_Color_Stop color_stops[4] =\r
28     {\r
29         {.offset=0.0, .r=0, .g=0, .b=0, .a=255},\r
30         {.offset=0.25, .r=255, .g=0, .b=0, .a=255},\r
31         {.offset=0.5, .r=0, .g=255, .b=0, .a=255},\r
32         {.offset=1.0, .r=0, .g=0, .b=255, .a=255}\r
33     };\r
34 \r
35 \r
36     Tvg_Paint *shape1 = tvg_shape_new();\r
37     tvg_shape_append_rect(shape1, 500, 500, 100, 100, 30, 30);\r
38     Tvg_Gradient* grad1 = tvg_radial_gradient_new();\r
39     tvg_radial_gradient_set(grad1, 550, 550, 50);\r
40     Tvg_Color_Stop color_stops1[3] =\r
41     {\r
42         {.offset=0.0, .r=0, .g=0, .b=0, .a=255},\r
43         {.offset=0.6, .r=255, .g=0, .b=0, .a=255},\r
44         {.offset=1.0, .r=0, .g=255, .b=255, .a=255}\r
45     };\r
46 \r
47     Tvg_Paint *shape2 = tvg_shape_new();\r
48     tvg_shape_append_rect(shape2, 400, 0, 800, 400, 20, 20);\r
49     Tvg_Gradient* grad2 = tvg_linear_gradient_new();\r
50     tvg_linear_gradient_set(grad2, 400, 0, 450, 50);\r
51     Tvg_Color_Stop color_stops2[2] =\r
52     {\r
53         {.offset=0.0, .r=0, .g=0, .b=0, .a=255},\r
54         {.offset=1, .r=255, .g=0, .b=0, .a=255},\r
55     };\r
56 \r
57     tvg_gradient_spread(grad2, TVG_STROKE_FILL_REPEAT);\r
58 \r
59     Tvg_Paint* shape3 = tvg_shape_new();\r
60     tvg_shape_append_rect(shape3, 0, 400, 400, 800, 20, 20);\r
61     Tvg_Gradient* grad3 = tvg_linear_gradient_new();\r
62     tvg_linear_gradient_set(grad3, 0, 400, 50, 450);\r
63     Tvg_Color_Stop color_stops3[2] =\r
64     {\r
65         {.offset=0.0, .r=0, .g=0, .b=0, .a=255},\r
66         {.offset=1, .r=0, .g=255, .b=0, .a=255},\r
67     };\r
68 \r
69     tvg_gradient_spread(grad3, TVG_STROKE_FILL_REFLECT);\r
70 \r
71     tvg_gradient_color_stops(grad, color_stops, 4);\r
72     tvg_gradient_color_stops(grad1, color_stops1, 3);\r
73     tvg_gradient_color_stops(grad2, color_stops2, 2);\r
74     tvg_gradient_color_stops(grad3, color_stops3, 2);\r
75     tvg_shape_linear_gradient_set(shape, grad);\r
76     tvg_shape_radial_gradient_set(shape1, grad1);\r
77     tvg_shape_linear_gradient_set(shape2, grad2);\r
78     tvg_shape_linear_gradient_set(shape3, grad3);\r
79 \r
80     tvg_canvas_push(canvas, shape);\r
81     tvg_canvas_push(canvas, shape1);\r
82     tvg_canvas_push(canvas, shape2);\r
83     tvg_canvas_push(canvas, shape3);\r
84 \r
85     Tvg_Paint* shape4 = tvg_shape_new();\r
86     tvg_shape_append_rect(shape4, 700, 700, 100, 100, 20, 20);\r
87     Tvg_Gradient* grad4 = tvg_linear_gradient_new();\r
88     tvg_linear_gradient_set(grad4, 700, 700, 800, 800);\r
89     Tvg_Color_Stop color_stops4[2] =\r
90     {\r
91         {.offset=0.0, .r=0, .g=0, .b=0, .a=255},\r
92         {.offset=1, .r=0, .g=255, .b=0, .a=255},\r
93     };\r
94     tvg_gradient_color_stops(grad4, color_stops4, 2);\r
95     tvg_shape_linear_gradient_set(shape4, grad4);\r
96 \r
97     Tvg_Gradient* grad5 = tvg_linear_gradient_new();\r
98     tvg_linear_gradient_set(grad5, 700, 700, 800, 800);\r
99     Tvg_Color_Stop color_stops5[2] =\r
100     {\r
101         {.offset=0.0, .r=0, .g=0, .b=255, .a=255},\r
102         {.offset=1, .r=0, .g=255, .b=255, .a=255},\r
103     };\r
104     tvg_gradient_color_stops(grad5, color_stops5, 2);\r
105     tvg_shape_linear_gradient_set(shape4, grad5);\r
106 \r
107     tvg_canvas_push(canvas, shape4);\r
108 \r
109     tvg_canvas_draw(canvas);\r
110     tvg_canvas_sync(canvas);\r
111 \r
112     tvg_canvas_destroy(canvas);\r
113 \r
114     tvg_engine_term(TVG_ENGINE_SW | TVG_ENGINE_GL);\r
115 }\r
116 \r
117 \r
118 /************************************************************************/\r
119 /* Main Code                                                            */\r
120 /************************************************************************/\r
121 \r
122 void win_del(void *data, Evas_Object *o, void *ev)\r
123 {\r
124    elm_exit();\r
125 }\r
126 \r
127 \r
128 int main(int argc, char **argv)\r
129 {\r
130     elm_init(argc, argv);\r
131 \r
132     Eo* win = elm_win_util_standard_add(NULL, "ThorVG Test");\r
133     evas_object_smart_callback_add(win, "delete,request", win_del, 0);\r
134 \r
135     Eo* view = evas_object_image_filled_add(evas_object_evas_get(win));\r
136     evas_object_image_size_set(view, WIDTH, HEIGHT);\r
137     evas_object_image_data_set(view, buffer);\r
138     evas_object_image_pixels_dirty_set(view, EINA_TRUE);\r
139     evas_object_image_data_update_add(view, 0, 0, WIDTH, HEIGHT);\r
140     evas_object_size_hint_weight_set(view, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);\r
141     evas_object_show(view);\r
142 \r
143     elm_win_resize_object_add(win, view);\r
144     evas_object_geometry_set(win, 0, 0, WIDTH, HEIGHT);\r
145     evas_object_show(win);\r
146 \r
147     testCapi();\r
148 \r
149     elm_run();\r
150     elm_shutdown();\r
151 \r
152     return 0;\r
153 }\r