Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / rive-cpp / src / transform_component.cpp
1 #include "rive/transform_component.hpp"
2 #include "rive/world_transform_component.hpp"
3 #include "rive/shapes/clipping_shape.hpp"
4 #include "rive/math/vec2d.hpp"
5 #include "rive/constraints/constraint.hpp"
6
7 using namespace rive;
8
9 StatusCode TransformComponent::onAddedClean(CoreContext* context) {
10     m_ParentTransformComponent = parent() != nullptr && parent()->is<WorldTransformComponent>()
11                                      ? parent()->as<WorldTransformComponent>()
12                                      : nullptr;
13     return StatusCode::Ok;
14 }
15
16 void TransformComponent::buildDependencies() {
17     if (parent() != nullptr) {
18         parent()->addDependent(this);
19     }
20 }
21
22 void TransformComponent::markTransformDirty() {
23     if (!addDirt(ComponentDirt::Transform)) {
24         return;
25     }
26     markWorldTransformDirty();
27 }
28
29 void TransformComponent::updateTransform() {
30     m_Transform = Mat2D::fromRotation(rotation());
31     m_Transform[4] = x();
32     m_Transform[5] = y();
33     m_Transform.scaleByValues(scaleX(), scaleY());
34 }
35
36 void TransformComponent::updateWorldTransform() {
37     if (m_ParentTransformComponent != nullptr) {
38         m_WorldTransform = m_ParentTransformComponent->m_WorldTransform * m_Transform;
39     } else {
40         m_WorldTransform = m_Transform;
41     }
42
43     for (auto constraint : m_Constraints) {
44         constraint->constrain(this);
45     }
46 }
47
48 void TransformComponent::update(ComponentDirt value) {
49     if (hasDirt(value, ComponentDirt::Transform)) {
50         updateTransform();
51     }
52     if (hasDirt(value, ComponentDirt::WorldTransform)) {
53         updateWorldTransform();
54     }
55     if (hasDirt(value, ComponentDirt::RenderOpacity)) {
56         m_RenderOpacity = opacity();
57         if (m_ParentTransformComponent != nullptr) {
58             m_RenderOpacity *= m_ParentTransformComponent->childOpacity();
59         }
60     }
61 }
62
63 const Mat2D& TransformComponent::transform() const { return m_Transform; }
64
65 Mat2D& TransformComponent::mutableTransform() { return m_Transform; }
66
67 void TransformComponent::rotationChanged() { markTransformDirty(); }
68 void TransformComponent::scaleXChanged() { markTransformDirty(); }
69 void TransformComponent::scaleYChanged() { markTransformDirty(); }
70
71 void TransformComponent::addConstraint(Constraint* constraint) {
72     m_Constraints.push_back(constraint);
73 }