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