a2070912d7f986eebcc2d2f6df8035a6df70ff57
[platform/core/uifw/dali-core.git] / dali / internal / event / animation / animation-impl.h
1 #ifndef __DALI_INTERNAL_ANIMATION_H__
2 #define __DALI_INTERNAL_ANIMATION_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/object/ref-object.h>
24 #include <dali/public-api/animation/animation.h>
25 #include <dali/public-api/object/base-object.h>
26 #include <dali/internal/event/animation/animator-connector-base.h>
27 #include <dali/internal/event/animation/key-frames-impl.h>
28
29 namespace Dali
30 {
31
32 namespace Internal
33 {
34
35 namespace SceneGraph
36 {
37 class Animation;
38 class UpdateManager;
39 }
40
41 class Actor;
42 class Animation;
43 class AnimationPlaylist;
44 class ProxyObject;
45 class ShaderEffect;
46
47 typedef IntrusivePtr<Animation> AnimationPtr;
48 typedef std::vector<AnimationPtr> AnimationContainer;
49
50 typedef AnimationContainer::iterator AnimationIter;
51 typedef AnimationContainer::const_iterator AnimationConstIter;
52
53 /**
54  * Animation is a proxy for a SceneGraph::Animation object.
55  * The UpdateManager owns the Animation object, but the lifetime of the animation is
56  * indirectly controlled by the Animation.
57  */
58 class Animation : public BaseObject
59 {
60 public:
61
62   typedef Dali::Animation::AnyFunction AnyFunction;
63   typedef Dali::Animation::EndAction EndAction;
64
65   typedef void (*FinishedCallback)(Object* object);
66
67   /**
68    * Create a new Animation object.
69    * @param[in] durationSeconds The duration of the animation.
70    * @return A smart-pointer to the newly allocated Animation.
71    */
72   static AnimationPtr New(float durationSeconds);
73
74   /**
75    * Create a new Animation object.
76    * @param[in] durationSeconds The duration of the animation.
77    * @param[in] endAction The action to perform when the animation ends.
78    * @param[in] destroyAction The action to perform when the animation ends.
79    * @return A smart-pointer to the newly allocated Animation.
80    */
81   static AnimationPtr New(float durationSeconds, EndAction endAction, EndAction destroyAction);
82
83   /**
84    * Create a new Animation object.
85    * @param[in] durationSeconds The duration of the animation.
86    * @param[in] endAction The action to perform when the animation ends.
87    * @param[in] destroyAction The action to perform when the animation ends.
88    * @param[in] alpha The default alpha function to apply to animators.
89    * @return A smart-pointer to the newly allocated Animation.
90    */
91   static AnimationPtr New(float durationSeconds, EndAction endAction, EndAction destroyAction, AlphaFunction alpha);
92
93   /**
94    * Set the duration of an animation.
95    * @pre durationSeconds must be greater than zero.
96    * @param[in] seconds The duration in seconds.
97    */
98   void SetDuration(float seconds);
99
100   /**
101    * Retrieve the duration of an animation.
102    * @return The duration in seconds.
103    */
104   float GetDuration() const;
105
106   /**
107    * Set whether the animation will loop.
108    * @param[in] looping True if the animation will loop.
109    */
110   void SetLooping(bool looping);
111
112   /**
113    * Query whether the animation will loop.
114    * @return True if the animation will loop.
115    */
116   bool IsLooping() const;
117
118   /**
119    * Set the end action of the animation.
120    * @param[in] action The end action.
121    */
122   void SetEndAction(EndAction action);
123
124   /**
125    * Returns the end action of the animation.
126    */
127   EndAction GetEndAction() const;
128
129   /**
130    * Set the destroy action of the animation.
131    * @param[in] action The destroy action.
132    */
133   void SetDestroyAction(EndAction action);
134
135   /**
136    * Returns the destroy action of the animation.
137    */
138   EndAction GetDestroyAction() const;
139
140   /**
141    * Set the default alpha function for an animation.
142    * This is applied to individual property animations, if no further alpha functions are supplied.
143    * @param[in] alpha The default alpha function.
144    */
145   void SetDefaultAlphaFunction(AlphaFunction alpha)
146   {
147     mDefaultAlpha = alpha;
148   }
149
150   /**
151    * Retrieve the default alpha function for an animation.
152    * @return The default alpha function.
153    */
154   AlphaFunction GetDefaultAlphaFunction() const
155   {
156     return mDefaultAlpha;
157   }
158
159   /**
160    * (Re)start the animation.
161    */
162   void Play();
163
164   /**
165    * (Re)start the animation from a given point.
166    * @param[in] progress The progress between [0,1] from where the animation should start
167    */
168   void PlayFrom( float progress );
169
170   /**
171    * Pause the animation.
172    */
173   void Pause();
174
175   /**
176    * Stop the animation.
177    */
178   void Stop();
179
180   /**
181    * Clear the animation.
182    * This disconnects any objects that were being animated, effectively stopping the animation.
183    */
184   void Clear();
185
186   /**
187    * Query whether a Finished signal should be emitted for this animation.
188    * This should only be called by NotificationManager, before signals are emitted.
189    * @post HasFinished() will return false on subsequent calls, until the animation is replayed to completion.
190    */
191   bool HasFinished();
192
193   /**
194    * @copydoc Dali::Animation::FinishedSignal()
195    */
196   Dali::Animation::AnimationSignalV2& FinishedSignal();
197
198   /**
199    * Emit the Finished signal
200    */
201   void EmitSignalFinish();
202
203   /**
204    * Connects a callback function with the object's signals.
205    * @param[in] object The object providing the signal.
206    * @param[in] tracker Used to disconnect the signal.
207    * @param[in] signalName The signal to connect to.
208    * @param[in] functor A newly allocated FunctorDelegate.
209    * @return True if the signal was connected.
210    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
211    */
212   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
213
214   /**
215    * Performs actions as requested using the action name.
216    * @param[in] object The object on which to perform the action.
217    * @param[in] actionName The action to perform.
218    * @param[in] attributes The attributes with which to perfrom this action.
219    * @return true if action was done
220    */
221   static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
222
223   /**
224    * This callback is intended for internal use only, to avoid the overhead of using a signal.
225    * @param[in] callback The callback function to connect.
226    * @param[in] object The internal object requesting the callback, or NULL.
227    */
228   void SetFinishedCallback( FinishedCallback callback, Object* object );
229
230   /**
231    * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue)
232    */
233   void AnimateBy(Property& target, Property::Value& relativeValue);
234
235   /**
236    * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue, AlphaFunction alpha)
237    */
238   void AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha);
239
240   /**
241    * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue, TimePeriod period)
242    */
243   void AnimateBy(Property& target, Property::Value& relativeValue, TimePeriod period);
244
245   /**
246    * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue, AlphaFunction alpha, TimePeriod period)
247    */
248   void AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha, TimePeriod period);
249
250   /**
251    * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue)
252    */
253   void AnimateTo(Property& target, Property::Value& destinationValue);
254
255   /**
256    * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue, AlphaFunction alpha)
257    */
258   void AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha);
259
260   /**
261    * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue, TimePeriod period)
262    */
263   void AnimateTo(Property& target, Property::Value& destinationValue, TimePeriod period);
264
265   /**
266    * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue, AlphaFunction alpha, TimePeriod period)
267    */
268   void AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period);
269
270   /**
271    * Animate a property to a destination value.
272    * @param [in] targetObject The target object to animate.
273    * @param [in] targetPropertyIndex The index of the target property.
274    * @param [in] componentIndex Index to a sub component of a property, for use with Vector2, Vector3 and Vector4
275    * @param [in] destinationValue The destination value.
276    * @param [in] alpha The alpha function to apply.
277    * @param [in] period The effect will occur during this time period.
278    */
279   void AnimateTo(ProxyObject& targetObject, Property::Index targetPropertyIndex, int componentIndex, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period);
280
281
282   /**
283    * Animate a property between the keyframe time / value pairs.
284    * It uses the current duration of the animation to run the key
285    * frame animator. Note, If the animation duration is subsequently
286    * changed, this does not change to match.
287    *
288    * @param[in] target The target object + property to animate
289    * @param[in] keyFrames The set of time / value pairs between which to animate.
290    */
291   void AnimateBetween(Property target, const KeyFrames& keyFrames);
292
293   /**
294    * Animate a property between the keyframe time / value pairs.
295    * @param[in] target The target object + property to animate
296    * @param[in] keyFrames The set of time / value pairs between which to animate.
297    * @param[in] period The effect will occur duing this time period.
298    */
299   void AnimateBetween(Property target, const KeyFrames& keyFrames, TimePeriod period);
300
301   /**
302    * Animate a property between the keyframe time / value pairs.
303    * @param[in] target The target object + property to animate
304    * @param[in] keyFrames The set of time / value pairs between which to animate.
305    * @param[in] alpha The alpha function to apply to the overall progress.
306    */
307   void AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha);
308
309   /**
310    * Animate a property between the keyframe time / value pairs.
311    * @param[in] target The target object + property to animate
312    * @param[in] keyFrames The set of time / value pairs between which to animate.
313    * @param[in] alpha The alpha function to apply to the overall progress.
314    * @param[in] period The effect will occur duing this time period.
315    */
316   void AnimateBetween(Property target, const KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period);
317
318   /**
319    * @copydoc Dali::Animation::Animate( Property target, Property::Type targetType, AnyFunction func )
320    */
321   void Animate( Property& target, Property::Type targetType, AnyFunction& func );
322
323   /**
324    * @copydoc Dali::Animation::Animate(Property target, Property::Type targetType, AnyFunction func, AlphaFunction alpha )
325    */
326   void Animate( Property& target, Property::Type targetType, AnyFunction& func, AlphaFunction& alpha );
327
328   /**
329    * @copydoc Dali::Animation::Animate(Property target, Property::Type targetType, AnyFunction func, TimePeriod period)
330    */
331   void Animate( Property& target, Property::Type targetType, AnyFunction& func, TimePeriod period );
332
333   /**
334    * @copydoc Dali::Animation::Animate(Property target, Property::Type targetType, AnyFunction func, AlphaFunction alpha, TimePeriod period)
335    */
336   void Animate( Property& target, Property::Type targetType, AnyFunction& func, AlphaFunction& alpha, TimePeriod period );
337
338   // Action-specific convenience functions
339
340   /**
341    * Translate an actor.
342    * The default alpha function will be used.
343    * The translation will start & end when the animation begins & ends.
344    * @param [in] actor The actor to animate.
345    * @param [in] x Translation in the X-direction.
346    * @param [in] y Translation in the Y-direction.
347    * @param [in] z Translation in the Z-direction.
348    */
349   void MoveBy(Actor& actor, float x, float y, float z);
350
351   /**
352    * Translate an actor. This overload allows the alpha function to be customized.
353    * The translation will start & end when the animation begins & ends.
354    * @param [in] actor The actor to animate.
355    * @param [in] translation The translation.
356    * @param [in] alpha The alpha function to apply.
357    */
358   void MoveBy(Actor& actor, const Vector3& translation, AlphaFunction alpha);
359
360   /**
361    * Translate an actor. This overload allows the translation start & end time to be customized.
362    * @pre delaySeconds must be zero or greater.
363    * @pre durationSeconds must be greater than zero.
364    * @param [in] actor The actor to animate.
365    * @param [in] translation The translation.
366    * @param [in] alpha The alpha function to apply.
367    * @param [in] delaySeconds The initial delay from the start of the animation.
368    * @param [in] durationSeconds The duration of the translation.
369    */
370   void MoveBy(Actor& actor, const Vector3& translation, AlphaFunction alpha, float delaySeconds, float durationSeconds);
371
372   /**
373    * Translate an actor to a target position.
374    * The default alpha function will be used.
375    * The translation will start & end when the animation begins & ends.
376    * @param [in] actor The actor to animate.
377    * @param [in] x Translation in the X-direction.
378    * @param [in] y Translation in the Y-direction.
379    * @param [in] z Translation in the Z-direction.
380    */
381   void MoveTo(Actor& actor, float x, float y, float z);
382
383   /**
384    * Translate an actor to a target position. This overload allows the alpha function to be customized.
385    * The translation will start & end when the animation begins & ends.
386    * @param [in] actor The actor to animate.
387    * @param [in] translation The translation.
388    * @param [in] alpha The alpha function to apply.
389    */
390   void MoveTo(Actor& actor, const Vector3& translation, AlphaFunction alpha);
391
392   /**
393    * Translate an actor to a target position. This overload allows the translation start & end time to be customized.
394    * @pre delaySeconds must be zero or greater.
395    * @pre durationSeconds must be greater than zero.
396    * @param [in] actor The actor to animate.
397    * @param [in] translation The translation.
398    * @param [in] alpha The alpha function to apply.
399    * @param [in] delaySeconds The initial delay from the start of the animation.
400    * @param [in] durationSeconds The duration of the translation.
401    */
402   void MoveTo(Actor& actor, const Vector3& translation, AlphaFunction alpha,  float delaySeconds, float durationSeconds);
403
404   /**
405    * Translate an actor using a custom function.
406    * The animatorFunc will be called from the rendering thread; it should return quickly, to avoid performance degredation.
407    * @pre delaySeconds must be zero or greater.
408    * @pre durationSeconds must be zero or greater; zero is useful when animating boolean values.
409    * @param [in] actor The actor to animate.
410    * @param [in] func The function to call during the animation.
411    * @param [in] alpha The alpha function to apply.
412    * @param [in] delaySeconds The initial delay from the start of the animation.
413    * @param [in] durationSeconds The duration of the translation.
414    */
415   void Move(Actor& actor, AnimatorFunctionVector3 func, AlphaFunction alpha, float delaySeconds, float durationSeconds);
416
417   /**
418    * Rotate an actor around an arbitrary axis.
419    * The default alpha function will be used.
420    * The rotation will start & end when the animation begins & ends.
421    * @param [in] actor The actor to animate.
422    * @param [in] angle The angle in radians.
423    * @param [in] axis The axis of rotation.
424    */
425   void RotateBy(Actor& actor, Radian angle, const Vector3& axis);
426
427   /**
428    * Rotate an actor around an arbitrary axis. This overload allows the alpha function to be customized.
429    * The rotation will start & end when the animation begins & ends.
430    * @param [in] actor The actor to animate.
431    * @param [in] angle The angle in radians.
432    * @param [in] axis The axis of rotation.
433    * @param [in] alpha The alpha function to apply.
434    */
435   void RotateBy(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha);
436
437   /**
438    * Rotate an actor around an arbitrary axis. This overload allows the rotation start & end time to be customized.
439    * @pre delaySeconds must be zero or greater.
440    * @pre durationSeconds must be zero or greater; zero is useful when animating boolean values.
441    * @param [in] actor The actor to animate.
442    * @param [in] angle The angle in radians.
443    * @param [in] axis The axis of rotation.
444    * @param [in] alpha The alpha function to apply.
445    * @param [in] delaySeconds The initial delay from the start of the animation.
446    * @param [in] durationSeconds The duration of the rotation.
447    */
448   void RotateBy(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha, float delaySeconds, float durationSeconds);
449
450   /**
451    * Rotate an actor to a target orientation.
452    * The default alpha function will be used.
453    * The rotation will start & end when the animation begins & ends.
454    * @param [in] actor The actor to animate.
455    * @param [in] angle The target rotation angle in radians.
456    * @param [in] axis The target axis of rotation.
457    */
458   void RotateTo(Actor& actor, Radian angle, const Vector3& axis);
459
460   /**
461    * Rotate an actor to a target orientation.
462    * The default alpha function will be used.
463    * The rotation will start & end when the animation begins & ends.
464    * @param [in] actor The actor to animate.
465    * @param [in] orientation The target orientation.
466    */
467   void RotateTo(Actor& actor, const Quaternion& orientation);
468
469   /**
470    * Rotate an actor to a target orientation. This overload allows the alpha function to be customized.
471    * The rotation will start & end when the animation begins & ends.
472    * @param [in] actor The actor to animate.
473    * @param [in] angle The target rotation angle in radians.
474    * @param [in] axis The target axis of rotation.
475    * @param [in] alpha The alpha function to apply.
476    */
477   void RotateTo(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha);
478
479   /**
480    * Rotate an actor to a target orientation. This overload allows the alpha function to be customized.
481    * The rotation will start & end when the animation begins & ends.
482    * @param [in] actor The actor to animate.
483    * @param [in] orientation The target orientation.
484    * @param [in] alpha The alpha function to apply.
485    */
486   void RotateTo(Actor& actor, const Quaternion& orientation, AlphaFunction alpha);
487
488   /**
489    * Rotate an actor to a target orientation. This overload allows the rotation start & end time to be customized.
490    * @pre delaySeconds must be zero or greater.
491    * @pre durationSeconds must be greater than zero.
492    * @param [in] actor The actor to animate.
493    * @param [in] orientation The target orientation.
494    * @param [in] alpha The alpha function to apply.
495    * @param [in] delaySeconds The initial delay from the start of the animation.
496    * @param [in] durationSeconds The duration of the rotation.
497    */
498   void RotateTo(Actor& actor, const Quaternion& orientation, AlphaFunction alpha, float delaySeconds, float durationSeconds);
499
500   /**
501    * Rotate an actor to a target orientation. This overload allows the rotation start & end time to be customized.
502    * @pre delaySeconds must be zero or greater.
503    * @pre durationSeconds must be greater than zero.
504    * @param [in] actor The actor to animate.
505    * @param [in] angle The target rotation angle in radians.
506    * @param [in] axis The target axis of rotation.
507    * @param [in] alpha The alpha function to apply.
508    * @param [in] delaySeconds The initial delay from the start of the animation.
509    * @param [in] durationSeconds The duration of the rotation.
510    */
511   void RotateTo(Actor& actor, Radian angle, const Vector3& axis, AlphaFunction alpha, float delaySeconds, float durationSeconds);
512
513   /**
514    * Rotate an actor using a custom function.
515    * The animatorFunc will be called from the rendering thread; it should return quickly, to avoid performance degredation.
516    * @pre delaySeconds must be zero or greater.
517    * @pre durationSeconds must be zero or greater; zero is useful when animating boolean values.
518    * @param [in] actor The actor to animate.
519    * @param [in] func The function to call during the animation.
520    * @param [in] alpha The alpha function to apply.
521    * @param [in] delaySeconds The initial delay from the start of the animation.
522    * @param [in] durationSeconds The duration of the translation.
523    */
524   void Rotate(Actor& actor, AnimatorFunctionQuaternion func, AlphaFunction alpha, float delaySeconds, float durationSeconds);
525
526   /**
527    * Scale an actor.
528    * The default alpha function will be used.
529    * The scaling will start & end when the animation begins & ends.
530    * @param [in] actor The actor to animate.
531    * @param [in] x Scale factor in the X-direction.
532    * @param [in] y Scale factor in the Y-direction.
533    * @param [in] z Scale factor in the Z-direction.
534    */
535   void ScaleBy(Actor& actor, float x, float y, float z);
536
537   /**
538    * Scale an actor. This overload allows the alpha function to be customized.
539    * The scaling will start & end when the animation begins & ends.
540    * @param [in] actor The actor to animate.
541    * @param [in] scale The scale factor.
542    * @param [in] alpha The alpha function to apply.
543    */
544   void ScaleBy(Actor& actor, const Vector3& scale, AlphaFunction alpha);
545
546   /**
547    * Scale an actor. This overload allows the translation start & end time to be customized.
548    * @pre delaySeconds must be zero or greater.
549    * @pre durationSeconds must be greater than zero.
550    * @param [in] actor The actor to animate.
551    * @param [in] scale The scale factor.
552    * @param [in] alpha The alpha function to apply.
553    * @param [in] delaySeconds The initial delay from the start of the animation.
554    * @param [in] durationSeconds The duration of the translation.
555    */
556   void ScaleBy(Actor& actor, const Vector3& scale, AlphaFunction alpha, float delaySeconds, float durationSeconds);
557
558   /**
559    * Scale an actor to a target scale factor.
560    * The default alpha function will be used.
561    * The scaling will start & end when the animation begins & ends.
562    * @param [in] actor The actor to animate.
563    * @param [in] x Target scale-factor in the X-direction.
564    * @param [in] y Target scale-factor in the Y-direction.
565    * @param [in] z Target scale-factor in the Z-direction.
566    */
567   void ScaleTo(Actor& actor, float x, float y, float z);
568
569   /**
570    * Scale an actor to a target scale factor. This overload allows the alpha function to be customized.
571    * The scaling will start & end when the animation begins & ends.
572    * @param [in] actor The actor to animate.
573    * @param [in] scale The target scale factor.
574    * @param [in] alpha The alpha function to apply.
575    */
576   void ScaleTo(Actor& actor, const Vector3& scale, AlphaFunction alpha);
577
578   /**
579    * Scale an actor to a target scale factor. This overload allows the translation start & end time to be customized.
580    * @pre delaySeconds must be zero or greater.
581    * @pre durationSeconds must be greater than zero.
582    * @param [in] actor The actor to animate.
583    * @param [in] scale The target scale factor.
584    * @param [in] alpha The alpha function to apply.
585    * @param [in] delaySeconds The initial delay from the start of the animation.
586    * @param [in] durationSeconds The duration of the translation.
587    */
588   void ScaleTo(Actor& actor, const Vector3& scale, AlphaFunction alpha, float delaySeconds, float durationSeconds);
589
590   /**
591    * Show an actor during the animation.
592    * @param [in] actor The actor to animate.
593    * @param [in] delaySeconds The initial delay from the start of the animation.
594    */
595   void Show(Actor& actor, float delaySeconds);
596
597   /**
598    * Hide an actor during the animation.
599    * @param [in] actor The actor to animate.
600    * @param [in] delaySeconds The initial delay from the start of the animation.
601    */
602   void Hide(Actor& actor, float delaySeconds);
603
604   /**
605    * Animate the opacity of an actor.
606    * The default alpha function will be used.
607    * The effect will start & end when the animation begins & ends.
608    * @param [in] actor The actor to animate.
609    * @param [in] opacity The relative change in opacity.
610    */
611   void OpacityBy(Actor& actor, float opacity);
612
613   /**
614    * Animate the opacity of an actor. This overload allows the alpha function to be customized.
615    * The effect will start & end when the animation begins & ends.
616    * @param [in] actor The actor to animate.
617    * @param [in] opacity The relative change in opacity.
618    * @param [in] alpha The alpha function to apply.
619    */
620   void OpacityBy(Actor& actor, float opacity, AlphaFunction alpha);
621
622   /**
623    * Animate the opacity of an actor. This overload allows the translation start & end time to be customized.
624    * @pre delaySeconds must be zero or greater.
625    * @pre durationSeconds must be greater than zero.
626    * @param [in] actor The actor to animate.
627    * @param [in] opacity The relative change in opacity.
628    * @param [in] alpha The alpha function to apply.
629    * @param [in] delaySeconds The initial delay from the start of the animation.
630    * @param [in] durationSeconds The duration of the translation.
631    */
632   void OpacityBy(Actor& actor, float opacity, AlphaFunction alpha, float delaySeconds, float durationSeconds);
633
634   /**
635    * Animate an actor to a target opacity.
636    * The default alpha function will be used.
637    * The effect will start & end when the animation begins & ends.
638    * @param [in] actor The actor to animate.
639    * @param [in] opacity The target opacity.
640    */
641   void OpacityTo(Actor& actor, float opacity);
642
643   /**
644    * Animate an actor to a target opacity. This overload allows the alpha function to be customized.
645    * The effect will start & end when the animation begins & ends.
646    * @param [in] actor The actor to animate.
647    * @param [in] opacity The target opacity.
648    * @param [in] alpha The alpha function to apply.
649    */
650   void OpacityTo(Actor& actor, float opacity, AlphaFunction alpha);
651
652   /**
653    * Animate an actor to a target opacity. This overload allows the translation start & end time to be customized.
654    * @pre delaySeconds must be zero or greater.
655    * @pre durationSeconds must be greater than zero.
656    * @param [in] actor The actor to animate.
657    * @param [in] opacity The target opacity.
658    * @param [in] alpha The alpha function to apply.
659    * @param [in] delaySeconds The initial delay from the start of the animation.
660    * @param [in] durationSeconds The duration of the translation.
661    */
662   void OpacityTo(Actor& actor, float opacity, AlphaFunction alpha, float delaySeconds, float durationSeconds);
663
664   /**
665    * Animate the color of an actor.
666    * The default alpha function will be used.
667    * The effect will start & end when the animation begins & ends.
668    * @param [in] actor The actor to animate.
669    * @param [in] color The relative change in color.
670    */
671   void ColorBy(Actor& actor, const Vector4& color);
672
673   /**
674    * Animate the color of an actor. This overload allows the alpha function to be customized.
675    * The effect will start & end when the animation begins & ends.
676    * @param [in] actor The actor to animate.
677    * @param [in] color The relative change in color.
678    * @param [in] alpha The alpha function to apply.
679    */
680   void ColorBy(Actor& actor, const Vector4& color, AlphaFunction alpha);
681
682   /**
683    * Animate the color of an actor. This overload allows the translation start & end time to be customized.
684    * @pre delaySeconds must be zero or greater.
685    * @pre durationSeconds must be zero or greater; zero is useful when animating boolean values.
686    * @param [in] actor The actor to animate.
687    * @param [in] color The relative change in color.
688    * @param [in] alpha The alpha function to apply.
689    * @param [in] delaySeconds The initial delay from the start of the animation.
690    * @param [in] durationSeconds The duration of the translation.
691    */
692   void ColorBy(Actor& actor, const Vector4& color, AlphaFunction alpha, float delaySeconds, float durationSeconds);
693
694   /**
695    * Animate an actor to a target color.
696    * The default alpha function will be used.
697    * The effect will start & end when the animation begins & ends.
698    * @param [in] actor The actor to animate.
699    * @param [in] color The target color.
700    */
701   void ColorTo(Actor& actor, const Vector4& color);
702
703   /**
704    * Animate an actor to a target color. This overload allows the alpha function to be customized.
705    * The effect will start & end when the animation begins & ends.
706    * @param [in] actor The actor to animate.
707    * @param [in] color The target color.
708    * @param [in] alpha The alpha function to apply.
709    */
710   void ColorTo(Actor& actor, const Vector4& color, AlphaFunction alpha);
711
712   /**
713    * Animate an actor to a target color. This overload allows the translation start & end time to be customized.
714    * @pre delaySeconds must be zero or greater.
715    * @pre durationSeconds must be zero or greater; zero is useful when animating boolean values.
716    * @param [in] actor The actor to animate.
717    * @param [in] color The target color.
718    * @param [in] alpha The alpha function to apply.
719    * @param [in] delaySeconds The initial delay from the start of the animation.
720    * @param [in] durationSeconds The duration of the translation.
721    */
722   void ColorTo(Actor& actor, const Vector4& color, AlphaFunction alpha, float delaySeconds, float durationSeconds);
723
724   /**
725    * Resize an actor.
726    * The default alpha function will be used.
727    * The resizing will start & end when the animation begins & ends.
728    * The depth defaults to the minimum of width & height.
729    * @param [in] actor The actor to animate.
730    * @param [in] width The target width.
731    * @param [in] height The target height.
732    */
733   void Resize(Actor& actor, float width, float height);
734
735   /**
736    * Resize an actor. This overload allows the alpha function to be customized.
737    * The resizing will start & end when the animation begins & ends.
738    * The depth defaults to the minimum of width & height.
739    * @param [in] actor The actor to animate.
740    * @param [in] width The target width.
741    * @param [in] height The target height.
742    * @param [in] alpha The alpha function to apply.
743    */
744   void Resize(Actor& actor, float width, float height, AlphaFunction alpha);
745
746   /**
747    * Resize an actor. This overload allows the resizing start & end time to be customized.
748    * The depth defaults to the minimum of width & height.
749    * @pre delaySeconds must be zero or greater.
750    * @pre durationSeconds must be greater than zero.
751    * @param [in] actor The actor to animate.
752    * @param [in] width The target width.
753    * @param [in] height The target height.
754    * @param [in] alpha The alpha function to apply.
755    * @param [in] delaySeconds The initial delay from the start of the animation.
756    * @param [in] durationSeconds The duration of the translation.
757    */
758   void Resize(Actor& actor, float width, float height, AlphaFunction alpha, float delaySeconds, float durationSeconds);
759
760   /**
761    * Resize an actor.
762    * The default alpha function will be used.
763    * The resizing will start & end when the animation begins & ends.
764    * @param [in] actor The actor to animate.
765    * @param [in] size The target size.
766    */
767   void Resize(Actor& actor, const Vector3& size);
768
769   /**
770    * Resize an actor. This overload allows the alpha function to be customized.
771    * The resizing will start & end when the animation begins & ends.
772    * @param [in] actor The actor to animate.
773    * @param [in] size The target size.
774    * @param [in] alpha The alpha function to apply.
775    */
776   void Resize(Actor& actor, const Vector3& size, AlphaFunction alpha);
777
778   /**
779    * Resize an actor. This overload allows the resizing start & end time to be customized.
780    * @pre delaySeconds must be zero or greater.
781    * @pre durationSeconds must be greater than zero.
782    * @param [in] actor The actor to animate.
783    * @param [in] size The target size.
784    * @param [in] alpha The alpha function to apply.
785    * @param [in] delaySeconds The initial delay from the start of the animation.
786    * @param [in] durationSeconds The duration of the translation.
787    */
788   void Resize(Actor& actor, const Vector3& size, AlphaFunction alpha, float delaySeconds, float durationSeconds);
789
790   /*
791    * @copydoc Dali::Animation::SetCurrentProgress()
792    */
793   void SetCurrentProgress(float progress);
794
795   /*
796    * @copydoc Dali::Animation::GetCurrentProgress()
797    */
798   float GetCurrentProgress();
799
800   /*
801    * @copydoc Dali::Animation::SetSpeedFactor()
802    */
803   void SetSpeedFactor( float factor );
804
805   /*
806    * @copydoc Dali::Animation::GetSpeedFactor()
807    */
808   float GetSpeedFactor() const;
809
810   /*
811    * @copydoc Dali::Animation::SetPlayRange()
812    */
813   void SetPlayRange( const Vector2& range );
814
815   /*
816    * @copydoc Dali::Animation::GetPlayRange
817    */
818   Vector2 GetPlayRange() const;
819
820 public: // For connecting animators to animations
821
822   /**
823    * Add an animator connector.
824    * @param[in] connector The animator connector.
825    */
826   void AddAnimatorConnector( AnimatorConnectorBase* connector );
827
828   /**
829    * Retrieve the SceneGraph::Animation object.
830    * @return The animation.
831    */
832   const SceneGraph::Animation* GetSceneObject()
833   {
834     return mAnimation;
835   }
836
837   /**
838    * Retrieve the UpdateManager associated with this animation.
839    * @return The UpdateManager.
840    */
841   SceneGraph::UpdateManager& GetUpdateManager()
842   {
843     return mUpdateManager;
844   }
845
846 protected:
847
848   /**
849    * Construct a new Animation.
850    * @param[in] updateManager The UpdateManager associated with this animation.
851    * @param[in] playlist The list of currently playing animations.
852    * @param[in] durationSeconds The duration of the animation in seconds.
853    * @param[in] endAction The action to perform when the animation ends.
854    * @param[in] destroyAction The action to perform when the animation is destroyed.
855    * @param[in] defaultAlpha The default alpha function to apply to animators.
856    */
857   Animation( SceneGraph::UpdateManager& updateManager,
858              AnimationPlaylist& playlist,
859              float durationSeconds,
860              EndAction endAction,
861              EndAction destroyAction,
862              AlphaFunction defaultAlpha);
863
864   /**
865    * Second-phase constructor.
866    */
867   void Initialize();
868
869   /**
870    * Helper to create a scene-graph animation
871    */
872   void CreateSceneObject();
873
874   /**
875    * Helper to create a scene-graph animation
876    */
877   void DestroySceneObject();
878
879   /**
880    * A reference counted object may only be deleted by calling Unreference()
881    */
882   virtual ~Animation();
883
884 private:
885
886   /**
887    * Extends the duration when an animator is added with TimePeriod that exceeds current duration.
888    * @param[in] timePeriod The time period for an animator.
889    */
890   void ExtendDuration( const TimePeriod& timePeriod );
891
892   // Undefined
893   Animation(const Animation&);
894
895   // Undefined
896   Animation& operator=(const Animation& rhs);
897
898 private:
899
900   SceneGraph::UpdateManager& mUpdateManager;
901   AnimationPlaylist& mPlaylist;
902
903   const SceneGraph::Animation* mAnimation;
904
905   int mNotificationCount; ///< Keep track of how many Finished signals have been emitted.
906
907   Dali::Animation::AnimationSignalV2 mFinishedSignal;
908
909   FinishedCallback mFinishedCallback;
910   Object* mFinishedCallbackObject;
911
912   AnimatorConnectorContainer mConnectors; ///< Owned by the Animation
913
914   // Cached for public getters
915   float mDurationSeconds;
916   float mSpeedFactor;
917   bool mIsLooping;
918   Vector2 mPlayRange;
919   EndAction mEndAction;
920   EndAction mDestroyAction;
921   AlphaFunction mDefaultAlpha;
922
923 };
924
925 } // namespace Internal
926
927 // Helpers for public-api forwarding methods
928
929 inline Internal::Animation& GetImplementation(Dali::Animation& animation)
930 {
931   DALI_ASSERT_ALWAYS( animation && "Animation handle is empty" );
932
933   BaseObject& handle = animation.GetBaseObject();
934
935   return static_cast<Internal::Animation&>(handle);
936 }
937
938 inline const Internal::Animation& GetImplementation(const Dali::Animation& animation)
939 {
940   DALI_ASSERT_ALWAYS( animation && "Animation handle is empty" );
941
942   const BaseObject& handle = animation.GetBaseObject();
943
944   return static_cast<const Internal::Animation&>(handle);
945 }
946
947 } // namespace Dali
948
949 #endif // __DALI_INTERNAL_ANIMATION_H__