/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/public-api/animation/constraint.h>
// INTERNAL INCLUDES
-#include <dali/public-api/animation/time-period.h>
#include <dali/internal/event/animation/constraint-impl.h>
#include <dali/internal/event/animation/constraint-source-impl.h>
+#include <dali/internal/event/animation/property-constraint-ptr.h>
+#include <dali/internal/event/animation/property-constraint.h>
namespace Dali
{
-
-const AlphaFunction Constraint::DEFAULT_ALPHA_FUNCTION = AlphaFunctions::Linear;
-const Constraint::RemoveAction Constraint::DEFAULT_REMOVE_ACTION = Constraint::Bake;
-
-Constraint::Constraint()
+namespace // unnamed namespace
{
-}
-
-Constraint::Constraint(Internal::Constraint* constraint)
-: BaseHandle(constraint)
+template<class P>
+Internal::PropertyConstraint<P>* CreatePropertyConstraint(CallbackBase* func)
{
+ return new Internal::PropertyConstraint<P>(reinterpret_cast<Dali::Constraint::Function<P>*>(func));
}
-Constraint::~Constraint()
-{
-}
+} // unnamed namespace
-Constraint::Constraint(const Constraint& handle)
-: BaseHandle(handle)
-{
-}
+const Constraint::RemoveAction Constraint::DEFAULT_REMOVE_ACTION = Constraint::BAKE;
-Constraint& Constraint::operator=(const Constraint& rhs)
-{
- BaseHandle::operator=(rhs);
- return *this;
-}
+Constraint::Constraint() = default;
-Constraint& Constraint::operator=(BaseHandle::NullType* rhs)
+Constraint Constraint::Clone(Handle object)
{
- DALI_ASSERT_ALWAYS( (rhs == NULL) && "Can only assign NULL pointer to handle");
- Reset();
- return *this;
+ return Constraint(GetImplementation(*this).Clone(GetImplementation(object)));
}
-void Constraint::SetApplyTime( TimePeriod timePeriod )
-{
- GetImplementation(*this).SetApplyTime( timePeriod );
-}
+Constraint::~Constraint() = default;
-TimePeriod Constraint::GetApplyTime() const
-{
- return GetImplementation(*this).GetApplyTime();
-}
+Constraint::Constraint(const Constraint& constraint) = default;
-void Constraint::SetRemoveTime( TimePeriod timePeriod )
-{
- GetImplementation(*this).SetRemoveTime( timePeriod );
-}
+Constraint& Constraint::operator=(const Constraint& rhs) = default;
-TimePeriod Constraint::GetRemoveTime() const
-{
- return GetImplementation(*this).GetRemoveTime();
-}
+Constraint::Constraint(Constraint&& rhs) noexcept = default;
-void Constraint::SetAlphaFunction( AlphaFunction func )
-{
- GetImplementation(*this).SetAlphaFunction( func );
-}
+Constraint& Constraint::operator=(Constraint&& rhs) noexcept = default;
-AlphaFunction Constraint::GetAlphaFunction()
+Constraint Constraint::DownCast(BaseHandle baseHandle)
{
- return GetImplementation(*this).GetAlphaFunction();
+ return Constraint(dynamic_cast<Dali::Internal::ConstraintBase*>(baseHandle.GetObjectPtr()));
}
-void Constraint::SetRemoveAction(Constraint::RemoveAction action)
+void Constraint::AddSource(ConstraintSource source)
{
- GetImplementation(*this).SetRemoveAction(action);
+ GetImplementation(*this).AddSource(Internal::Source(source));
}
-Constraint::RemoveAction Constraint::GetRemoveAction() const
+void Constraint::Apply()
{
- return GetImplementation(*this).GetRemoveAction();
+ GetImplementation(*this).Apply();
}
-void Constraint::SetTag( const unsigned int tag )
+void Constraint::Remove()
{
- GetImplementation(*this).SetTag( tag );
+ GetImplementation(*this).Remove();
}
-unsigned int Constraint::GetTag() const
+Handle Constraint::GetTargetObject()
{
- return GetImplementation(*this).GetTag();
+ return GetImplementation(*this).GetTargetObject();
}
-
-
-
-
-Constraint Constraint::New( Property::Index target,
- Property::Type targetType,
- AnyFunction func,
- AnyFunction interpolator )
+Property::Index Constraint::GetTargetProperty()
{
- Internal::SourceContainer sources; // empty
-
- return Constraint( new Internal::Constraint( target,
- targetType,
- sources,
- func,
- interpolator ) );
+ return GetImplementation(*this).GetTargetProperty();
}
-Constraint Constraint::New( Property::Index target,
- Property::Type targetType,
- ConstraintSource source1,
- AnyFunction func,
- AnyFunction interpolator )
+void Constraint::SetRemoveAction(Constraint::RemoveAction action)
{
- Internal::SourceContainer sources;
- sources.push_back( Internal::Source( source1 ) );
-
- return Constraint( new Internal::Constraint( target,
- targetType,
- sources,
- func,
- interpolator ) );
+ GetImplementation(*this).SetRemoveAction(action);
}
-Constraint Constraint::New( Property::Index target,
- Property::Type targetType,
- ConstraintSource source1,
- ConstraintSource source2,
- AnyFunction func,
- AnyFunction interpolator )
+Constraint::RemoveAction Constraint::GetRemoveAction() const
{
- Internal::SourceContainer sources;
- sources.push_back( Internal::Source( source1 ) );
- sources.push_back( Internal::Source( source2 ) );
-
- return Constraint( new Internal::Constraint( target,
- targetType,
- sources,
- func,
- interpolator ) );
+ return GetImplementation(*this).GetRemoveAction();
}
-Constraint Constraint::New( Property::Index target,
- Property::Type targetType,
- ConstraintSource source1,
- ConstraintSource source2,
- ConstraintSource source3,
- AnyFunction func,
- AnyFunction interpolator )
+void Constraint::SetTag(const uint32_t tag)
{
- Internal::SourceContainer sources;
- sources.push_back( Internal::Source( source1 ) );
- sources.push_back( Internal::Source( source2 ) );
- sources.push_back( Internal::Source( source3 ) );
-
- return Constraint( new Internal::Constraint( target,
- targetType,
- sources,
- func,
- interpolator ) );
+ GetImplementation(*this).SetTag(tag);
}
-Constraint Constraint::New( Property::Index target,
- Property::Type targetType,
- ConstraintSource source1,
- ConstraintSource source2,
- ConstraintSource source3,
- ConstraintSource source4,
- AnyFunction func,
- AnyFunction interpolator )
+uint32_t Constraint::GetTag() const
{
- Internal::SourceContainer sources;
- sources.push_back( Internal::Source( source1 ) );
- sources.push_back( Internal::Source( source2 ) );
- sources.push_back( Internal::Source( source3 ) );
- sources.push_back( Internal::Source( source4 ) );
-
- return Constraint( new Internal::Constraint( target,
- targetType,
- sources,
- func,
- interpolator ) );
+ return GetImplementation(*this).GetTag();
}
-Constraint Constraint::New( Property::Index target,
- Property::Type targetType,
- ConstraintSource source1,
- ConstraintSource source2,
- ConstraintSource source3,
- ConstraintSource source4,
- ConstraintSource source5,
- AnyFunction func,
- AnyFunction interpolator )
+Constraint::Constraint(Internal::ConstraintBase* constraint)
+: BaseHandle(constraint)
{
- Internal::SourceContainer sources;
- sources.push_back( Internal::Source( source1 ) );
- sources.push_back( Internal::Source( source2 ) );
- sources.push_back( Internal::Source( source3 ) );
- sources.push_back( Internal::Source( source4 ) );
- sources.push_back( Internal::Source( source5 ) );
-
- return Constraint( new Internal::Constraint( target,
- targetType,
- sources,
- func,
- interpolator ) );
}
-Constraint Constraint::New( Property::Index target,
- Property::Type targetType,
- ConstraintSource source1,
- ConstraintSource source2,
- ConstraintSource source3,
- ConstraintSource source4,
- ConstraintSource source5,
- ConstraintSource source6,
- AnyFunction func,
- AnyFunction interpolator )
+Constraint Constraint::New(Handle handle, Property::Index targetIndex, Property::Type targetType, CallbackBase* function)
{
+ Constraint constraint;
Internal::SourceContainer sources;
- sources.push_back( Internal::Source( source1 ) );
- sources.push_back( Internal::Source( source2 ) );
- sources.push_back( Internal::Source( source3 ) );
- sources.push_back( Internal::Source( source4 ) );
- sources.push_back( Internal::Source( source5 ) );
- sources.push_back( Internal::Source( source6 ) );
-
- return Constraint( new Internal::Constraint( target,
- targetType,
- sources,
- func,
- interpolator ) );
-}
-
-Constraint Constraint::DownCast( BaseHandle handle )
-{
- return Constraint( dynamic_cast<Dali::Internal::Constraint*>(handle.GetObjectPtr()) );
+ Internal::Object& object = GetImplementation(handle);
+
+ switch(targetType)
+ {
+ case Property::BOOLEAN:
+ {
+ Internal::PropertyConstraintPtr<bool>::Type funcPtr(CreatePropertyConstraint<bool>(function));
+
+ constraint = Dali::Constraint(Internal::Constraint<bool>::New(object,
+ targetIndex,
+ sources,
+ funcPtr));
+ break;
+ }
+
+ case Property::FLOAT:
+ {
+ Internal::PropertyConstraintPtr<float>::Type funcPtr(CreatePropertyConstraint<float>(function));
+
+ constraint = Dali::Constraint(Internal::Constraint<float>::New(object,
+ targetIndex,
+ sources,
+ funcPtr));
+ break;
+ }
+
+ case Property::INTEGER:
+ {
+ Internal::PropertyConstraintPtr<int>::Type funcPtr(CreatePropertyConstraint<int>(function));
+
+ constraint = Dali::Constraint(Internal::Constraint<int>::New(object,
+ targetIndex,
+ sources,
+ funcPtr));
+ break;
+ }
+
+ case Property::VECTOR2:
+ {
+ Internal::PropertyConstraintPtr<Vector2>::Type funcPtr(CreatePropertyConstraint<Vector2>(function));
+
+ constraint = Dali::Constraint(Internal::Constraint<Vector2>::New(object,
+ targetIndex,
+ sources,
+ funcPtr));
+ break;
+ }
+
+ case Property::VECTOR3:
+ {
+ Internal::PropertyConstraintPtr<Vector3>::Type funcPtr(CreatePropertyConstraint<Vector3>(function));
+
+ constraint = Dali::Constraint(Internal::Constraint<Vector3>::New(object,
+ targetIndex,
+ sources,
+ funcPtr));
+ break;
+ }
+
+ case Property::VECTOR4:
+ {
+ Internal::PropertyConstraintPtr<Vector4>::Type funcPtr(CreatePropertyConstraint<Vector4>(function));
+
+ constraint = Dali::Constraint(Internal::Constraint<Vector4>::New(object,
+ targetIndex,
+ sources,
+ funcPtr));
+ break;
+ }
+
+ case Property::ROTATION:
+ {
+ Internal::PropertyConstraintPtr<Quaternion>::Type funcPtr(CreatePropertyConstraint<Quaternion>(function));
+
+ constraint = Dali::Constraint(Internal::Constraint<Quaternion>::New(object,
+ targetIndex,
+ sources,
+ funcPtr));
+ break;
+ }
+
+ case Property::MATRIX:
+ {
+ Internal::PropertyConstraintPtr<Matrix>::Type funcPtr(CreatePropertyConstraint<Matrix>(function));
+
+ constraint = Dali::Constraint(Internal::Constraint<Matrix>::New(object,
+ targetIndex,
+ sources,
+ funcPtr));
+ break;
+ }
+
+ case Property::MATRIX3:
+ {
+ Internal::PropertyConstraintPtr<Matrix3>::Type funcPtr(CreatePropertyConstraint<Matrix3>(function));
+
+ constraint = Dali::Constraint(Internal::Constraint<Matrix3>::New(object,
+ targetIndex,
+ sources,
+ funcPtr));
+ break;
+ }
+
+ default:
+ {
+ DALI_ABORT("Property not constrainable");
+ break;
+ }
+ }
+
+ return constraint;
}
} // namespace Dali