up-to-date submodule(rive-cpp)
[platform/core/uifw/rive-tizen.git] / submodule / src / component.cpp
1 #include "component.hpp"
2 #include "artboard.hpp"
3 #include "container_component.hpp"
4 #include "core_context.hpp"
5 #include "importers/artboard_importer.hpp"
6 #include "importers/import_stack.hpp"
7 #include <algorithm>
8
9 using namespace rive;
10
11 StatusCode Component::onAddedDirty(CoreContext* context)
12 {
13         m_Artboard = static_cast<Artboard*>(context);
14         if (this == m_Artboard)
15         {
16                 // We're the artboard, don't parent to ourselves.
17                 return StatusCode::Ok;
18         }
19         auto coreObject = context->resolve(parentId());
20         if (coreObject == nullptr || !coreObject->is<ContainerComponent>())
21         {
22                 return StatusCode::MissingObject;
23         }
24         m_Parent = reinterpret_cast<ContainerComponent*>(coreObject);
25         return StatusCode::Ok;
26 }
27
28 void Component::addDependent(Component* component)
29 {
30         // Make it's not already a dependent.
31         assert(std::find(m_Dependents.begin(), m_Dependents.end(), component) ==
32                m_Dependents.end());
33         m_Dependents.push_back(component);
34 }
35
36 bool Component::addDirt(ComponentDirt value, bool recurse)
37 {
38         if ((m_Dirt & value) == value)
39         {
40                 // Already marked.
41                 return false;
42         }
43
44         // Make sure dirt is set before calling anything that can set more dirt.
45         m_Dirt |= value;
46
47         onDirty(m_Dirt);
48
49         m_Artboard->onComponentDirty(this);
50
51         if (!recurse)
52         {
53                 return true;
54         }
55
56         for (auto d : m_Dependents)
57         {
58                 d->addDirt(value, true);
59         }
60         return true;
61 }
62
63 StatusCode Component::import(ImportStack& importStack)
64 {
65         auto artboardImporter =
66             importStack.latest<ArtboardImporter>(ArtboardBase::typeKey);
67         if (artboardImporter == nullptr)
68         {
69                 return StatusCode::MissingObject;
70         }
71         artboardImporter->addComponent(this);
72         return Super::import(importStack);
73 }