X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Fpublic-api%2Fanimation%2Fconstraint.cpp;h=4951c7e98ba973678da7057753af74800be0114b;hb=646f736e77b085c86e982c0d1d4b895c2a431330;hp=2c8cc9819d96bdbd5818137975f04c221fdaa65b;hpb=2aca6c3748a55a07b3fb937aae35117e7207ddcf;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/public-api/animation/constraint.cpp b/dali/public-api/animation/constraint.cpp index 2c8cc98..4951c7e 100644 --- a/dali/public-api/animation/constraint.cpp +++ b/dali/public-api/animation/constraint.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 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. @@ -19,76 +19,79 @@ #include // INTERNAL INCLUDES -#include #include #include +#include +#include namespace Dali { -const AlphaFunction Constraint::DEFAULT_ALPHA_FUNCTION = AlphaFunctions::Linear; -const Constraint::RemoveAction Constraint::DEFAULT_REMOVE_ACTION = Constraint::Bake; +namespace // unnamed namespace +{ -Constraint::Constraint() +template < class P > +Internal::PropertyConstraint< P >* CreatePropertyConstraint( CallbackBase* func ) { + return new Internal::PropertyConstraint< P >( reinterpret_cast< Dali::Constraint::Function< P >* >( func ) ); } -Constraint::Constraint(Internal::Constraint* constraint) -: BaseHandle(constraint) +} // unnamed namespace + +const Constraint::RemoveAction Constraint::DEFAULT_REMOVE_ACTION = Constraint::Bake; + +Constraint::Constraint() { } -Constraint::~Constraint() +Constraint Constraint::Clone( Handle object ) { + return Constraint( GetImplementation( *this ).Clone( GetImplementation( object ) ) ); } -Constraint::Constraint(const Constraint& handle) -: BaseHandle(handle) +Constraint::~Constraint() { } -Constraint& Constraint::operator=(const Constraint& rhs) +Constraint::Constraint( const Constraint& constraint ) +: BaseHandle( constraint ) { - BaseHandle::operator=(rhs); - return *this; } -Constraint& Constraint::operator=(BaseHandle::NullType* rhs) +Constraint& Constraint::operator=( const Constraint& rhs ) { - DALI_ASSERT_ALWAYS( (rhs == NULL) && "Can only assign NULL pointer to handle"); - Reset(); + BaseHandle::operator=( rhs ); return *this; } -void Constraint::SetApplyTime( TimePeriod timePeriod ) +Constraint Constraint::DownCast( BaseHandle baseHandle ) { - GetImplementation(*this).SetApplyTime( timePeriod ); + return Constraint( dynamic_cast< Dali::Internal::ConstraintBase* >( baseHandle.GetObjectPtr() ) ); } -TimePeriod Constraint::GetApplyTime() const +void Constraint::AddSource( ConstraintSource source ) { - return GetImplementation(*this).GetApplyTime(); + GetImplementation( *this ).AddSource( Internal::Source( source ) ); } -void Constraint::SetRemoveTime( TimePeriod timePeriod ) +void Constraint::Apply() { - // TODO - Remove this deprecated method + GetImplementation( *this ).Apply(); } -TimePeriod Constraint::GetRemoveTime() const +void Constraint::Remove() { - // TODO - Remove this deprecated method - return TimePeriod(0.0f); + GetImplementation( *this ).Remove(); } -void Constraint::SetAlphaFunction( AlphaFunction func ) +Handle Constraint::GetTargetObject() { - GetImplementation(*this).SetAlphaFunction( func ); + return GetImplementation(*this).GetTargetObject(); } -AlphaFunction Constraint::GetAlphaFunction() +Property::Index Constraint::GetTargetProperty() { - return GetImplementation(*this).GetAlphaFunction(); + return GetImplementation(*this).GetTargetProperty(); } void Constraint::SetRemoveAction(Constraint::RemoveAction action) @@ -101,163 +104,136 @@ Constraint::RemoveAction Constraint::GetRemoveAction() const return GetImplementation(*this).GetRemoveAction(); } -void Constraint::SetTag( const unsigned int tag ) +void Constraint::SetTag( uint32_t tag ) { GetImplementation(*this).SetTag( tag ); } -unsigned int Constraint::GetTag() const +uint32_t Constraint::GetTag() const { return GetImplementation(*this).GetTag(); } - - - - -Constraint Constraint::New( Property::Index target, - Property::Type targetType, - AnyFunction func, - AnyFunction interpolator ) -{ - Internal::SourceContainer sources; // empty - - return Constraint( new Internal::Constraint( target, - targetType, - sources, - func, - interpolator ) ); -} - -Constraint Constraint::New( Property::Index target, - Property::Type targetType, - ConstraintSource source1, - AnyFunction func, - AnyFunction interpolator ) +Constraint::Constraint( Internal::ConstraintBase* constraint ) +: BaseHandle( constraint ) { - Internal::SourceContainer sources; - sources.push_back( Internal::Source( source1 ) ); - - return Constraint( new Internal::Constraint( target, - targetType, - sources, - func, - interpolator ) ); } -Constraint Constraint::New( Property::Index target, - Property::Type targetType, - ConstraintSource source1, - ConstraintSource source2, - 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 ) ); - - 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, - AnyFunction func, - AnyFunction interpolator ) -{ - 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 ) ); -} - -Constraint Constraint::New( Property::Index target, - Property::Type targetType, - ConstraintSource source1, - ConstraintSource source2, - ConstraintSource source3, - ConstraintSource source4, - AnyFunction func, - AnyFunction interpolator ) -{ - 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 ) ); -} - -Constraint Constraint::New( Property::Index target, - Property::Type targetType, - ConstraintSource source1, - ConstraintSource source2, - ConstraintSource source3, - ConstraintSource source4, - ConstraintSource source5, - AnyFunction func, - AnyFunction interpolator ) -{ - 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 ) -{ - 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(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::Type funcPtr( CreatePropertyConstraint( function ) ); + + constraint = Dali::Constraint( Internal::Constraint< Matrix3 >::New( object, + targetIndex, + sources, + funcPtr ) ); + break; + } + + default: + { + DALI_ABORT( "Property not constrainable" ); + break; + } + } + + return constraint; } } // namespace Dali