bindings/capi: fix c compatibility warnings.
[platform/core/graphics/tizenvg.git] / src / examples / testStroke.cpp
1 #include "testCommon.h"
2
3 /************************************************************************/
4 /* Drawing Commands                                                     */
5 /************************************************************************/
6
7 void tvgDrawCmds(tvg::Canvas* canvas)
8 {
9     if (!canvas) return;
10
11     //Shape 1
12     auto shape1 = tvg::Shape::gen();
13     shape1->appendRect(50, 50, 200, 200, 0, 0);
14     shape1->fill(50, 50, 50, 255);
15     shape1->stroke(255, 255, 255, 255);       //color: r, g, b, a
16     shape1->stroke(tvg::StrokeJoin::Bevel);   //default is Bevel
17     shape1->stroke(10);                       //width: 10px
18
19     if (canvas->push(move(shape1)) != tvg::Result::Success) return;
20
21     //Shape 2
22     auto shape2 = tvg::Shape::gen();
23     shape2->appendRect(300, 50, 200, 200, 0, 0);
24     shape2->fill(50, 50, 50, 255);
25     shape2->stroke(255, 255, 255, 255);
26     shape2->stroke(tvg::StrokeJoin::Round);
27     shape2->stroke(10);
28
29     if (canvas->push(move(shape2)) != tvg::Result::Success) return;
30
31     //Shape 3
32     auto shape3 = tvg::Shape::gen();
33     shape3->appendRect(550, 50, 200, 200, 0, 0);
34     shape3->fill(50, 50, 50, 255);
35     shape3->stroke(255, 255, 255, 255);
36     shape3->stroke(tvg::StrokeJoin::Miter);
37     shape3->stroke(10);
38
39     if (canvas->push(move(shape3)) != tvg::Result::Success) return;
40
41     //Shape 4
42     auto shape4 = tvg::Shape::gen();
43     shape4->appendCircle(150, 450, 100, 100);
44     shape4->fill(50, 50, 50, 255);
45     shape4->stroke(255, 255, 255, 255);
46     shape4->stroke(1);
47
48     if (canvas->push(move(shape4)) != tvg::Result::Success) return;
49
50     //Shape 5
51     auto shape5 = tvg::Shape::gen();
52     shape5->appendCircle(400, 450, 100, 100);
53     shape5->fill(50, 50, 50, 255);
54     shape5->stroke(255, 255, 255, 255);
55     shape5->stroke(2);
56
57     if (canvas->push(move(shape5)) != tvg::Result::Success) return;
58
59     //Shape 6
60     auto shape6 = tvg::Shape::gen();
61     shape6->appendCircle(650, 450, 100, 100);
62     shape6->fill(50, 50, 50, 255);
63     shape6->stroke(255, 255, 255, 255);
64     shape6->stroke(4);
65
66     if (canvas->push(move(shape6)) != tvg::Result::Success) return;
67 }
68
69
70 /************************************************************************/
71 /* Sw Engine Test Code                                                  */
72 /************************************************************************/
73
74 static unique_ptr<tvg::SwCanvas> swCanvas;
75
76 void tvgSwTest(uint32_t* buffer)
77 {
78     //Create a Canvas
79     swCanvas = tvg::SwCanvas::gen();
80     swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
81
82     /* Push the shape into the Canvas drawing list
83        When this shape is into the canvas list, the shape could update & prepare
84        internal data asynchronously for coming rendering.
85        Canvas keeps this shape node unless user call canvas->clear() */
86     tvgDrawCmds(swCanvas.get());
87 }
88
89 void drawSwView(void* data, Eo* obj)
90 {
91     if (swCanvas->draw() == tvg::Result::Success) {
92         swCanvas->sync();
93     }
94 }
95
96
97 /************************************************************************/
98 /* GL Engine Test Code                                                  */
99 /************************************************************************/
100
101 static unique_ptr<tvg::GlCanvas> glCanvas;
102
103 void initGLview(Evas_Object *obj)
104 {
105     static constexpr auto BPP = 4;
106
107     //Create a Canvas
108     glCanvas = tvg::GlCanvas::gen();
109     glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
110
111     /* Push the shape into the Canvas drawing list
112        When this shape is into the canvas list, the shape could update & prepare
113        internal data asynchronously for coming rendering.
114        Canvas keeps this shape node unless user call canvas->clear() */
115     tvgDrawCmds(glCanvas.get());
116 }
117
118 void drawGLview(Evas_Object *obj)
119 {
120     auto gl = elm_glview_gl_api_get(obj);
121     gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
122     gl->glClear(GL_COLOR_BUFFER_BIT);
123
124     if (glCanvas->draw() == tvg::Result::Success) {
125         glCanvas->sync();
126     }
127 }
128
129
130 /************************************************************************/
131 /* Main Code                                                            */
132 /************************************************************************/
133
134 int main(int argc, char **argv)
135 {
136     tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
137
138     if (argc > 1) {
139         if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
140     }
141
142     //Initialize ThorVG Engine
143     if (tvgEngine == tvg::CanvasEngine::Sw) {
144         cout << "tvg engine: software" << endl;
145     } else {
146         cout << "tvg engine: opengl" << endl;
147     }
148
149     //Threads Count
150     auto threads = std::thread::hardware_concurrency();
151
152     //Initialize ThorVG Engine
153     if (tvg::Initializer::init(tvgEngine, threads) == tvg::Result::Success) {
154
155         elm_init(argc, argv);
156
157         if (tvgEngine == tvg::CanvasEngine::Sw) {
158             createSwView();
159         } else {
160             createGlView();
161         }
162
163         elm_run();
164         elm_shutdown();
165
166         //Terminate ThorVG Engine
167         tvg::Initializer::term(tvgEngine);
168
169     } else {
170         cout << "engine is not supported" << endl;
171     }
172     return 0;
173 }