0c1475605b08eff02df7688d9f53f0c783310a7c
[platform/core/uifw/rive-tizen.git] / src / renderer / include / thorvg_renderer.hpp
1 #ifndef _RIVE_THORVG_RENDERER_HPP_
2 #define _RIVE_THORVG_RENDERER_HPP_
3
4 #include <thorvg.h>
5 #include <vector>
6 #include "renderer.hpp"
7
8 namespace rive
9 {
10    enum ThorvgPathType 
11    {
12       MoveTo,
13       LineTo,
14       CubicTo,
15       Close
16    };
17
18    struct ThorvgPoint
19    {
20       float x, y;
21       ThorvgPoint(int _x, int _y) : x(_x), y(_y) { }
22    };
23
24    struct ThorvgPaint
25    {
26       int fillColor[4];
27       int strokeColor[4];
28       float thickness;
29       RenderPaintStyle style;
30       bool isFill;
31       bool isStroke;
32       ThorvgPaint() : isFill(false), isStroke(false) {}
33    };
34
35    class ThorvgRenderPath : public RenderPath
36    {
37    private:
38       tvg::Shape *m_Path;
39       std::vector<ThorvgPathType> m_PathType;
40       std::vector<ThorvgPoint> m_PathPoints;
41       bool m_Pushed;
42
43    public:
44       ThorvgRenderPath();
45       tvg::Shape* path() { return m_Path; }
46       bool getPushed() { return m_Pushed; }
47       bool setPushed(bool pushed) { m_Pushed = pushed; }
48       void reset() override;
49       void addRenderPath(RenderPath* path, const Mat2D& transform) override;
50       void fillRule(FillRule value) override;
51       void moveTo(float x, float y) override;
52       void lineTo(float x, float y) override;
53       void cubicTo(float ox, float oy, float ix, float iy, float x, float y) override;
54       virtual void close() override;
55    };
56
57    class ThorvgRenderPaint : public RenderPaint
58    {
59    private:
60       ThorvgPaint m_Paint;
61
62    public:
63       ThorvgRenderPaint();
64       ThorvgPaint* paint() { return &m_Paint; }
65       void style(RenderPaintStyle style) override;
66       void color(unsigned int value) override;
67       void thickness(float value) override;
68       void join(StrokeJoin value) override;
69       void cap(StrokeCap value) override;
70       void blendMode(BlendMode value) override;
71
72       void linearGradient(float sx, float sy, float ex, float ey) override;
73       void radialGradient(float sx, float sy, float ex, float ey) override;
74       void addStop(unsigned int color, float stop) override;
75       void completeGradient() override;
76    };
77
78    class ThorvgRenderer : public Renderer
79    {
80    private:
81       tvg::Canvas* m_Canvas;
82       rive::Mat2D m_Transform;
83
84    public:
85       ThorvgRenderer(tvg::Canvas* canvas) : m_Canvas(canvas) {}
86       void save() override;
87       void restore() override;
88       void transform(const Mat2D& transform) override;
89       void drawPath(RenderPath* path, RenderPaint* paint) override;
90       void clipPath(RenderPath* path) override;
91    };
92 } // namespace rive
93 #endif