2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 #include <dali/internal/event/animation/constraint-impl.h>
21 #include <boost/any.hpp>
22 #include <boost/function.hpp>
25 #include <dali/internal/event/animation/active-constraint-impl.h>
26 #include <dali/internal/event/animation/property-constraint-ptr.h>
27 #include <dali/internal/event/animation/property-constraint.h>
28 #include <dali/internal/event/animation/property-input-accessor.h>
36 namespace // unnamed namespace
40 PropertyConstraintBase<P>* CreatePropertyConstraint( Constraint::AnyFunction& func, unsigned int sourceCount )
42 PropertyConstraintBase<P>* propertyConstraint( NULL );
44 switch ( sourceCount )
48 propertyConstraint = new PropertyConstraint0<P>( boost::any_cast<boost::function<P (const P&)> >( func ) );
54 propertyConstraint = new PropertyConstraint1<P, PropertyInputAccessor>( boost::any_cast< boost::function<P (const P&,
55 const PropertyInput&)> >( func ) );
61 propertyConstraint = new PropertyConstraint2<P, PropertyInputAccessor>( boost::any_cast< boost::function<P (const P&,
63 const PropertyInput&)> >( func ) );
69 propertyConstraint = new PropertyConstraint3<P, PropertyInputAccessor>( boost::any_cast< boost::function<P (const P&,
72 const PropertyInput&)> >( func ) );
78 propertyConstraint = new PropertyConstraint4<P, PropertyInputAccessor>( boost::any_cast< boost::function<P (const P&,
82 const PropertyInput&)> >( func ) );
88 propertyConstraint = new PropertyConstraint5<P, PropertyInputAccessor>( boost::any_cast< boost::function<P (const P&,
93 const PropertyInput&)> >( func ) );
99 propertyConstraint = new PropertyConstraint6<P, PropertyInputAccessor>( boost::any_cast< boost::function<P (const P&,
100 const PropertyInput&,
101 const PropertyInput&,
102 const PropertyInput&,
103 const PropertyInput&,
104 const PropertyInput&,
105 const PropertyInput&)> >( func ) );
112 // should never come here
113 DALI_ASSERT_ALWAYS( false && "Cannot have more than 6 property constraints" );
118 return propertyConstraint;
121 } // unnamed namespace
123 Constraint::Constraint( Property::Index targetIndex,
124 Property::Type targetType,
125 SourceContainer& sources,
127 AnyFunction& interpolator )
130 switch ( targetType )
132 case Property::BOOLEAN:
134 PropertyConstraintPtr<bool>::Type funcPtr( CreatePropertyConstraint<bool>( func, sources.size() ) );
136 mActiveConstraintTemplate = ActiveConstraint<bool>::New( targetIndex,
139 boost::any_cast< BoolInterpolator >( interpolator ) );
143 case Property::FLOAT:
145 PropertyConstraintPtr<float>::Type funcPtr( CreatePropertyConstraint<float>( func, sources.size() ) );
147 mActiveConstraintTemplate = ActiveConstraint<float>::New( targetIndex,
150 boost::any_cast< FloatInterpolator >( interpolator ) );
154 case Property::VECTOR2:
156 PropertyConstraintPtr<Vector2>::Type funcPtr( CreatePropertyConstraint<Vector2>( func, sources.size() ) );
158 mActiveConstraintTemplate = ActiveConstraint<Vector2>::New( targetIndex,
161 boost::any_cast< Vector2Interpolator >( interpolator ) );
165 case Property::VECTOR3:
167 PropertyConstraintPtr<Vector3>::Type funcPtr( CreatePropertyConstraint<Vector3>( func, sources.size() ) );
169 mActiveConstraintTemplate = ActiveConstraint<Vector3>::New( targetIndex,
172 boost::any_cast< Vector3Interpolator >( interpolator ) );
176 case Property::VECTOR4:
178 PropertyConstraintPtr<Vector4>::Type funcPtr( CreatePropertyConstraint<Vector4>( func, sources.size() ) );
180 mActiveConstraintTemplate = ActiveConstraint<Vector4>::New( targetIndex,
183 boost::any_cast< Vector4Interpolator >( interpolator ) );
187 case Property::ROTATION:
189 PropertyConstraintPtr<Quaternion>::Type funcPtr( CreatePropertyConstraint<Quaternion>( func, sources.size() ) );
191 mActiveConstraintTemplate = ActiveConstraint<Quaternion>::New( targetIndex,
194 boost::any_cast< QuaternionInterpolator >( interpolator ) );
198 case Property::MATRIX:
200 PropertyConstraintPtr<Matrix>::Type funcPtr( CreatePropertyConstraint<Matrix>( func, sources.size() ) );
202 mActiveConstraintTemplate = ActiveConstraint<Matrix>::New( targetIndex,
205 boost::any_cast< MatrixInterpolator >( interpolator ) );
209 case Property::MATRIX3:
211 PropertyConstraintPtr<Matrix3>::Type funcPtr( CreatePropertyConstraint<Matrix3>( func, sources.size() ) );
213 mActiveConstraintTemplate = ActiveConstraint<Matrix3>::New( targetIndex,
216 boost::any_cast< Matrix3Interpolator >( interpolator ) );
222 DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should never come here
228 ActiveConstraintBase* Constraint::CreateActiveConstraint()
230 return GetImplementation( mActiveConstraintTemplate ).Clone();
233 void Constraint::SetApplyTime( TimePeriod timePeriod )
235 mApplyTime = timePeriod;
238 TimePeriod Constraint::GetApplyTime() const
243 void Constraint::SetRemoveTime( TimePeriod timePeriod )
245 GetImplementation( mActiveConstraintTemplate ).SetRemoveTime( timePeriod );
248 TimePeriod Constraint::GetRemoveTime() const
250 return GetImplementation( mActiveConstraintTemplate ).GetRemoveTime();
253 void Constraint::SetAlphaFunction( Dali::AlphaFunction func )
255 GetImplementation( mActiveConstraintTemplate ).SetAlphaFunction( func );
258 Dali::AlphaFunction Constraint::GetAlphaFunction() const
260 return GetImplementation( mActiveConstraintTemplate ).GetAlphaFunction();
263 void Constraint::SetRemoveAction( Dali::Constraint::RemoveAction action )
265 GetImplementation( mActiveConstraintTemplate ).SetRemoveAction( action );
268 Dali::Constraint::RemoveAction Constraint::GetRemoveAction() const
270 return GetImplementation( mActiveConstraintTemplate ).GetRemoveAction();
273 Constraint::~Constraint()
277 } // namespace Internal