[3.0] Update doxygen comments
[platform/core/uifw/dali-core.git] / dali / public-api / animation / animation.h
1 #ifndef __DALI_ANIMATION_H__
2 #define __DALI_ANIMATION_H__
3
4 /*
5  * Copyright (c) 2015 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/animation/alpha-function.h>
23 #include <dali/public-api/animation/key-frames.h>
24 #include <dali/public-api/animation/path.h>
25 #include <dali/public-api/animation/time-period.h>
26 #include <dali/public-api/object/any.h>
27 #include <dali/public-api/object/handle.h>
28 #include <dali/public-api/object/property.h>
29 #include <dali/public-api/signals/dali-signal.h>
30
31 namespace Dali
32 {
33 /**
34  * @addtogroup dali_core_animation
35  * @{
36  */
37
38 class Actor;
39 struct Property;
40 struct Vector2;
41 struct Vector3;
42
43 namespace Internal DALI_INTERNAL
44 {
45 class Animation;
46 }
47
48 /**
49  * @brief Dali::Animation can be used to animate the properties of any number of objects, typically Actors.
50  *
51  * An example animation setup is shown below:
52  *
53  * @code
54  *
55  * struct MyProgram
56  * {
57  *   Actor mActor; // The object we wish to animate
58  *   Animation mAnimation; // Keep this to control the animation
59  * }
60  *
61  * // ...To play the animation
62  *
63  * mAnimation = Animation::New(3.0f); // duration 3 seconds
64  * mAnimation.AnimateTo(Property(mActor, Actor::Property::POSITION), Vector3(10.0f, 50.0f, 0.0f));
65  * mAnimation.Play();
66  *
67  * @endcode
68  *
69  * Dali::Animation supports "fire and forget" behaviour i.e. an animation continues to play if the handle is discarded.
70  * Note that in the following example, the "Finish" signal will be emitted:
71  *
72  * @code
73  *
74  * void ExampleCallback( Animation& source )
75  * {
76  *   std::cout << "Animation has finished" << std::endl;
77  * }
78  *
79  * void ExampleAnimation( Actor actor )
80  * {
81  *   Animation animation = Animation::New(2.0f); // duration 2 seconds
82  *   animation.AnimateTo(Property(actor, Actor::Property::POSITION), 10.0f, 50.0f, 0.0f);
83  *   animation.FinishedSignal().Connect( ExampleCallback );
84  *   animation.Play();
85  * } // At this point the animation handle has gone out of scope
86  *
87  * Actor actor = Actor::New();
88  * Stage::GetCurrent().Add( actor );
89  *
90  * // Fire animation and forget about it
91  * ExampleAnimation( actor );
92  *
93  * // However the animation will continue, and "Animation has finished" will be printed after 2 seconds.
94  *
95  * @endcode
96  *
97  * If the "Finish" signal is connected to a member function of an object, it must be disconnected before the object is destroyed.
98  * This is typically done in the object destructor, and requires either the Dali::Connection object or Dali::Animation handle to be stored.
99  *
100  * Signals
101  * | %Signal Name | Method                   |
102  * |--------------|--------------------------|
103  * | finished     | @ref FinishedSignal()    |
104  *
105  * Actions
106  * | %Action Name | %Animation method called |
107  * |--------------|--------------------------|
108  * | play         | Play()                   |
109  * | stop         | Stop()                   |
110  * | pause        | Pause()                  |
111  * @SINCE_1_0.0
112  */
113 class DALI_IMPORT_API Animation : public BaseHandle
114 {
115 public:
116
117   typedef Signal< void (Animation&) > AnimationSignalType; ///< Animation finished signal type @SINCE_1_0.0
118
119   typedef Any AnyFunction; ///< Interpolation function @SINCE_1_0.0
120
121   /**
122    * @brief Enumeration for what to do when the animation ends, is stopped, or is destroyed.
123    * @SINCE_1_0.0
124    */
125   enum EndAction
126   {
127     Bake,     ///< When the animation ends, the animated property values are saved. @SINCE_1_0.0
128     Discard,  ///< When the animation ends, the animated property values are forgotten. @SINCE_1_0.0
129     BakeFinal ///< If the animation is stopped, the animated property values are saved as if the animation had run to completion, otherwise behaves like Bake. @SINCE_1_0.0
130   };
131
132   /**
133    * @brief Enumeration for what interpolation method to use on key-frame animations.
134    * @SINCE_1_0.0
135    */
136   enum Interpolation
137   {
138     Linear,   ///< Values in between key frames are interpolated using a linear polynomial. (Default) @SINCE_1_0.0
139     Cubic     ///< Values in between key frames are interpolated using a cubic polynomial. @SINCE_1_0.0
140   };
141
142   /**
143    * @brief Enumeration for what state the animation is in.
144    *
145    * Note: Calling Reset() on this class will NOT reset the animation. It will call BaseHandle::Reset() which drops the object handle.
146    *
147    * @SINCE_1_1.21
148    */
149   enum State
150   {
151     STOPPED,   ///< Animation has stopped @SINCE_1_1.21
152     PLAYING,   ///< The animation is playing @SINCE_1_1.21
153     PAUSED     ///< The animation is paused @SINCE_1_1.21
154   };
155
156   /**
157    * @brief Creates an uninitialized Animation; this can be initialized with Animation::New().
158    *
159    * Calling member functions with an uninitialized Animation handle is not allowed.
160    * @SINCE_1_0.0
161    */
162   Animation();
163
164   /**
165    * @brief Creates an initialized Animation.
166    *
167    * The animation will not loop.
168    * The default end action is "Bake".
169    * The default alpha function is linear.
170    * @SINCE_1_0.0
171    * @param[in] durationSeconds The duration in seconds
172    * @return A handle to a newly allocated Dali resource
173    * @pre DurationSeconds must be greater than zero.
174    */
175   static Animation New(float durationSeconds);
176
177   /**
178    * @brief Downcasts a handle to Animation handle.
179    *
180    * If handle points to an Animation object, the downcast produces valid handle.
181    * If not, the returned handle is left uninitialized.
182    *
183    * @SINCE_1_0.0
184    * @param[in] handle Handle to an object
185    * @return Handle to an Animation object or an uninitialized handle
186    */
187   static Animation DownCast( BaseHandle handle );
188
189   /**
190    * @brief Destructor.
191    *
192    * This is non-virtual since derived Handle types must not contain data or virtual methods.
193    * @SINCE_1_0.0
194    */
195   ~Animation();
196
197   /**
198    * @brief This copy constructor is required for (smart) pointer semantics.
199    *
200    * @SINCE_1_0.0
201    * @param[in] handle A reference to the copied handle
202    */
203   Animation(const Animation& handle);
204
205   /**
206    * @brief This assignment operator is required for (smart) pointer semantics.
207    *
208    * @SINCE_1_0.0
209    * @param[in] rhs A reference to the copied handle
210    * @return A reference to this
211    */
212   Animation& operator=(const Animation& rhs);
213
214   /**
215    * @brief Sets the duration of an animation.
216    *
217    * @SINCE_1_0.0
218    * @param[in] seconds The duration in seconds
219    * @pre DurationSeconds must be greater than zero.
220    */
221   void SetDuration(float seconds);
222
223   /**
224    * @brief Retrieves the duration of an animation.
225    *
226    * @SINCE_1_0.0
227    * @return The duration in seconds
228    */
229   float GetDuration() const;
230
231   /**
232    * @brief Sets whether the animation will loop.
233    *
234    * This function resets the loop count and should not be used with SetLoopCount(int).
235    * Setting this parameter does not cause the animation to Play().
236    *
237    * @SINCE_1_0.0
238    * @param[in] looping True if the animation will loop
239    */
240   void SetLooping(bool looping);
241
242   /**
243    * @brief Enables looping for 'count' repeats.
244    *
245    * A zero is the same as SetLooping(true) i.e. repeat forever.
246    * If Play() Stop() or 'count' loops is reached, the loop counter will reset.
247    * Setting this parameter does not cause the animation to Play().
248    *
249    * @SINCE_1_1.20
250    * @param[in] count The number of times to loop
251    */
252   void SetLoopCount(int count);
253
254   /**
255    * @brief Gets the loop count.
256    *
257    * A zero is the same as SetLooping(true) ie repeat forever.
258    * The loop count is initially 1 for play once.
259    *
260    * @SINCE_1_1.20
261    * @return The number of times to loop
262    */
263   int GetLoopCount();
264
265   /**
266    * @brief Gets the current loop count.
267    *
268    * A value 0 to GetLoopCount() indicating the current loop count when looping.
269    *
270    * @SINCE_1_1.20
271    * @return The current number of loops that have occured
272    */
273   int GetCurrentLoop();
274
275   /**
276    * @brief Queries whether the animation will loop.
277    *
278    * @SINCE_1_0.0
279    * @return True if the animation will loop
280    */
281   bool IsLooping() const;
282
283   /**
284    * @brief Sets the end action of the animation.
285    *
286    * This action is performed when the animation ends or if it is stopped.
287    * Default end action is bake.
288    * @SINCE_1_0.0
289    * @param[in] action The end action
290    */
291   void SetEndAction(EndAction action);
292
293   /**
294    * @brief Returns the end action of the animation.
295    *
296    * @SINCE_1_0.0
297    * @return The end action
298    */
299   EndAction GetEndAction() const;
300
301   /**
302    * @brief Sets the disconnect action.
303    *
304    * If any of the animated property owners are disconnected from the stage while the animation is being played, then this action is performed.
305    * Default action is to BakeFinal.
306    * @SINCE_1_0.0
307    * @param[in] disconnectAction The disconnect action
308    */
309   void SetDisconnectAction( EndAction disconnectAction );
310
311   /**
312    * @brief Returns the disconnect action.
313    *
314    * @SINCE_1_0.0
315    * @return The disconnect action
316    */
317   EndAction GetDisconnectAction() const;
318
319   /**
320    * @brief Sets the default alpha function for an animation.
321    *
322    * This is applied to individual property animations, if no further alpha functions are supplied.
323    * @SINCE_1_0.0
324    * @param[in] alpha The default alpha function
325    */
326   void SetDefaultAlphaFunction(AlphaFunction alpha);
327
328   /**
329    * @brief Retrieves the default alpha function for an animation.
330    *
331    * @SINCE_1_0.0
332    * @return The default alpha function
333    */
334   AlphaFunction GetDefaultAlphaFunction() const;
335
336   /*
337    * @brief Sets the progress of the animation.
338    *
339    * The animation will play (or continue playing) from this point. The progress
340    * must be in the 0-1 interval or in the play range interval if defined ( See @ref Animation::SetPlayRange ),
341    * otherwise, it will be ignored.
342    *
343    * @SINCE_1_0.0
344    * @param[in] progress The new progress as a normalized value between [0,1]
345    * or between the play range if specified
346    */
347   void SetCurrentProgress( float progress );
348
349   /**
350   * @brief Retrieves the current progress of the animation.
351   *
352   * @SINCE_1_0.0
353   * @return The current progress as a normalized value between [0,1]
354   */
355   float GetCurrentProgress();
356
357   /**
358    * @brief Specifies a speed factor for the animation.
359    *
360    * The speed factor is a multiplier of the normal velocity of the animation. Values between [0,1] will
361    * slow down the animation and values above one will speed up the animation. It is also possible to specify a negative multiplier
362    * to play the animation in reverse.
363    *
364    * @SINCE_1_0.0
365    * @param[in] factor A value which will multiply the velocity
366    */
367   void SetSpeedFactor( float factor );
368
369   /**
370    * @brief Retrieves the speed factor of the animation.
371    *
372    * @SINCE_1_0.0
373    * @return Speed factor
374    */
375   float GetSpeedFactor() const;
376
377   /**
378    * @brief Sets the playing range.
379    *
380    * Animation will play between the values specified. Both values ( range.x and range.y ) should be between 0-1,
381    * otherwise they will be ignored. If the range provided is not in proper order ( minimum,maximum ), it will be reordered.
382    *
383    * @SINCE_1_0.0
384    * @param[in] range Two values between [0,1] to specify minimum and maximum progress. The
385    * animation will play between those values
386    */
387   void SetPlayRange( const Vector2& range );
388
389   /**
390    * @brief Gets the playing range.
391    *
392    * @SINCE_1_0.0
393    * @return The play range defined for the animation
394    */
395   Vector2 GetPlayRange() const;
396
397   /**
398    * @brief Play the animation.
399    * @SINCE_1_0.0
400    */
401   void Play();
402
403   /**
404    * @brief Plays the animation from a given point.
405    *
406    * The progress must be in the 0-1 interval or in the play range interval if defined ( See @ref Animation::SetPlayRange ),
407    * otherwise, it will be ignored.
408    *
409    * @SINCE_1_0.0
410    * @param[in] progress A value between [0,1], or between the play range if specified, from where the animation should start playing
411    */
412   void PlayFrom( float progress );
413
414   /**
415    * @brief Pauses the animation.
416    * @SINCE_1_0.0
417    */
418   void Pause();
419
420   /**
421    * @brief Queries the state of the animation.
422    * @SINCE_1_1.21
423    * @return The Animation::State
424    */
425   State GetState() const;
426
427   /**
428    * @brief Stops the animation.
429    * @SINCE_1_0.0
430    */
431   void Stop();
432
433   /**
434    * @brief Clears the animation.
435    *
436    * This disconnects any objects that were being animated, effectively stopping the animation.
437    * @SINCE_1_0.0
438    */
439   void Clear();
440
441   /**
442    * @brief Connects to this signal to be notified when an Animation's animations have finished.
443    *
444    * @SINCE_1_0.0
445    * @return A signal object to connect with
446    */
447   AnimationSignalType& FinishedSignal();
448
449   /**
450    * @brief Animates a property value by a relative amount.
451    *
452    * The default alpha function will be used.
453    * The effect will start & end when the animation begins & ends.
454    * @SINCE_1_0.0
455    * @param[in] target The target object/property to animate
456    * @param[in] relativeValue The property value will change by this amount
457    */
458   void AnimateBy(Property target, Property::Value relativeValue);
459
460   /**
461    * @brief Animates a property value by a relative amount.
462    *
463    * The effect will start & end when the animation begins & ends.
464    * @SINCE_1_0.0
465    * @param[in] target The target object/property to animate
466    * @param[in] relativeValue The property value will change by this amount
467    * @param[in] alpha The alpha function to apply
468    */
469   void AnimateBy(Property target, Property::Value relativeValue, AlphaFunction alpha);
470
471   /**
472    * @brief Animates a property value by a relative amount.
473    *
474    * The default alpha function will be used.
475    * @SINCE_1_0.0
476    * @param[in] target The target object/property to animate
477    * @param[in] relativeValue The property value will increase/decrease by this amount
478    * @param[in] period The effect will occur during this time period
479    */
480   void AnimateBy(Property target, Property::Value relativeValue, TimePeriod period);
481
482   /**
483    * @brief Animates a property value by a relative amount.
484    *
485    * @SINCE_1_0.0
486    * @param[in] target The target object/property to animate
487    * @param[in] relativeValue The property value will increase/decrease by this amount
488    * @param[in] alpha The alpha function to apply
489    * @param[in] period The effect will occur during this time period
490    */
491   void AnimateBy(Property target, Property::Value relativeValue, AlphaFunction alpha, TimePeriod period);
492
493   /**
494    * @brief Animates a property to a destination value.
495    *
496    * The default alpha function will be used.
497    * The effect will start & end when the animation begins & ends.
498    * @SINCE_1_0.0
499    * @param[in] target The target object/property to animate
500    * @param[in] destinationValue The destination value
501    */
502   void AnimateTo(Property target, Property::Value destinationValue);
503
504   /**
505    * @brief Animates a property to a destination value.
506    *
507    * The effect will start & end when the animation begins & ends.
508    * @SINCE_1_0.0
509    * @param[in] target The target object/property to animate
510    * @param[in] destinationValue The destination value
511    * @param[in] alpha The alpha function to apply
512    */
513   void AnimateTo(Property target, Property::Value destinationValue, AlphaFunction alpha);
514
515   /**
516    * @brief Animates a property to a destination value.
517    *
518    * The default alpha function will be used.
519    * @SINCE_1_0.0
520    * @param[in] target The target object/property to animate
521    * @param[in] destinationValue The destination value
522    * @param[in] period The effect will occur during this time period
523    */
524   void AnimateTo(Property target, Property::Value destinationValue, TimePeriod period);
525
526   /**
527    * @brief Animates a property to a destination value.
528    *
529    * @SINCE_1_0.0
530    * @param[in] target The target object/property to animate
531    * @param[in] destinationValue The destination value
532    * @param[in] alpha The alpha function to apply
533    * @param[in] period The effect will occur during this time period
534    */
535   void AnimateTo(Property target, Property::Value destinationValue, AlphaFunction alpha, TimePeriod period);
536
537    /**
538    * @brief Animates a property between keyframes.
539    *
540    * @SINCE_1_0.0
541    * @param[in] target The target object property to animate
542    * @param[in] keyFrames The set of time/value pairs between which to animate
543    */
544   void AnimateBetween(Property target, KeyFrames& keyFrames);
545
546   /**
547    * @brief Animates a property between keyframes.
548    *
549    * @SINCE_1_0.0
550    * @param[in] target The target object property to animate
551    * @param[in] keyFrames The set of time/value pairs between which to animate
552    * @param[in] interpolation The method used to interpolate between values
553    */
554   void AnimateBetween(Property target, KeyFrames& keyFrames, Interpolation interpolation);
555
556   /**
557    * @brief Animates a property between keyframes.
558    *
559    * @SINCE_1_0.0
560    * @param[in] target The target object property to animate
561    * @param[in] keyFrames The set of time/value pairs between which to animate
562    * @param[in] alpha The alpha function to apply
563    */
564   void AnimateBetween(Property target, KeyFrames& keyFrames, AlphaFunction alpha);
565
566   /**
567    * @brief Animates a property between keyframes.
568    *
569    * @SINCE_1_0.0
570    * @param[in] target The target object property to animate
571    * @param[in] keyFrames The set of time/value pairs between which to animate
572    * @param[in] alpha The alpha function to apply
573    * @param[in] interpolation The method used to interpolate between values
574    */
575   void AnimateBetween(Property target, KeyFrames& keyFrames, AlphaFunction alpha, Interpolation interpolation);
576
577   /**
578    * @brief Animates a property between keyframes.
579    *
580    * @SINCE_1_0.0
581    * @param[in] target The target object property to animate
582    * @param[in] keyFrames The set of time/value pairs between which to animate
583    * @param[in] period The effect will occur during this time period
584    */
585   void AnimateBetween(Property target, KeyFrames& keyFrames, TimePeriod period);
586
587   /**
588    * @brief Animates a property between keyframes.
589    *
590    * @SINCE_1_0.0
591    * @param[in] target The target object property to animate
592    * @param[in] keyFrames The set of time/value pairs between which to animate
593    * @param[in] period The effect will occur duing this time period
594    * @param[in] interpolation The method used to interpolate between values
595    */
596   void AnimateBetween(Property target, KeyFrames& keyFrames, TimePeriod period, Interpolation interpolation);
597
598   /**
599    * @brief Animates a property between keyframes.
600    *
601    * @SINCE_1_0.0
602    * @param[in] target The target object property to animate
603    * @param[in] keyFrames The set of time/value pairs between which to animate
604    * @param[in] alpha The alpha function to apply
605    * @param[in] period The effect will occur during this time period
606    */
607   void AnimateBetween(Property target, KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period);
608
609   /**
610    * @brief Animates a property between keyframes.
611    *
612    * @SINCE_1_0.0
613    * @param[in] target The target object property to animate
614    * @param[in] keyFrames The set of time/value pairs between which to animate
615    * @param[in] alpha The alpha function to apply to the overall progress
616    * @param[in] period The effect will occur duing this time period
617    * @param[in] interpolation The method used to interpolate between values
618    */
619   void AnimateBetween(Property target, KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period, Interpolation interpolation);
620
621
622   // Actor-specific convenience methods
623
624   /**
625    * @brief Animates an actor's position and orientation through a predefined path.
626    *
627    * The actor will rotate to orient the supplied
628    * forward vector with the path's tangent. If forward is the zero vector then no rotation will happen.
629    *
630    * @SINCE_1_0.0
631    * @param[in] actor The actor to animate
632    * @param[in] path The path. It defines position and orientation
633    * @param[in] forward The vector (in local space coordinate system) that will be oriented with the path's tangent direction
634    */
635   void Animate( Actor actor, Path path, const Vector3& forward );
636
637   /**
638    * @brief Animates an actor's position and orientation through a predefined path.
639    *
640    * The actor will rotate to orient the supplied
641    * forward vector with the path's tangent. If forward is the zero vector then no rotation will happen.
642    *
643    * @SINCE_1_0.0
644    * @param[in] actor The actor to animate
645    * @param[in] path The path. It defines position and orientation
646    * @param[in] forward The vector (in local space coordinate system) that will be oriented with the path's tangent direction
647    * @param[in] alpha The alpha function to apply
648    */
649   void Animate( Actor actor, Path path, const Vector3& forward, AlphaFunction alpha );
650
651   /**
652    * @brief Animates an actor's position and orientation through a predefined path.
653    *
654    * The actor will rotate to orient the supplied
655    * forward vector with the path's tangent. If forward is the zero vector then no rotation will happen.
656    *
657    * @SINCE_1_0.0
658    * @param[in] actor The actor to animate
659    * @param[in] path The path. It defines position and orientation
660    * @param[in] forward The vector (in local space coordinate system) that will be oriented with the path's tangent direction
661    * @param[in] period The effect will occur during this time period
662    */
663   void Animate( Actor actor, Path path, const Vector3& forward, TimePeriod period );
664
665   /**
666    * @brief Animates an actor's position and orientation through a predefined path.
667    *
668    * The actor will rotate to orient the supplied
669    * forward vector with the path's tangent. If forward is the zero vector then no rotation will happen.
670    *
671    * @SINCE_1_0.0
672    * @param[in] actor The actor to animate
673    * @param[in] path The path. It defines position and orientation
674    * @param[in] forward The vector (in local space coordinate system) that will be oriented with the path's tangent direction
675    * @param[in] alpha The alpha function to apply
676    * @param[in] period The effect will occur during this time period
677    */
678   void Animate( Actor actor, Path path, const Vector3& forward, AlphaFunction alpha, TimePeriod period);
679
680   /**
681    * @brief Shows an actor during the animation.
682    *
683    * @SINCE_1_0.0
684    * @param[in] actor The actor to animate
685    * @param[in] delaySeconds The initial delay from the start of the animation
686    */
687   void Show(Actor actor, float delaySeconds);
688
689   /**
690    * @brief Hides an actor during the animation.
691    *
692    * @SINCE_1_0.0
693    * @param[in] actor The actor to animate
694    * @param[in] delaySeconds The initial delay from the start of the animation
695    */
696   void Hide(Actor actor, float delaySeconds);
697
698 public: // Not intended for use by Application developers
699
700   /**
701    * @internal
702    * @brief This constructor is used by Animation::New() methods.
703    * @SINCE_1_0.0
704    * @param[in] animation A pointer to a newly allocated Dali resource
705    */
706   explicit DALI_INTERNAL Animation(Internal::Animation* animation);
707
708 };
709
710 /**
711  * @}
712  */
713 } // namespace Dali
714
715 #endif // __DALI_ANIMATION_H__