1 #include "rive/component.hpp"
2 #include "rive/artboard.hpp"
3 #include "rive/container_component.hpp"
4 #include "rive/core_context.hpp"
5 #include "rive/importers/artboard_importer.hpp"
6 #include "rive/importers/import_stack.hpp"
11 StatusCode Component::onAddedDirty(CoreContext* context) {
12 m_Artboard = static_cast<Artboard*>(context);
13 if (this == m_Artboard) {
14 // We're the artboard, don't parent to ourselves.
15 return StatusCode::Ok;
17 auto coreObject = context->resolve(parentId());
18 if (coreObject == nullptr || !coreObject->is<ContainerComponent>()) {
19 return StatusCode::MissingObject;
21 m_Parent = reinterpret_cast<ContainerComponent*>(coreObject);
22 return StatusCode::Ok;
25 void Component::addDependent(Component* component) {
26 // Make it's not already a dependent.
27 if (std::find(m_Dependents.begin(), m_Dependents.end(), component) != m_Dependents.end()) {
30 m_Dependents.push_back(component);
33 bool Component::addDirt(ComponentDirt value, bool recurse) {
34 if ((m_Dirt & value) == value) {
39 // Make sure dirt is set before calling anything that can set more dirt.
44 m_Artboard->onComponentDirty(this);
50 for (auto d : m_Dependents) {
51 d->addDirt(value, true);
56 StatusCode Component::import(ImportStack& importStack) {
58 // Artboards are always their first object.
59 assert(as<Artboard>()->objects().size() == 0);
60 as<Artboard>()->addObject(this);
61 return Super::import(importStack);
64 auto artboardImporter = importStack.latest<ArtboardImporter>(ArtboardBase::typeKey);
65 if (artboardImporter == nullptr) {
66 return StatusCode::MissingObject;
68 artboardImporter->addComponent(this);
69 return Super::import(importStack);