Added funcionality to play animations from an specified initial progress
[platform/core/uifw/dali-core.git] / dali / public-api / animation / animation.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/public-api/animation/animation.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/animation/alpha-functions.h>
23 #include <dali/public-api/animation/time-period.h>
24 #include <dali/public-api/math/quaternion.h>
25 #include <dali/public-api/math/degree.h>
26 #include <dali/public-api/math/radian.h>
27 #include <dali/public-api/math/vector2.h>
28 #include <dali/internal/event/actors/actor-impl.h>
29 #include <dali/internal/event/animation/animation-impl.h>
30 #include <dali/internal/event/effects/shader-effect-impl.h>
31
32 namespace Dali
33 {
34
35 const char* const Animation::SIGNAL_FINISHED = "finished";
36 const char* const Animation::ACTION_PLAY = "play";
37 const char* const Animation::ACTION_STOP = "stop";
38 const char* const Animation::ACTION_PAUSE = "pause";
39
40 Animation::Animation()
41 {
42 }
43
44 Animation::Animation(Internal::Animation* animation)
45 : BaseHandle(animation)
46 {
47 }
48
49 Animation Animation::New(float durationSeconds)
50 {
51   Internal::AnimationPtr internal = Dali::Internal::Animation::New(durationSeconds);
52
53   return Animation(internal.Get());
54 }
55
56 Animation Animation::DownCast( BaseHandle handle )
57 {
58   return Animation( dynamic_cast<Dali::Internal::Animation*>(handle.GetObjectPtr()) );
59 }
60
61 Animation::~Animation()
62 {
63 }
64
65 void Animation::SetDuration(float durationSeconds)
66 {
67   GetImplementation(*this).SetDuration(durationSeconds);
68 }
69
70 float Animation::GetDuration() const
71 {
72   return GetImplementation(*this).GetDuration();
73 }
74
75 void Animation::SetLooping(bool looping)
76 {
77   GetImplementation(*this).SetLooping(looping);
78 }
79
80 bool Animation::IsLooping() const
81 {
82   return GetImplementation(*this).IsLooping();
83 }
84
85 void Animation::SetEndAction(Dali::Animation::EndAction endAction)
86 {
87   GetImplementation(*this).SetEndAction(endAction);
88 }
89
90 Dali::Animation::EndAction Animation::GetEndAction() const
91 {
92   return GetImplementation(*this).GetEndAction();
93 }
94
95 void Animation::SetDestroyAction(Dali::Animation::EndAction destroyAction)
96 {
97   GetImplementation(*this).SetDestroyAction(destroyAction);
98 }
99
100 Dali::Animation::EndAction Animation::GetDestroyAction() const
101 {
102   return GetImplementation(*this).GetDestroyAction();
103 }
104
105 void Animation::SetDefaultAlphaFunction(AlphaFunction alpha)
106 {
107   GetImplementation(*this).SetDefaultAlphaFunction(alpha);
108 }
109
110 AlphaFunction Animation::GetDefaultAlphaFunction() const
111 {
112   return GetImplementation(*this).GetDefaultAlphaFunction();
113 }
114
115 void Animation::Play()
116 {
117   GetImplementation(*this).Play();
118 }
119
120 void Animation::PlayFrom(float progress)
121 {
122   GetImplementation(*this).PlayFrom(progress);
123 }
124
125
126 void Animation::Pause()
127 {
128   GetImplementation(*this).Pause();
129 }
130
131 void Animation::Stop()
132 {
133   GetImplementation(*this).Stop();
134 }
135
136 void Animation::Clear()
137 {
138   GetImplementation(*this).Clear();
139 }
140
141 Animation::AnimationSignalV2& Animation::FinishedSignal()
142 {
143   return GetImplementation(*this).FinishedSignal();
144 }
145
146 void Animation::AnimateBy(Property target, Property::Value relativeValue)
147 {
148   GetImplementation(*this).AnimateBy(target, relativeValue);
149 }
150
151 void Animation::AnimateBy(Property target, Property::Value relativeValue, AlphaFunction alpha)
152 {
153   GetImplementation(*this).AnimateBy(target, relativeValue, alpha);
154 }
155
156 void Animation::AnimateBy(Property target, Property::Value relativeValue, TimePeriod period)
157 {
158   GetImplementation(*this).AnimateBy(target, relativeValue, period);
159 }
160
161 void Animation::AnimateBy(Property target, Property::Value relativeValue, AlphaFunction alpha, TimePeriod period)
162 {
163   GetImplementation(*this).AnimateBy(target, relativeValue, alpha, period);
164 }
165
166 void Animation::AnimateTo(Property target, Property::Value destinationValue)
167 {
168   GetImplementation(*this).AnimateTo(target, destinationValue);
169 }
170
171 void Animation::AnimateTo(Property target, Property::Value destinationValue, AlphaFunction alpha)
172 {
173   GetImplementation(*this).AnimateTo(target, destinationValue, alpha);
174 }
175
176 void Animation::AnimateTo(Property target, Property::Value destinationValue, TimePeriod period)
177 {
178   GetImplementation(*this).AnimateTo(target, destinationValue, period);
179 }
180
181 void Animation::AnimateTo(Property target, Property::Value destinationValue, AlphaFunction alpha, TimePeriod period)
182 {
183   GetImplementation(*this).AnimateTo(target, destinationValue, alpha, period);
184 }
185
186 void Animation::AnimateBetween(Property target, KeyFrames& keyFrames)
187 {
188   GetImplementation(*this).AnimateBetween(target, GetImplementation(keyFrames));
189 }
190
191 void Animation::AnimateBetween(Property target, KeyFrames& keyFrames, TimePeriod period)
192 {
193   GetImplementation(*this).AnimateBetween(target, GetImplementation(keyFrames), period);
194 }
195
196 void Animation::AnimateBetween(Property target, KeyFrames& keyFrames, AlphaFunction alpha)
197 {
198   GetImplementation(*this).AnimateBetween(target, GetImplementation(keyFrames), alpha);
199 }
200
201 void Animation::AnimateBetween(Property target, KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period)
202 {
203   GetImplementation(*this).AnimateBetween(target, GetImplementation(keyFrames), alpha, period);
204 }
205
206 void Animation::Animate( Property target, Property::Type targetType, AnyFunction func )
207 {
208   GetImplementation(*this).Animate( target, targetType, func );
209 }
210
211 void Animation::Animate( Property target, Property::Type targetType, AnyFunction func, AlphaFunction alpha )
212 {
213   GetImplementation(*this).Animate( target, targetType, func, alpha );
214 }
215
216 void Animation::Animate( Property target, Property::Type targetType, AnyFunction func, TimePeriod period )
217 {
218   GetImplementation(*this).Animate( target, targetType, func, period );
219 }
220
221 void Animation::Animate( Property target, Property::Type targetType, AnyFunction func, AlphaFunction alpha, TimePeriod period )
222 {
223   GetImplementation(*this).Animate( target, targetType, func, alpha, period );
224 }
225
226 // Actor specific animations
227
228 void Animation::MoveBy(Actor actor, float x, float y, float z)
229 {
230   GetImplementation(*this).MoveBy(GetImplementation(actor), x, y, z);
231 }
232
233 void Animation::MoveBy(Actor actor, Vector3 displacement, AlphaFunction alpha)
234 {
235   GetImplementation(*this).MoveBy(GetImplementation(actor), displacement, alpha);
236 }
237
238 void Animation::MoveBy(Actor actor, Vector3 displacement, AlphaFunction alpha, float delaySeconds, float durationSeconds)
239 {
240   GetImplementation(*this).MoveBy(GetImplementation(actor), displacement, alpha, delaySeconds, durationSeconds);
241 }
242
243 void Animation::MoveTo(Actor actor, float x, float y, float z)
244 {
245   GetImplementation(*this).MoveTo(GetImplementation(actor), x, y, z);
246 }
247
248 void Animation::MoveTo(Actor actor, Vector3 position, AlphaFunction alpha)
249 {
250   GetImplementation(*this).MoveTo(GetImplementation(actor), position, alpha);
251 }
252
253 void Animation::MoveTo(Actor actor, Vector3 position, AlphaFunction alpha, float delaySeconds, float durationSeconds)
254 {
255   GetImplementation(*this).MoveTo(GetImplementation(actor), position, alpha, delaySeconds, durationSeconds);
256 }
257
258 void Animation::Move(Actor actor, AnimatorFunctionVector3 animatorFunc, AlphaFunction alpha, float delaySeconds, float durationSeconds)
259 {
260   GetImplementation(*this).Move(GetImplementation(actor), animatorFunc, alpha, delaySeconds, durationSeconds);
261 }
262
263 void Animation::RotateBy(Actor actor, Degree angle, Vector3 axis)
264 {
265   GetImplementation(*this).RotateBy(GetImplementation(actor), Radian(angle), axis);
266 }
267
268 void Animation::RotateBy(Actor actor, Radian angle, Vector3 axis)
269 {
270   GetImplementation(*this).RotateBy(GetImplementation(actor), angle, axis);
271 }
272
273 void Animation::RotateBy(Actor actor, Degree angle, Vector3 axis, AlphaFunction alpha)
274 {
275   GetImplementation(*this).RotateBy(GetImplementation(actor), Radian(angle), axis, alpha);
276 }
277
278 void Animation::RotateBy(Actor actor, Radian angle, Vector3 axis, AlphaFunction alpha)
279 {
280   GetImplementation(*this).RotateBy(GetImplementation(actor), angle, axis, alpha);
281 }
282
283 void Animation::RotateBy(Actor actor, Degree angle, Vector3 axis, AlphaFunction alpha, float delaySeconds, float durationSeconds)
284 {
285   GetImplementation(*this).RotateBy(GetImplementation(actor), Radian(angle), axis, alpha, delaySeconds, durationSeconds);
286 }
287
288 void Animation::RotateBy(Actor actor, Radian angle, Vector3 axis, AlphaFunction alpha, float delaySeconds, float durationSeconds)
289 {
290   GetImplementation(*this).RotateBy(GetImplementation(actor), angle, axis, alpha, delaySeconds, durationSeconds);
291 }
292
293 void Animation::RotateTo(Actor actor, Degree angle, Vector3 axis)
294 {
295   GetImplementation(*this).RotateTo(GetImplementation(actor), Radian(angle), axis);
296 }
297
298 void Animation::RotateTo(Actor actor, Radian angle, Vector3 axis)
299 {
300   GetImplementation(*this).RotateTo(GetImplementation(actor), angle, axis);
301 }
302
303 void Animation::RotateTo(Actor actor, Quaternion rotation)
304 {
305   GetImplementation(*this).RotateTo(GetImplementation(actor), rotation);
306 }
307
308 void Animation::RotateTo(Actor actor, Degree angle, Vector3 axis, AlphaFunction alpha)
309 {
310   GetImplementation(*this).RotateTo(GetImplementation(actor), Radian(angle), axis, alpha);
311 }
312
313 void Animation::RotateTo(Actor actor, Radian angle, Vector3 axis, AlphaFunction alpha)
314 {
315   GetImplementation(*this).RotateTo(GetImplementation(actor), angle, axis, alpha);
316 }
317
318 void Animation::RotateTo(Actor actor, Quaternion rotation, AlphaFunction alpha)
319 {
320   GetImplementation(*this).RotateTo(GetImplementation(actor), rotation, alpha);
321 }
322
323 void Animation::RotateTo(Actor actor, Degree angle, Vector3 axis, AlphaFunction alpha, float delaySeconds, float durationSeconds)
324 {
325   GetImplementation(*this).RotateTo(GetImplementation(actor), Radian(angle), axis, alpha, delaySeconds, durationSeconds);
326 }
327
328 void Animation::RotateTo(Actor actor, Radian angle, Vector3 axis, AlphaFunction alpha, float delaySeconds, float durationSeconds)
329 {
330   GetImplementation(*this).RotateTo(GetImplementation(actor), angle, axis, alpha, delaySeconds, durationSeconds);
331 }
332
333 void Animation::RotateTo(Actor actor, Quaternion rotation, AlphaFunction alpha, float delaySeconds, float durationSeconds)
334 {
335   GetImplementation(*this).RotateTo(GetImplementation(actor), rotation, alpha, delaySeconds, durationSeconds);
336 }
337
338 void Animation::Rotate(Actor actor, AnimatorFunctionQuaternion animatorFunc, AlphaFunction alpha, float delaySeconds, float durationSeconds)
339 {
340   GetImplementation(*this).Rotate(GetImplementation(actor), animatorFunc, alpha, delaySeconds, durationSeconds);
341 }
342
343 void Animation::ScaleBy(Actor actor, float x, float y, float z)
344 {
345   GetImplementation(*this).ScaleBy(GetImplementation(actor), x, y, z);
346 }
347
348 void Animation::ScaleBy(Actor actor, Vector3 scale, AlphaFunction alpha)
349 {
350   GetImplementation(*this).ScaleBy(GetImplementation(actor), scale, alpha);
351 }
352
353 void Animation::ScaleBy(Actor actor, Vector3 scale, AlphaFunction alpha, float delaySeconds, float durationSeconds)
354 {
355   GetImplementation(*this).ScaleBy(GetImplementation(actor), scale, alpha, delaySeconds, durationSeconds);
356 }
357
358 void Animation::ScaleTo(Actor actor, float x, float y, float z)
359 {
360   GetImplementation(*this).ScaleTo(GetImplementation(actor), x, y, z);
361 }
362
363 void Animation::ScaleTo(Actor actor, Vector3 scale, AlphaFunction alpha)
364 {
365   GetImplementation(*this).ScaleTo(GetImplementation(actor), scale, alpha);
366 }
367
368 void Animation::ScaleTo(Actor actor, Vector3 scale, AlphaFunction alpha, float delaySeconds, float durationSeconds)
369 {
370   GetImplementation(*this).ScaleTo(GetImplementation(actor), scale, alpha, delaySeconds, durationSeconds);
371 }
372
373 void Animation::Show(Actor actor, float delaySeconds)
374 {
375   GetImplementation(*this).Show(GetImplementation(actor), delaySeconds);
376 }
377
378 void Animation::Hide(Actor actor, float delaySeconds)
379 {
380   GetImplementation(*this).Hide(GetImplementation(actor), delaySeconds);
381 }
382
383 void Animation::OpacityBy(Actor actor, float opacity)
384 {
385   GetImplementation(*this).OpacityBy(GetImplementation(actor), opacity);
386 }
387
388 void Animation::OpacityBy(Actor actor, float opacity, AlphaFunction alpha)
389 {
390   GetImplementation(*this).OpacityBy(GetImplementation(actor), opacity, alpha);
391 }
392
393 void Animation::OpacityBy(Actor actor, float opacity, AlphaFunction alpha, float delaySeconds, float durationSeconds)
394 {
395   GetImplementation(*this).OpacityBy(GetImplementation(actor), opacity, alpha, delaySeconds, durationSeconds);
396 }
397
398 void Animation::OpacityTo(Actor actor, float opacity)
399 {
400   GetImplementation(*this).OpacityTo(GetImplementation(actor), opacity);
401 }
402
403 void Animation::OpacityTo(Actor actor, float opacity, AlphaFunction alpha)
404 {
405   GetImplementation(*this).OpacityTo(GetImplementation(actor), opacity, alpha);
406 }
407
408 void Animation::OpacityTo(Actor actor, float opacity, AlphaFunction alpha, float delaySeconds, float durationSeconds)
409 {
410   GetImplementation(*this).OpacityTo(GetImplementation(actor), opacity, alpha, delaySeconds, durationSeconds);
411 }
412
413 void Animation::ColorBy(Actor actor, Vector4 color)
414 {
415   GetImplementation(*this).ColorBy(GetImplementation(actor), color);
416 }
417
418 void Animation::ColorBy(Actor actor, Vector4 color, AlphaFunction alpha)
419 {
420   GetImplementation(*this).ColorBy(GetImplementation(actor), color, alpha);
421 }
422
423 void Animation::ColorBy(Actor actor, Vector4 color, AlphaFunction alpha, float delaySeconds, float durationSeconds)
424 {
425   GetImplementation(*this).ColorBy(GetImplementation(actor), color, alpha, delaySeconds, durationSeconds);
426 }
427
428 void Animation::ColorTo(Actor actor, Vector4 color)
429 {
430   GetImplementation(*this).ColorTo(GetImplementation(actor), color);
431 }
432
433 void Animation::ColorTo(Actor actor, Vector4 color, AlphaFunction alpha)
434 {
435   GetImplementation(*this).ColorTo(GetImplementation(actor), color, alpha);
436 }
437
438 void Animation::ColorTo(Actor actor, Vector4 color, AlphaFunction alpha, float delaySeconds, float durationSeconds)
439 {
440   GetImplementation(*this).ColorTo(GetImplementation(actor), color, alpha, delaySeconds, durationSeconds);
441 }
442
443 void Animation::Resize(Actor actor, float width, float height)
444 {
445   GetImplementation(*this).Resize(GetImplementation(actor), width, height);
446 }
447
448 void Animation::Resize(Actor actor, float width, float height, AlphaFunction alpha)
449 {
450   GetImplementation(*this).Resize(GetImplementation(actor), width, height, alpha);
451 }
452
453 void Animation::Resize(Actor actor,float width, float height, AlphaFunction alpha, float delaySeconds, float durationSeconds)
454 {
455   GetImplementation(*this).Resize(GetImplementation(actor), width, height, alpha, delaySeconds, durationSeconds);
456 }
457
458 void Animation::Resize(Actor actor, Vector3 size)
459 {
460   GetImplementation(*this).Resize(GetImplementation(actor), size);
461 }
462
463 void Animation::Resize(Actor actor, Vector3 size, AlphaFunction alpha)
464 {
465   GetImplementation(*this).Resize(GetImplementation(actor), size, alpha);
466 }
467
468 void Animation::Resize(Actor actor, Vector3 size, AlphaFunction alpha, float delaySeconds, float durationSeconds)
469 {
470   GetImplementation(*this).Resize(GetImplementation(actor), size, alpha, delaySeconds, durationSeconds);
471 }
472
473 float Animation::GetCurrentProgress()
474 {
475   return GetImplementation(*this).GetCurrentProgress();
476 }
477
478 void Animation::SetCurrentProgress( float progress )
479 {
480   return GetImplementation(*this).SetCurrentProgress( progress );
481 }
482
483 } // namespace Dali