bindings/capi: fix c compatibility warnings.
[platform/core/graphics/tizenvg.git] / test / testStrokeLine.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     //Test for Stroke Width
12     for (int i = 0; i < 10; ++i) {
13         auto shape = tvg::Shape::gen();
14         shape->moveTo(50, 50 + (25 * i));
15         shape->lineTo(750, 50 + (25 * i));
16         shape->stroke(255, 255, 255, 255);       //color: r, g, b, a
17         shape->stroke(i + 1);                    //stroke width
18         shape->stroke(tvg::StrokeCap::Round);    //default is Square
19         if (canvas->push(move(shape)) != tvg::Result::Success) return;
20     }
21
22     //Test for StrokeJoin & StrokeCap
23     auto shape1 = tvg::Shape::gen();
24     shape1->moveTo(20, 350);
25     shape1->lineTo(250, 350);
26     shape1->lineTo(220, 500);
27     shape1->lineTo(70, 470);
28     shape1->lineTo(70, 330);
29     shape1->stroke(255, 0, 0, 255);
30     shape1->stroke(10);
31     shape1->stroke(tvg::StrokeJoin::Round);
32     shape1->stroke(tvg::StrokeCap::Round);
33     if (canvas->push(move(shape1)) != tvg::Result::Success) return;
34
35     auto shape2 = tvg::Shape::gen();
36     shape2->moveTo(270, 350);
37     shape2->lineTo(500, 350);
38     shape2->lineTo(470, 500);
39     shape2->lineTo(320, 470);
40     shape2->lineTo(320, 330);
41     shape2->stroke(255, 255, 0, 255);
42     shape2->stroke(10);
43     shape2->stroke(tvg::StrokeJoin::Bevel);
44     shape2->stroke(tvg::StrokeCap::Square);
45     if (canvas->push(move(shape2)) != tvg::Result::Success) return;
46
47     auto shape3 = tvg::Shape::gen();
48     shape3->moveTo(520, 350);
49     shape3->lineTo(750, 350);
50     shape3->lineTo(720, 500);
51     shape3->lineTo(570, 470);
52     shape3->lineTo(570, 330);
53     shape3->stroke(0, 255, 0, 255);
54     shape3->stroke(10);
55     shape3->stroke(tvg::StrokeJoin::Miter);
56     shape3->stroke(tvg::StrokeCap::Butt);
57     if (canvas->push(move(shape3)) != tvg::Result::Success) return;
58
59     //Test for Stroke Dash
60     auto shape4 = tvg::Shape::gen();
61     shape4->moveTo(20, 600);
62     shape4->lineTo(250, 600);
63     shape4->lineTo(220, 750);
64     shape4->lineTo(70, 720);
65     shape4->lineTo(70, 580);
66     shape4->stroke(255, 0, 0, 255);
67     shape4->stroke(5);
68     shape4->stroke(tvg::StrokeJoin::Round);
69     shape4->stroke(tvg::StrokeCap::Round);
70
71     float dashPattern1[2] = {10, 10};
72     shape4->stroke(dashPattern1, 2);
73     if (canvas->push(move(shape4)) != tvg::Result::Success) return;
74
75     auto shape5 = tvg::Shape::gen();
76     shape5->moveTo(270, 600);
77     shape5->lineTo(500, 600);
78     shape5->lineTo(470, 750);
79     shape5->lineTo(320, 720);
80     shape5->lineTo(320, 580);
81     shape5->stroke(255, 255, 0, 255);
82     shape5->stroke(5);
83     shape5->stroke(tvg::StrokeJoin::Bevel);
84     shape5->stroke(tvg::StrokeCap::Butt);
85
86     float dashPattern2[2] = {10, 10};
87     shape5->stroke(dashPattern2, 2);
88     if (canvas->push(move(shape5)) != tvg::Result::Success) return;
89
90     auto shape6 = tvg::Shape::gen();
91     shape6->moveTo(520, 600);
92     shape6->lineTo(750, 600);
93     shape6->lineTo(720, 750);
94     shape6->lineTo(570, 720);
95     shape6->lineTo(570, 580);
96     shape6->stroke(255, 255, 255, 255);
97     shape6->stroke(5);
98     shape6->stroke(tvg::StrokeJoin::Miter);
99     shape6->stroke(tvg::StrokeCap::Square);
100
101     float dashPattern3[2] = {10, 10};
102     shape6->stroke(dashPattern3, 2);
103     if (canvas->push(move(shape6)) != tvg::Result::Success) return;
104 }
105
106
107 /************************************************************************/
108 /* Sw Engine Test Code                                                  */
109 /************************************************************************/
110
111 static unique_ptr<tvg::SwCanvas> swCanvas;
112
113 void tvgSwTest(uint32_t* buffer)
114 {
115     //Create a Canvas
116     swCanvas = tvg::SwCanvas::gen();
117     swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
118
119     /* Push the shape into the Canvas drawing list
120        When this shape is into the canvas list, the shape could update & prepare
121        internal data asynchronously for coming rendering.
122        Canvas keeps this shape node unless user call canvas->clear() */
123     tvgDrawCmds(swCanvas.get());
124 }
125
126 void drawSwView(void* data, Eo* obj)
127 {
128     if (swCanvas->draw() == tvg::Result::Success) {
129         swCanvas->sync();
130     }
131 }
132
133
134 /************************************************************************/
135 /* GL Engine Test Code                                                  */
136 /************************************************************************/
137
138 static unique_ptr<tvg::GlCanvas> glCanvas;
139
140 void initGLview(Evas_Object *obj)
141 {
142     static constexpr auto BPP = 4;
143
144     //Create a Canvas
145     glCanvas = tvg::GlCanvas::gen();
146     glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
147
148     /* Push the shape into the Canvas drawing list
149        When this shape is into the canvas list, the shape could update & prepare
150        internal data asynchronously for coming rendering.
151        Canvas keeps this shape node unless user call canvas->clear() */
152     tvgDrawCmds(glCanvas.get());
153 }
154
155 void drawGLview(Evas_Object *obj)
156 {
157     auto gl = elm_glview_gl_api_get(obj);
158     gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
159     gl->glClear(GL_COLOR_BUFFER_BIT);
160
161     if (glCanvas->draw() == tvg::Result::Success) {
162         glCanvas->sync();
163     }
164 }
165
166
167 /************************************************************************/
168 /* Main Code                                                            */
169 /************************************************************************/
170
171 int main(int argc, char **argv)
172 {
173     tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
174
175     if (argc > 1) {
176         if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
177     }
178
179     //Initialize ThorVG Engine
180     if (tvgEngine == tvg::CanvasEngine::Sw) {
181         cout << "tvg engine: software" << endl;
182     } else {
183         cout << "tvg engine: opengl" << endl;
184     }
185
186     //Threads Count
187     auto threads = std::thread::hardware_concurrency();
188
189     //Initialize ThorVG Engine
190     if (tvg::Initializer::init(tvgEngine, threads) == tvg::Result::Success) {
191
192
193         elm_init(argc, argv);
194
195         if (tvgEngine == tvg::CanvasEngine::Sw) {
196             createSwView();
197         } else {
198             createGlView();
199         }
200
201         elm_run();
202         elm_shutdown();
203
204         //Terminate ThorVG Engine
205         tvg::Initializer::term(tvgEngine);
206
207     } else {
208         cout << "engine is not supported" << endl;
209     }
210     return 0;
211 }