blob: 292c63819ba0da46f339e5f445da9ae2e061eb92 [file] [log] [blame]
#include "rive/constraints/constraint.hpp"
#include "rive/container_component.hpp"
#include "rive/transform_component.hpp"
#include "rive/core_context.hpp"
#include "rive/artboard.hpp"
#include "rive/math/mat2d.hpp"
using namespace rive;
StatusCode Constraint::onAddedClean(CoreContext* context)
{
if (!parent()->is<TransformComponent>())
{
return StatusCode::InvalidObject;
}
parent()->as<TransformComponent>()->addConstraint(this);
return StatusCode::Ok;
}
void Constraint::markConstraintDirty()
{
parent()->as<TransformComponent>()->markTransformDirty();
}
void Constraint::strengthChanged() { markConstraintDirty(); }
void Constraint::buildDependencies()
{
Super::buildDependencies();
parent()->addDependent(this);
}
void Constraint::onDirty(ComponentDirt dirt)
{
// Whenever the constraint gets any dirt, make sure to mark the constrained
// component dirty.
markConstraintDirty();
}
static Mat2D identity;
const Mat2D& rive::getParentWorld(const TransformComponent& component)
{
auto parent = component.parent();
if (parent->is<Artboard>())
{
// TODO: when we have symbols working artboards will need to store their
// world transform (probably should just become TransformComponent).
return identity;
}
else
{
return parent->as<TransformComponent>()->worldTransform();
}
}