renamed project name tizenvg => thorvg
[platform/core/graphics/tizenvg.git] / test / testScene.cpp
1 #include <thorvg.h>
2 #include <Elementary.h>
3
4 using namespace std;
5
6 #define WIDTH 800
7 #define HEIGHT 800
8
9 static uint32_t buffer[WIDTH * HEIGHT];
10
11 void tvgtest()
12 {
13     //Initialize ThorVG Engine
14     tvg::Initializer::init(tvg::CanvasEngine::Sw);
15
16     //Create a Canvas
17     auto canvas = tvg::SwCanvas::gen();
18     canvas->target(buffer, WIDTH, WIDTH, HEIGHT);
19
20     //Create a Scene
21     auto scene = tvg::Scene::gen();
22     scene->reserve(3);   //reserve 3 shape nodes (optional)
23
24     //Prepare Round Rectangle
25     auto shape1 = tvg::Shape::gen();
26     shape1->appendRect(0, 0, 400, 400, 50);      //x, y, w, h, cornerRadius
27     shape1->fill(0, 255, 0, 255);                //r, g, b, a
28     scene->push(move(shape1));
29
30     //Prepare Circle
31     auto shape2 = tvg::Shape::gen();
32     shape2->appendCircle(400, 400, 200, 200);    //cx, cy, radiusW, radiusH
33     shape2->fill(255, 255, 0, 255);              //r, g, b, a
34     scene->push(move(shape2));
35
36     //Prepare Ellipse
37     auto shape3 = tvg::Shape::gen();
38     shape3->appendCircle(600, 600, 150, 100);    //cx, cy, radiusW, radiusH
39     shape3->fill(0, 255, 255, 255);              //r, g, b, a
40     scene->push(move(shape3));
41
42     //Create another Scene
43     auto scene2 = tvg::Scene::gen();
44     scene2->reserve(2);   //reserve 2 shape nodes (optional)
45
46     //Star
47     auto shape4 = tvg::Shape::gen();
48
49     //Appends Paths
50     shape4->moveTo(199, 34);
51     shape4->lineTo(253, 143);
52     shape4->lineTo(374, 160);
53     shape4->lineTo(287, 244);
54     shape4->lineTo(307, 365);
55     shape4->lineTo(199, 309);
56     shape4->lineTo(97, 365);
57     shape4->lineTo(112, 245);
58     shape4->lineTo(26, 161);
59     shape4->lineTo(146, 143);
60     shape4->close();
61     shape4->fill(0, 0, 255, 255);
62     scene2->push(move(shape4));
63
64     //Circle
65     auto shape5 = tvg::Shape::gen();
66
67     auto cx = 550.0f;
68     auto cy = 550.0f;
69     auto radius = 125.0f;
70     auto halfRadius = radius * 0.552284f;
71
72     //Append Paths
73     shape5->moveTo(cx, cy - radius);
74     shape5->cubicTo(cx + halfRadius, cy - radius, cx + radius, cy - halfRadius, cx + radius, cy);
75     shape5->cubicTo(cx + radius, cy + halfRadius, cx + halfRadius, cy + radius, cx, cy+ radius);
76     shape5->cubicTo(cx - halfRadius, cy + radius, cx - radius, cy + halfRadius, cx - radius, cy);
77     shape5->cubicTo(cx - radius, cy - halfRadius, cx - halfRadius, cy - radius, cx, cy - radius);
78     shape5->fill(255, 0, 0, 255);
79     scene2->push(move(shape5));
80
81     //Push scene2 onto the scene
82     scene->push(move(scene2));
83
84     //Draw the Scene onto the Canvas
85     canvas->push(move(scene));
86     canvas->draw();
87     canvas->sync();
88
89     //Terminate ThorVG Engine
90     tvg::Initializer::term(tvg::CanvasEngine::Sw);
91 }
92
93 void win_del(void *data, Evas_Object *o, void *ev)
94 {
95    elm_exit();
96 }
97
98
99 int main(int argc, char **argv)
100 {
101     tvgtest();
102
103     //Show the result using EFL...
104     elm_init(argc, argv);
105
106     Eo* win = elm_win_util_standard_add(NULL, "ThorVG Test");
107     evas_object_smart_callback_add(win, "delete,request", win_del, 0);
108
109     Eo* img = evas_object_image_filled_add(evas_object_evas_get(win));
110     evas_object_image_size_set(img, WIDTH, HEIGHT);
111     evas_object_image_data_set(img, buffer);
112     evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
113     evas_object_show(img);
114
115     elm_win_resize_object_add(win, img);
116     evas_object_geometry_set(win, 0, 0, WIDTH, HEIGHT);
117     evas_object_show(win);
118
119     elm_run();
120     elm_shutdown();
121 }