lottie/render: handle AlphaInverse matte for composition layer.
[platform/core/uifw/lottie-player.git] / example / pathtest.cpp
1 #include "evasapp.h"
2 #include"vpath.h"
3 #include<iostream>
4 using namespace std;
5
6 EvasApp *APP;
7
8 static void
9 _on_resize(Ecore_Evas *ee)
10 {
11    int w, h;
12    ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
13    APP->resize(w, h);
14 }
15
16 class PathTest
17 {
18 public:
19   PathTest(EvasApp *app) {
20       mApp = app;
21       mShape = evas_vg_shape_add(mApp->root());
22   }
23   void setColor(int r, int g, int b, int a) {
24     evas_vg_node_color_set(mShape, r, g, b, a);
25   }
26
27   void setStrokeColor(int r, int g, int b, int a) {
28     evas_vg_shape_stroke_color_set(mShape, r, g, b, a);
29   }
30
31   void setStrokeWidth(int w) {
32     evas_vg_shape_stroke_width_set(mShape, w);
33   }
34
35   void setPath(const VPath &path) {
36     Efl_VG  *shape = mShape;
37     evas_vg_shape_reset(shape);
38     const std::vector<VPath::Element> &elm = path.elements();
39     const std::vector<VPointF> &pts  = path.points();
40     int i=0;
41     for (auto e : elm) {
42       switch(e) {
43         case VPath::Element::MoveTo:
44             {
45                 VPointF p = pts[i++];
46                 evas_vg_shape_append_move_to(shape, p.x(), p.y());
47                 break;
48             }
49         case VPath::Element::LineTo:
50             {
51                 VPointF p = pts[i++];
52                 evas_vg_shape_append_line_to(shape, p.x(), p.y());
53                 break;
54             }
55         case VPath::Element::CubicTo:
56             {
57                 VPointF p = pts[i++];
58                 VPointF p1 = pts[i++];
59                 VPointF p2 = pts[i++];
60                 evas_vg_shape_append_cubic_to(shape, p.x(), p.y(), p1.x(), p1.y(), p2.x(), p2.y());
61                 break;
62             }
63         case VPath::Element::Close:
64             {
65                 evas_vg_shape_append_close(shape);
66                 break;
67             }
68       }
69     }
70   }
71
72 public:
73   EvasApp *mApp;
74   Efl_VG  *mShape;
75 };
76
77 int
78 main(void)
79 {
80    APP = new EvasApp(800, 800);
81    ecore_evas_callback_resize_set(APP->mEcoreEvas, _on_resize);
82    APP->setup();
83
84    VPath path;
85    path.addRoundRect(VRectF(100, 100, 200, 200), 20, 20, VPath::Direction::CCW);
86    path.addCircle(50, 50, 20, VPath::Direction::CCW);
87
88    path.addOval(VRectF(300, 100, 100, 50), VPath::Direction::CCW);
89
90    path.addPolystar(15.0, 106.0, 34.0, 0.0, 150,
91                     150, 231.0, 88.0, VPath::Direction::CW);
92
93    PathTest test(APP);
94    test.setPath(path);
95    test.setColor(255, 0, 0, 255);
96    test.setStrokeColor(200, 200, 0, 200);
97    test.setStrokeWidth(5);
98
99
100    APP->run();
101    delete APP;
102    return 0;
103 }
104
105
106
107
108