2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/event/animation/constraint-impl.h>
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>( AnyCast<boost::function<P (const P&)> >( func ) );
54 propertyConstraint = new PropertyConstraint1<P, PropertyInputAccessor>( AnyCast< boost::function<P (const P&,
55 const PropertyInput&)> >( func ) );
61 propertyConstraint = new PropertyConstraint2<P, PropertyInputAccessor>( AnyCast< boost::function<P (const P&,
63 const PropertyInput&)> >( func ) );
69 propertyConstraint = new PropertyConstraint3<P, PropertyInputAccessor>( AnyCast< boost::function<P (const P&,
72 const PropertyInput&)> >( func ) );
78 propertyConstraint = new PropertyConstraint4<P, PropertyInputAccessor>( AnyCast< boost::function<P (const P&,
82 const PropertyInput&)> >( func ) );
88 propertyConstraint = new PropertyConstraint5<P, PropertyInputAccessor>( AnyCast< boost::function<P (const P&,
93 const PropertyInput&)> >( func ) );
99 propertyConstraint = new PropertyConstraint6<P, PropertyInputAccessor>( AnyCast< 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 = Dali::ActiveConstraint( ActiveConstraint<bool>::New( targetIndex,
139 AnyCast< BoolInterpolator >( interpolator ) ) );
143 case Property::FLOAT:
145 PropertyConstraintPtr<float>::Type funcPtr( CreatePropertyConstraint<float>( func, sources.size() ) );
147 mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint<float>::New( targetIndex,
150 AnyCast< FloatInterpolator >( interpolator ) ) );
154 case Property::INTEGER:
156 PropertyConstraintPtr<int>::Type funcPtr( CreatePropertyConstraint<int>( func, sources.size() ) );
158 mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint<int>::New( targetIndex,
161 AnyCast< IntegerInterpolator >( interpolator ) ) );
165 case Property::VECTOR2:
167 PropertyConstraintPtr<Vector2>::Type funcPtr( CreatePropertyConstraint<Vector2>( func, sources.size() ) );
169 mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint<Vector2>::New( targetIndex,
172 AnyCast< Vector2Interpolator >( interpolator ) ) );
176 case Property::VECTOR3:
178 PropertyConstraintPtr<Vector3>::Type funcPtr( CreatePropertyConstraint<Vector3>( func, sources.size() ) );
180 mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint<Vector3>::New( targetIndex,
183 AnyCast< Vector3Interpolator >( interpolator ) ) );
187 case Property::VECTOR4:
189 PropertyConstraintPtr<Vector4>::Type funcPtr( CreatePropertyConstraint<Vector4>( func, sources.size() ) );
191 mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint<Vector4>::New( targetIndex,
194 AnyCast< Vector4Interpolator >( interpolator ) ) );
198 case Property::ROTATION:
200 PropertyConstraintPtr<Quaternion>::Type funcPtr( CreatePropertyConstraint<Quaternion>( func, sources.size() ) );
202 mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint<Quaternion>::New( targetIndex,
205 AnyCast< QuaternionInterpolator >( interpolator ) ) );
209 case Property::MATRIX:
211 PropertyConstraintPtr<Matrix>::Type funcPtr( CreatePropertyConstraint<Matrix>( func, sources.size() ) );
213 mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint<Matrix>::New( targetIndex,
216 AnyCast< MatrixInterpolator >( interpolator ) ) );
220 case Property::MATRIX3:
222 PropertyConstraintPtr<Matrix3>::Type funcPtr( CreatePropertyConstraint<Matrix3>( func, sources.size() ) );
224 mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint<Matrix3>::New( targetIndex,
227 AnyCast< Matrix3Interpolator >( interpolator ) ) );
233 DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should never come here
239 ActiveConstraintBase* Constraint::CreateActiveConstraint()
241 return GetImplementation( mActiveConstraintTemplate ).Clone();
244 void Constraint::SetApplyTime( TimePeriod timePeriod )
246 mApplyTime = timePeriod;
249 TimePeriod Constraint::GetApplyTime() const
254 void Constraint::SetAlphaFunction( Dali::AlphaFunction func )
256 GetImplementation( mActiveConstraintTemplate ).SetAlphaFunction( func );
259 Dali::AlphaFunction Constraint::GetAlphaFunction() const
261 return GetImplementation( mActiveConstraintTemplate ).GetAlphaFunction();
264 void Constraint::SetRemoveAction( Dali::Constraint::RemoveAction action )
266 GetImplementation( mActiveConstraintTemplate ).SetRemoveAction( action );
269 Dali::Constraint::RemoveAction Constraint::GetRemoveAction() const
271 return GetImplementation( mActiveConstraintTemplate ).GetRemoveAction();
275 void Constraint::SetTag(unsigned int tag)
277 GetImplementation( mActiveConstraintTemplate ).SetTag(tag);
280 unsigned int Constraint::GetTag() const
282 return GetImplementation( mActiveConstraintTemplate ).GetTag();
287 Constraint::~Constraint()
291 } // namespace Internal