Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / rive-cpp / src / component.cpp
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"
7 #include <algorithm>
8
9 using namespace rive;
10
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;
16     }
17     auto coreObject = context->resolve(parentId());
18     if (coreObject == nullptr || !coreObject->is<ContainerComponent>()) {
19         return StatusCode::MissingObject;
20     }
21     m_Parent = reinterpret_cast<ContainerComponent*>(coreObject);
22     return StatusCode::Ok;
23 }
24
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()) {
28         return;
29     }
30     m_Dependents.push_back(component);
31 }
32
33 bool Component::addDirt(ComponentDirt value, bool recurse) {
34     if ((m_Dirt & value) == value) {
35         // Already marked.
36         return false;
37     }
38
39     // Make sure dirt is set before calling anything that can set more dirt.
40     m_Dirt |= value;
41
42     onDirty(m_Dirt);
43
44     m_Artboard->onComponentDirty(this);
45
46     if (!recurse) {
47         return true;
48     }
49
50     for (auto d : m_Dependents) {
51         d->addDirt(value, true);
52     }
53     return true;
54 }
55
56 StatusCode Component::import(ImportStack& importStack) {
57     if (is<Artboard>()) {
58         // Artboards are always their first object.
59         assert(as<Artboard>()->objects().size() == 0);
60         as<Artboard>()->addObject(this);
61         return Super::import(importStack);
62     }
63
64     auto artboardImporter = importStack.latest<ArtboardImporter>(ArtboardBase::typeKey);
65     if (artboardImporter == nullptr) {
66         return StatusCode::MissingObject;
67     }
68     artboardImporter->addComponent(this);
69     return Super::import(importStack);
70 }