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