up-to-date submodule(rive-cpp)
[platform/core/uifw/rive-tizen.git] / submodule / include / artboard.hpp
1 #ifndef _RIVE_ARTBOARD_HPP_
2 #define _RIVE_ARTBOARD_HPP_
3 #include "animation/linear_animation.hpp"
4 #include "animation/state_machine.hpp"
5 #include "core_context.hpp"
6 #include "generated/artboard_base.hpp"
7 #include "math/aabb.hpp"
8 #include "renderer.hpp"
9 #include "shapes/shape_paint_container.hpp"
10 #include <vector>
11 namespace rive
12 {
13         class File;
14         class Drawable;
15         class Node;
16         class DrawTarget;
17
18         class Artboard : public ArtboardBase,
19                          public CoreContext,
20                          public ShapePaintContainer
21         {
22                 friend class File;
23
24         private:
25                 std::vector<Core*> m_Objects;
26                 std::vector<LinearAnimation*> m_Animations;
27                 std::vector<StateMachine*> m_StateMachines;
28                 std::vector<Component*> m_DependencyOrder;
29                 std::vector<Drawable*> m_Drawables;
30                 std::vector<DrawTarget*> m_DrawTargets;
31                 unsigned int m_DirtDepth = 0;
32                 CommandPath* m_BackgroundPath = nullptr;
33                 CommandPath* m_ClipPath = nullptr;
34                 Drawable* m_FirstDrawable = nullptr;
35
36                 void sortDependencies();
37                 void sortDrawOrder();
38
39         public:
40                 ~Artboard();
41                 StatusCode initialize();
42                 void addObject(Core* object);
43                 void addAnimation(LinearAnimation* object);
44                 void addStateMachine(StateMachine* object);
45
46                 Core* resolve(int id) const override;
47
48                 StatusCode onAddedClean(CoreContext* context) override
49                 {
50                         return StatusCode::Ok;
51                 }
52                 void onComponentDirty(Component* component);
53
54                 /// Update components that depend on each other in DAG order.
55                 bool updateComponents();
56                 void update(ComponentDirt value) override;
57                 void onDirty(ComponentDirt dirt) override;
58
59                 bool advance(double elapsedSeconds);
60                 void draw(Renderer* renderer);
61
62                 CommandPath* clipPath() const { return m_ClipPath; }
63                 CommandPath* backgroundPath() const { return m_BackgroundPath; }
64
65                 const std::vector<Core*>& objects() const { return m_Objects; }
66
67                 AABB bounds() const;
68
69                 template <typename T = Component> T* find(std::string name)
70                 {
71                         for (auto object : m_Objects)
72                         {
73                                 if (object != nullptr && object->is<T>() &&
74                                     object->as<T>()->name() == name)
75                                 {
76                                         return reinterpret_cast<T*>(object);
77                                 }
78                         }
79                         return nullptr;
80                 }
81
82                 LinearAnimation* firstAnimation();
83                 LinearAnimation* animation(std::string name);
84                 LinearAnimation* animation(size_t index);
85                 size_t animationCount() { return m_Animations.size(); }
86
87                 StateMachine* firstStateMachine();
88                 StateMachine* stateMachine(std::string name);
89                 StateMachine* stateMachine(size_t index);
90                 size_t stateMachineCount() { return m_StateMachines.size(); }
91         };
92 } // namespace rive
93
94 #endif