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>
29 #include <dali/public-api/math/vector2.h>
30 #include <dali/public-api/math/vector3.h>
31 #include <dali/public-api/math/vector4.h>
32 #include <dali/public-api/math/quaternion.h>
33 #include <dali/public-api/math/matrix.h>
34 #include <dali/public-api/math/matrix3.h>
42 namespace // unnamed namespace
46 PropertyConstraintBase<P>* CreatePropertyConstraint( Constraint::AnyFunction& func, unsigned int sourceCount )
48 PropertyConstraintBase<P>* propertyConstraint( NULL );
50 switch ( sourceCount )
54 propertyConstraint = new PropertyConstraint0<P>( AnyCast<boost::function<P (const P&)> >( func ) );
60 propertyConstraint = new PropertyConstraint1<P, PropertyInputAccessor>( AnyCast< boost::function<P (const P&,
61 const PropertyInput&)> >( func ) );
67 propertyConstraint = new PropertyConstraint2<P, PropertyInputAccessor>( AnyCast< boost::function<P (const P&,
69 const PropertyInput&)> >( func ) );
75 propertyConstraint = new PropertyConstraint3<P, PropertyInputAccessor>( AnyCast< boost::function<P (const P&,
78 const PropertyInput&)> >( func ) );
84 propertyConstraint = new PropertyConstraint4<P, PropertyInputAccessor>( AnyCast< boost::function<P (const P&,
88 const PropertyInput&)> >( func ) );
94 propertyConstraint = new PropertyConstraint5<P, PropertyInputAccessor>( AnyCast< boost::function<P (const P&,
99 const PropertyInput&)> >( func ) );
105 propertyConstraint = new PropertyConstraint6<P, PropertyInputAccessor>( AnyCast< boost::function<P (const P&,
106 const PropertyInput&,
107 const PropertyInput&,
108 const PropertyInput&,
109 const PropertyInput&,
110 const PropertyInput&,
111 const PropertyInput&)> >( func ) );
118 // should never come here
119 DALI_ASSERT_ALWAYS( false && "Cannot have more than 6 property constraints" );
124 return propertyConstraint;
127 } // unnamed namespace
129 Constraint::Constraint( Property::Index targetIndex,
130 Property::Type targetType,
131 SourceContainer& sources,
135 switch ( targetType )
137 case Property::BOOLEAN:
139 PropertyConstraintPtr<bool>::Type funcPtr( CreatePropertyConstraint<bool>( func, sources.size() ) );
141 mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint<bool>::New( targetIndex,
147 case Property::FLOAT:
149 PropertyConstraintPtr<float>::Type funcPtr( CreatePropertyConstraint<float>( func, sources.size() ) );
151 mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint<float>::New( targetIndex,
157 case Property::INTEGER:
159 PropertyConstraintPtr<int>::Type funcPtr( CreatePropertyConstraint<int>( func, sources.size() ) );
161 mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint<int>::New( targetIndex,
167 case Property::VECTOR2:
169 PropertyConstraintPtr<Vector2>::Type funcPtr( CreatePropertyConstraint<Vector2>( func, sources.size() ) );
171 mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint<Vector2>::New( targetIndex,
177 case Property::VECTOR3:
179 PropertyConstraintPtr<Vector3>::Type funcPtr( CreatePropertyConstraint<Vector3>( func, sources.size() ) );
181 mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint<Vector3>::New( targetIndex,
187 case Property::VECTOR4:
189 PropertyConstraintPtr<Vector4>::Type funcPtr( CreatePropertyConstraint<Vector4>( func, sources.size() ) );
191 mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint<Vector4>::New( targetIndex,
197 case Property::ROTATION:
199 PropertyConstraintPtr<Quaternion>::Type funcPtr( CreatePropertyConstraint<Quaternion>( func, sources.size() ) );
201 mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint<Quaternion>::New( targetIndex,
207 case Property::MATRIX:
209 PropertyConstraintPtr<Matrix>::Type funcPtr( CreatePropertyConstraint<Matrix>( func, sources.size() ) );
211 mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint<Matrix>::New( targetIndex,
217 case Property::MATRIX3:
219 PropertyConstraintPtr<Matrix3>::Type funcPtr( CreatePropertyConstraint<Matrix3>( func, sources.size() ) );
221 mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint<Matrix3>::New( targetIndex,
229 DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should never come here
235 ActiveConstraintBase* Constraint::CreateActiveConstraint()
237 return GetImplementation( mActiveConstraintTemplate ).Clone();
240 void Constraint::SetApplyTime( TimePeriod timePeriod )
242 mApplyTime = timePeriod;
245 TimePeriod Constraint::GetApplyTime() const
250 void Constraint::SetAlphaFunction( Dali::AlphaFunction func )
252 GetImplementation( mActiveConstraintTemplate ).SetAlphaFunction( func );
255 Dali::AlphaFunction Constraint::GetAlphaFunction() const
257 return GetImplementation( mActiveConstraintTemplate ).GetAlphaFunction();
260 void Constraint::SetRemoveAction( Dali::Constraint::RemoveAction action )
262 GetImplementation( mActiveConstraintTemplate ).SetRemoveAction( action );
265 Dali::Constraint::RemoveAction Constraint::GetRemoveAction() const
267 return GetImplementation( mActiveConstraintTemplate ).GetRemoveAction();
271 void Constraint::SetTag(unsigned int tag)
273 GetImplementation( mActiveConstraintTemplate ).SetTag(tag);
276 unsigned int Constraint::GetTag() const
278 return GetImplementation( mActiveConstraintTemplate ).GetTag();
283 Constraint::~Constraint()
287 } // namespace Internal