Unnecessary export removal
[platform/core/uifw/dali-core.git] / dali / internal / event / animation / constraint-impl.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/event/animation/constraint-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <boost/function.hpp>
23
24 // INTERNAL INCLUDES
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>
35
36 namespace
37 {
38 // Constraint Interpolation function prototypes
39 typedef boost::function<bool (const bool& start, const bool& target, float progress)> BoolInterpolator;
40 typedef boost::function<float (const float& start, const float& target, float progress)> FloatInterpolator;
41 typedef boost::function<int (const int& start, const int& target, float progress)> IntegerInterpolator;
42 typedef boost::function<Dali::Vector2 (const Dali::Vector2& current, const Dali::Vector2& target, float progress)> Vector2Interpolator;
43 typedef boost::function<Dali::Vector3 (const Dali::Vector3& current, const Dali::Vector3& target, float progress)> Vector3Interpolator;
44 typedef boost::function<Dali::Vector4 (const Dali::Vector4& current, const Dali::Vector4& target, float progress)> Vector4Interpolator;
45 typedef boost::function<Dali::Quaternion (const Dali::Quaternion& current, const Dali::Quaternion& target, float progress)> QuaternionInterpolator;
46 typedef boost::function<Dali::Matrix3 (const Dali::Matrix3& current, const Dali::Matrix3& target, float progress)> Matrix3Interpolator;
47 typedef boost::function<Dali::Matrix (const Dali::Matrix& current, const Dali::Matrix& target, float progress)> MatrixInterpolator;
48
49 }
50
51 namespace Dali
52 {
53
54 namespace Internal
55 {
56
57 namespace // unnamed namespace
58 {
59
60 template <class P>
61 PropertyConstraintBase<P>* CreatePropertyConstraint( Constraint::AnyFunction& func, unsigned int sourceCount )
62 {
63   PropertyConstraintBase<P>* propertyConstraint( NULL );
64
65   switch ( sourceCount )
66   {
67     case 0u:
68     {
69       propertyConstraint = new PropertyConstraint0<P>( AnyCast<boost::function<P (const P&)> >( func ) );
70       break;
71     }
72
73     case 1u:
74     {
75       propertyConstraint = new PropertyConstraint1<P, PropertyInputAccessor>( AnyCast< boost::function<P (const P&,
76                                                                                                                   const PropertyInput&)> >( func ) );
77       break;
78     }
79
80     case 2u:
81     {
82       propertyConstraint = new PropertyConstraint2<P, PropertyInputAccessor>( AnyCast< boost::function<P (const P&,
83                                                                                                                   const PropertyInput&,
84                                                                                                                   const PropertyInput&)> >( func ) );
85       break;
86     }
87
88     case 3u:
89     {
90       propertyConstraint = new PropertyConstraint3<P, PropertyInputAccessor>( AnyCast< boost::function<P (const P&,
91                                                                                                                   const PropertyInput&,
92                                                                                                                   const PropertyInput&,
93                                                                                                                   const PropertyInput&)> >( func ) );
94       break;
95     }
96
97     case 4u:
98     {
99       propertyConstraint = new PropertyConstraint4<P, PropertyInputAccessor>( AnyCast< boost::function<P (const P&,
100                                                                                                                   const PropertyInput&,
101                                                                                                                   const PropertyInput&,
102                                                                                                                   const PropertyInput&,
103                                                                                                                   const PropertyInput&)> >( func ) );
104       break;
105     }
106
107     case 5u:
108     {
109       propertyConstraint = new PropertyConstraint5<P, PropertyInputAccessor>( AnyCast< boost::function<P (const P&,
110                                                                                                                   const PropertyInput&,
111                                                                                                                   const PropertyInput&,
112                                                                                                                   const PropertyInput&,
113                                                                                                                   const PropertyInput&,
114                                                                                                                   const PropertyInput&)> >( func ) );
115       break;
116     }
117
118     case 6u:
119     {
120       propertyConstraint = new PropertyConstraint6<P, PropertyInputAccessor>( AnyCast< boost::function<P (const P&,
121                                                                                                                   const PropertyInput&,
122                                                                                                                   const PropertyInput&,
123                                                                                                                   const PropertyInput&,
124                                                                                                                   const PropertyInput&,
125                                                                                                                   const PropertyInput&,
126                                                                                                                   const PropertyInput&)> >( func ) );
127       break;
128     }
129
130
131     default:
132     {
133       // should never come here
134       DALI_ASSERT_ALWAYS( false && "Cannot have more than 6 property constraints" );
135       break;
136     }
137   }
138
139   return propertyConstraint;
140 }
141
142 } // unnamed namespace
143
144 Constraint::Constraint( Property::Index targetIndex,
145                         Property::Type targetType,
146                         SourceContainer& sources,
147                         AnyFunction& func,
148                         AnyFunction& interpolator )
149 : mApplyTime( 0.0f )
150 {
151   switch ( targetType )
152   {
153     case Property::BOOLEAN:
154     {
155       PropertyConstraintPtr<bool>::Type funcPtr( CreatePropertyConstraint<bool>( func, sources.size() ) );
156
157       mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint<bool>::New( targetIndex,
158                                                                                        sources,
159                                                                                        funcPtr,
160                                                                                        AnyCast< BoolInterpolator >( interpolator ) ) );
161       break;
162     }
163
164     case Property::FLOAT:
165     {
166       PropertyConstraintPtr<float>::Type funcPtr( CreatePropertyConstraint<float>( func, sources.size() ) );
167
168       mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint<float>::New( targetIndex,
169                                                                                         sources,
170                                                                                         funcPtr,
171                                                                                         AnyCast< FloatInterpolator >( interpolator ) ) );
172       break;
173     }
174
175     case Property::INTEGER:
176     {
177       PropertyConstraintPtr<int>::Type funcPtr( CreatePropertyConstraint<int>( func, sources.size() ) );
178
179       mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint<int>::New( targetIndex,
180                                                                                       sources,
181                                                                                       funcPtr,
182                                                                                       AnyCast< IntegerInterpolator >( interpolator ) ) );
183       break;
184     }
185
186     case Property::VECTOR2:
187     {
188       PropertyConstraintPtr<Vector2>::Type funcPtr( CreatePropertyConstraint<Vector2>( func, sources.size() ) );
189
190       mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint<Vector2>::New( targetIndex,
191                                                                                           sources,
192                                                                                           funcPtr,
193                                                                                           AnyCast< Vector2Interpolator >( interpolator ) ) );
194       break;
195     }
196
197     case Property::VECTOR3:
198     {
199       PropertyConstraintPtr<Vector3>::Type funcPtr( CreatePropertyConstraint<Vector3>( func, sources.size() ) );
200
201       mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint<Vector3>::New( targetIndex,
202                                                                                           sources,
203                                                                                           funcPtr,
204                                                                                           AnyCast< Vector3Interpolator >( interpolator ) ) );
205       break;
206     }
207
208     case Property::VECTOR4:
209     {
210       PropertyConstraintPtr<Vector4>::Type funcPtr( CreatePropertyConstraint<Vector4>( func, sources.size() ) );
211
212       mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint<Vector4>::New( targetIndex,
213                                                                                           sources,
214                                                                                           funcPtr,
215                                                                                           AnyCast< Vector4Interpolator >( interpolator ) ) );
216       break;
217     }
218
219     case Property::ROTATION:
220     {
221       PropertyConstraintPtr<Quaternion>::Type funcPtr( CreatePropertyConstraint<Quaternion>( func, sources.size() ) );
222
223       mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint<Quaternion>::New( targetIndex,
224                                                                                              sources,
225                                                                                              funcPtr,
226                                                                                              AnyCast< QuaternionInterpolator >( interpolator ) ) );
227       break;
228     }
229
230     case Property::MATRIX:
231     {
232       PropertyConstraintPtr<Matrix>::Type funcPtr( CreatePropertyConstraint<Matrix>( func, sources.size() ) );
233
234       mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint<Matrix>::New( targetIndex,
235                                                                                          sources,
236                                                                                          funcPtr,
237                                                                                          AnyCast< MatrixInterpolator >( interpolator ) ) );
238       break;
239     }
240
241     case Property::MATRIX3:
242     {
243       PropertyConstraintPtr<Matrix3>::Type funcPtr( CreatePropertyConstraint<Matrix3>( func, sources.size() ) );
244
245       mActiveConstraintTemplate = Dali::ActiveConstraint( ActiveConstraint<Matrix3>::New( targetIndex,
246                                                                                           sources,
247                                                                                           funcPtr,
248                                                                                           AnyCast< Matrix3Interpolator >( interpolator ) ) );
249       break;
250     }
251
252     default:
253     {
254       DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should never come here
255       break;
256     }
257   }
258 }
259
260 ActiveConstraintBase* Constraint::CreateActiveConstraint()
261 {
262   return GetImplementation( mActiveConstraintTemplate ).Clone();
263 }
264
265 void Constraint::SetApplyTime( TimePeriod timePeriod )
266 {
267   mApplyTime = timePeriod;
268 }
269
270 TimePeriod Constraint::GetApplyTime() const
271 {
272   return mApplyTime;
273 }
274
275 void Constraint::SetAlphaFunction( Dali::AlphaFunction func )
276 {
277   GetImplementation( mActiveConstraintTemplate ).SetAlphaFunction( func );
278 }
279
280 Dali::AlphaFunction Constraint::GetAlphaFunction() const
281 {
282   return GetImplementation( mActiveConstraintTemplate ).GetAlphaFunction();
283 }
284
285 void Constraint::SetRemoveAction( Dali::Constraint::RemoveAction action )
286 {
287   GetImplementation( mActiveConstraintTemplate ).SetRemoveAction( action );
288 }
289
290 Dali::Constraint::RemoveAction Constraint::GetRemoveAction() const
291 {
292   return GetImplementation( mActiveConstraintTemplate ).GetRemoveAction();
293 }
294
295
296 void Constraint::SetTag(unsigned int tag)
297 {
298   GetImplementation( mActiveConstraintTemplate ).SetTag(tag);
299 }
300
301 unsigned int Constraint::GetTag() const
302 {
303   return GetImplementation( mActiveConstraintTemplate ).GetTag();
304 }
305
306
307
308 Constraint::~Constraint()
309 {
310 }
311
312 } // namespace Internal
313
314 } // namespace Dali