Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / rive-cpp / include / rive / shapes / path.hpp
1 #ifndef _RIVE_PATH_HPP_
2 #define _RIVE_PATH_HPP_
3 #include "rive/command_path.hpp"
4 #include "rive/generated/shapes/path_base.hpp"
5 #include "rive/math/mat2d.hpp"
6 #include <vector>
7
8 namespace rive {
9     class Shape;
10     class PathVertex;
11
12 #ifdef ENABLE_QUERY_FLAT_VERTICES
13     /// Optionally compiled in for tools that need to compute per frame world
14     /// transformed path vertices. These should not be used at runtime as it's
15     /// not optimized for performance (it does a lot of memory allocation).
16
17     /// A flattened path is composed of only linear
18     /// and cubic vertices. No corner vertices and it's entirely in world space.
19     /// This is helpful for getting a close to identical representation of the
20     /// vertices used to issue the high level path draw commands.
21     class FlattenedPath {
22     private:
23         std::vector<PathVertex*> m_Vertices;
24
25     public:
26         ~FlattenedPath();
27
28         const std::vector<PathVertex*>& vertices() const { return m_Vertices; }
29         void addVertex(PathVertex* vertex, const Mat2D& transform);
30     };
31 #endif
32
33     class Path : public PathBase {
34     protected:
35         Shape* m_Shape = nullptr;
36         std::unique_ptr<CommandPath> m_CommandPath;
37         std::vector<PathVertex*> m_Vertices;
38
39     public:
40         Shape* shape() const { return m_Shape; }
41         StatusCode onAddedClean(CoreContext* context) override;
42         void buildDependencies() override;
43         virtual const Mat2D& pathTransform() const;
44         CommandPath* commandPath() const { return m_CommandPath.get(); }
45         void update(ComponentDirt value) override;
46
47         void addVertex(PathVertex* vertex);
48
49         virtual void markPathDirty();
50         virtual bool isPathClosed() const { return true; }
51         void onDirty(ComponentDirt dirt) override;
52 #ifdef ENABLE_QUERY_FLAT_VERTICES
53         FlattenedPath* makeFlat(bool transformToParent);
54 #endif
55
56 #ifdef TESTING
57         std::vector<PathVertex*>& vertices() { return m_Vertices; }
58 #endif
59
60         // pour ourselves into a command-path
61         void buildPath(CommandPath&) const;
62     };
63 } // namespace rive
64
65 #endif