added lottie2gif converter for both cmake and meson build
[platform/core/uifw/lottie-player.git] / example / pathtest.cpp
1 /* 
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
3  * 
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  * 
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  * 
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17  */
18
19 #include "evasapp.h"
20 #include"vpath.h"
21 #include<iostream>
22 using namespace std;
23
24 EvasApp *APP;
25
26 static void
27 _on_resize(Ecore_Evas *ee)
28 {
29    int w, h;
30    ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
31    APP->resize(w, h);
32 }
33
34 class PathTest
35 {
36 public:
37   PathTest(EvasApp *app) {
38       mApp = app;
39       mShape = evas_vg_shape_add(mApp->root());
40   }
41   void setColor(int r, int g, int b, int a) {
42     evas_vg_node_color_set(mShape, r, g, b, a);
43   }
44
45   void setStrokeColor(int r, int g, int b, int a) {
46     evas_vg_shape_stroke_color_set(mShape, r, g, b, a);
47   }
48
49   void setStrokeWidth(int w) {
50     evas_vg_shape_stroke_width_set(mShape, w);
51   }
52
53   void setPath(const VPath &path) {
54     Efl_VG  *shape = mShape;
55     evas_vg_shape_reset(shape);
56     const std::vector<VPath::Element> &elm = path.elements();
57     const std::vector<VPointF> &pts  = path.points();
58     int i=0;
59     for (auto e : elm) {
60       switch(e) {
61         case VPath::Element::MoveTo:
62             {
63                 VPointF p = pts[i++];
64                 evas_vg_shape_append_move_to(shape, p.x(), p.y());
65                 break;
66             }
67         case VPath::Element::LineTo:
68             {
69                 VPointF p = pts[i++];
70                 evas_vg_shape_append_line_to(shape, p.x(), p.y());
71                 break;
72             }
73         case VPath::Element::CubicTo:
74             {
75                 VPointF p = pts[i++];
76                 VPointF p1 = pts[i++];
77                 VPointF p2 = pts[i++];
78                 evas_vg_shape_append_cubic_to(shape, p.x(), p.y(), p1.x(), p1.y(), p2.x(), p2.y());
79                 break;
80             }
81         case VPath::Element::Close:
82             {
83                 evas_vg_shape_append_close(shape);
84                 break;
85             }
86       }
87     }
88   }
89
90 public:
91   EvasApp *mApp;
92   Efl_VG  *mShape;
93 };
94
95 int
96 main(void)
97 {
98    APP = new EvasApp(800, 800);
99    ecore_evas_callback_resize_set(APP->mEcoreEvas, _on_resize);
100    APP->setup();
101
102    VPath path;
103    path.addRoundRect(VRectF(100, 100, 200, 200), 20, 20, VPath::Direction::CCW);
104    path.addCircle(50, 50, 20, VPath::Direction::CCW);
105
106    path.addOval(VRectF(300, 100, 100, 50), VPath::Direction::CCW);
107
108    path.addPolystar(15.0, 106.0, 34.0, 0.0, 150,
109                     150, 231.0, 88.0, VPath::Direction::CW);
110
111    PathTest test(APP);
112    test.setPath(path);
113    test.setColor(255, 0, 0, 255);
114    test.setStrokeColor(200, 200, 0, 200);
115    test.setStrokeWidth(5);
116
117
118    APP->run();
119    delete APP;
120    return 0;
121 }
122
123
124
125
126