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"
18 class Artboard : public ArtboardBase,
20 public ShapePaintContainer
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;
36 void sortDependencies();
41 StatusCode initialize();
42 void addObject(Core* object);
43 void addAnimation(LinearAnimation* object);
44 void addStateMachine(StateMachine* object);
46 Core* resolve(int id) const override;
48 StatusCode onAddedClean(CoreContext* context) override
50 return StatusCode::Ok;
52 void onComponentDirty(Component* component);
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;
59 bool advance(double elapsedSeconds);
60 void draw(Renderer* renderer);
62 CommandPath* clipPath() const { return m_ClipPath; }
63 CommandPath* backgroundPath() const { return m_BackgroundPath; }
65 const std::vector<Core*>& objects() const { return m_Objects; }
69 template <typename T = Component> T* find(std::string name)
71 for (auto object : m_Objects)
73 if (object != nullptr && object->is<T>() &&
74 object->as<T>()->name() == name)
76 return reinterpret_cast<T*>(object);
82 LinearAnimation* firstAnimation();
83 LinearAnimation* animation(std::string name);
84 LinearAnimation* animation(size_t index);
85 size_t animationCount() { return m_Animations.size(); }
87 StateMachine* firstStateMachine();
88 StateMachine* stateMachine(std::string name);
89 StateMachine* stateMachine(size_t index);
90 size_t stateMachineCount() { return m_StateMachines.size(); }