Apply the new doxygen tagging rule for @SINCE
[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 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 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 Create an uninitialized Animation; this can be initialized with Animation::New().
144    *
145    * Calling member functions with an uninitialized Dali::Object is not allowed.
146    * @SINCE_1_0.0
147    */
148   Animation();
149
150   /**
151    * @brief Create an initialized Animation.
152    *
153    * The animation will not loop.
154    * The default end action is "Bake".
155    * The default alpha function is linear.
156    * @SINCE_1_0.0
157    * @param [in] durationSeconds The duration in seconds.
158    * @return A handle to a newly allocated Dali resource.
159    * @pre durationSeconds must be greater than zero.
160    */
161   static Animation New(float durationSeconds);
162
163   /**
164    * @brief Downcast an Object handle to Animation.
165    *
166    * If handle points to an Animation object the downcast produces
167    * valid handle. If not the returned handle is left uninitialized.
168    *
169    * @SINCE_1_0.0
170    * @param[in] handle to An object
171    * @return handle to a Animation object or an uninitialized handle
172    */
173   static Animation DownCast( BaseHandle handle );
174
175   /**
176    * @brief Destructor
177    *
178    * This is non-virtual since derived Handle types must not contain data or virtual methods.
179    * @SINCE_1_0.0
180    */
181   ~Animation();
182
183   /**
184    * @brief This copy constructor is required for (smart) pointer semantics.
185    *
186    * @SINCE_1_0.0
187    * @param [in] handle A reference to the copied handle
188    */
189   Animation(const Animation& handle);
190
191   /**
192    * @brief This assignment operator is required for (smart) pointer semantics.
193    *
194    * @SINCE_1_0.0
195    * @param [in] rhs  A reference to the copied handle
196    * @return A reference to this
197    */
198   Animation& operator=(const Animation& rhs);
199
200   /**
201    * @brief Set the duration of an animation.
202    *
203    * @SINCE_1_0.0
204    * @param[in] seconds The duration in seconds.
205    * @pre durationSeconds must be greater than zero.
206    */
207   void SetDuration(float seconds);
208
209   /**
210    * @brief Retrieve the duration of an animation.
211    *
212    * @SINCE_1_0.0
213    * @return The duration in seconds.
214    */
215   float GetDuration() const;
216
217   /**
218    * @brief Set whether the animation will loop.
219    *
220    * @SINCE_1_0.0
221    * @param[in] looping True if the animation will loop.
222    */
223   void SetLooping(bool looping);
224
225   /**
226    * @brief Query whether the animation will loop.
227    *
228    * @SINCE_1_0.0
229    * @return True if the animation will loop.
230    */
231   bool IsLooping() const;
232
233   /**
234    * @brief Set the end action of the animation.
235    *
236    * This action is performed when the animation ends or if it is stopped.
237    * Default end action is bake
238    * @SINCE_1_0.0
239    * @param[in] action The end action.
240    */
241   void SetEndAction(EndAction action);
242
243   /**
244    * @brief Returns the end action of the animation.
245    *
246    * @SINCE_1_0.0
247    * @return The end action.
248    */
249   EndAction GetEndAction() const;
250
251   /**
252    * @brief Set the disconnect action.
253    *
254    * If any of the animated property owners are disconnected from the stage while the animation is being played, then this action is performed.
255    * Default action is to BakeFinal.
256    * @SINCE_1_0.0
257    * @param[in] disconnectAction The disconnect action.
258    */
259   void SetDisconnectAction( EndAction disconnectAction );
260
261   /**
262    * @brief Returns the disconnect action.
263    *
264    * @SINCE_1_0.0
265    * @return The disconnect action.
266    */
267   EndAction GetDisconnectAction() const;
268
269   /**
270    * @brief Set the default alpha function for an animation.
271    *
272    * This is applied to individual property animations, if no further alpha functions are supplied.
273    * @SINCE_1_0.0
274    * @param[in] alpha The default alpha function.
275    */
276   void SetDefaultAlphaFunction(AlphaFunction alpha);
277
278   /**
279    * @brief Retrieve the default alpha function for an animation.
280    *
281    * @SINCE_1_0.0
282    * @return The default alpha function.
283    */
284   AlphaFunction GetDefaultAlphaFunction() const;
285
286   /*
287    * @brief Sets the progress of the animation.
288    *
289    * When played, the animation will start from this point.
290    * If playing, the animation will jump to, and continue playing from this point.
291    *
292    * The progress must be in the 0-1 interval or in the play range interval
293    * if defined ( See SetPlayRange ), otherwise, it will be ignored.
294    *
295    * @param[in] progress The new progress as a normalized value between [0,1]
296    * or between the play range if specified.
297    */
298   void SetCurrentProgress( float progress );
299
300   /**
301   * @brief Retrieve the current progress of the animation.
302   *
303   * @SINCE_1_0.0
304   * @return The current progress as a normalized value between [0,1].
305   */
306   float GetCurrentProgress();
307
308   /**
309    * @brief Specifies an speed factor for the animation.
310    *
311    * The speed factor is a multiplier of the normal velocity of the animation. Values between [0,1] will
312    * slow down the animation and values above one will speed up the animation. It is also possible to specify a negative multiplier
313    * to play the animation in reverse.
314    *
315    * @SINCE_1_0.0
316    * @param[in] factor A value which will multiply the velocity.
317    */
318   void SetSpeedFactor( float factor );
319
320   /**
321    * @brief Retrieve the speed factor of the animation
322    *
323    * @SINCE_1_0.0
324    * @return speed factor
325    */
326   float GetSpeedFactor() const;
327
328   /**
329    * @brief Set the playing range.
330    * Animation will play between the values specified. Both values ( range.x and range.y ) should be between 0-1,
331    * otherwise they will be ignored. If the range provided is not in proper order ( minimum,maximum ), it will be reordered.
332    *
333    * @SINCE_1_0.0
334    * @param[in] range Two values between [0,1] to specify minimum and maximum progress. The
335    * animation will play between those values.
336    */
337   void SetPlayRange( const Vector2& range );
338
339   /**
340    * @brief Get the playing range
341    *
342    * @SINCE_1_0.0
343    * @return The play range defined for the animation.
344    */
345   Vector2 GetPlayRange() const;
346
347   /**
348    * @brief Play the animation.
349    * @SINCE_1_0.0
350    */
351   void Play();
352
353   /**
354    * @brief Play the animation from a given point.
355    * The progress must be in the 0-1 interval or in the play range interval if defined ( See SetPlayRange ),
356    * otherwise, it will be ignored.
357    *
358    * @SINCE_1_0.0
359    * @param[in] progress A value between [0,1], or between the play range if specified, form where the animation should start playing
360    */
361   void PlayFrom( float progress );
362
363   /**
364    * @brief Pause the animation.
365    * @SINCE_1_0.0
366    */
367   void Pause();
368
369   /**
370    * @brief Stop the animation.
371    * @SINCE_1_0.0
372    */
373   void Stop();
374
375   /**
376    * @brief Clear the animation.
377    *
378    * This disconnects any objects that were being animated, effectively stopping the animation.
379    * @SINCE_1_0.0
380    */
381   void Clear();
382
383   /**
384    * @brief Connect to this signal to be notified when an Animation's animations have finished.
385    *
386    * @SINCE_1_0.0
387    * @return A signal object to Connect() with.
388    */
389   AnimationSignalType& FinishedSignal();
390
391   /**
392    * @brief Animate a property value by a relative amount.
393    *
394    * The default alpha function will be used.
395    * The effect will start & end when the animation begins & ends.
396    * @SINCE_1_0.0
397    * @param [in] target The target object/property to animate.
398    * @param [in] relativeValue The property value will change by this amount.
399    */
400   void AnimateBy(Property target, Property::Value relativeValue);
401
402   /**
403    * @brief Animate a property value by a relative amount.
404    *
405    * The effect will start & end when the animation begins & ends.
406    * @SINCE_1_0.0
407    * @param [in] target The target object/property to animate.
408    * @param [in] relativeValue The property value will change by this amount.
409    * @param [in] alpha The alpha function to apply.
410    */
411   void AnimateBy(Property target, Property::Value relativeValue, AlphaFunction alpha);
412
413   /**
414    * @brief Animate a property value by a relative amount.
415    *
416    * The default alpha function will be used.
417    * @SINCE_1_0.0
418    * @param [in] target The target object/property to animate.
419    * @param [in] relativeValue The property value will increase/decrease by this amount.
420    * @param [in] period The effect will occur during this time period.
421    */
422   void AnimateBy(Property target, Property::Value relativeValue, TimePeriod period);
423
424   /**
425    * @brief Animate a property value by a relative amount.
426    *
427    * @SINCE_1_0.0
428    * @param [in] target The target object/property to animate.
429    * @param [in] relativeValue The property value will increase/decrease by this amount.
430    * @param [in] alpha The alpha function to apply.
431    * @param [in] period The effect will occur during this time period.
432    */
433   void AnimateBy(Property target, Property::Value relativeValue, AlphaFunction alpha, TimePeriod period);
434
435   /**
436    * @brief Animate a property to a destination value.
437    *
438    * The default alpha function will be used.
439    * The effect will start & end when the animation begins & ends.
440    * @SINCE_1_0.0
441    * @param [in] target The target object/property to animate.
442    * @param [in] destinationValue The destination value.
443    */
444   void AnimateTo(Property target, Property::Value destinationValue);
445
446   /**
447    * @brief Animate a property to a destination value.
448    *
449    * The effect will start & end when the animation begins & ends.
450    * @SINCE_1_0.0
451    * @param [in] target The target object/property to animate.
452    * @param [in] destinationValue The destination value.
453    * @param [in] alpha The alpha function to apply.
454    */
455   void AnimateTo(Property target, Property::Value destinationValue, AlphaFunction alpha);
456
457   /**
458    * @brief Animate a property to a destination value.
459    *
460    * The default alpha function will be used.
461    * @SINCE_1_0.0
462    * @param [in] target The target object/property to animate.
463    * @param [in] destinationValue The destination value.
464    * @param [in] period The effect will occur during this time period.
465    */
466   void AnimateTo(Property target, Property::Value destinationValue, TimePeriod period);
467
468   /**
469    * @brief Animate a property to a destination value.
470    *
471    * @SINCE_1_0.0
472    * @param [in] target The target object/property to animate.
473    * @param [in] destinationValue The destination value.
474    * @param [in] alpha The alpha function to apply.
475    * @param [in] period The effect will occur during this time period.
476    */
477   void AnimateTo(Property target, Property::Value destinationValue, AlphaFunction alpha, TimePeriod period);
478
479    /**
480    * @brief Animate a property between keyframes.
481    *
482    * @SINCE_1_0.0
483    * @param [in] target The target object/property to animate.
484    * @param [in] keyFrames The key frames
485    */
486   void AnimateBetween(Property target, KeyFrames& keyFrames);
487
488   /**
489    * @brief Animate a property between keyframes.
490    *
491    * @SINCE_1_0.0
492    * @param [in] target The target object + property to animate
493    * @param [in] keyFrames The set of time / value pairs between which to animate.
494    * @param [in] interpolation The method used to interpolate between values.
495    */
496   void AnimateBetween(Property target, KeyFrames& keyFrames, Interpolation interpolation);
497
498   /**
499    * @brief Animate a property between keyframes.
500    *
501    * @SINCE_1_0.0
502    * @param [in] target The target object/property to animate.
503    * @param [in] keyFrames The key frames
504    * @param [in] alpha The alpha function to apply.
505    */
506   void AnimateBetween(Property target, KeyFrames& keyFrames, AlphaFunction alpha);
507
508   /**
509    * @brief Animate a property between keyframes.
510    *
511    * @SINCE_1_0.0
512    * @param [in] target The target object + property to animate
513    * @param [in] keyFrames The set of time / value pairs between which to animate.
514    * @param [in] alpha The alpha function to apply.
515    * @param [in] interpolation The method used to interpolate between values.
516    */
517   void AnimateBetween(Property target, KeyFrames& keyFrames, AlphaFunction alpha, Interpolation interpolation);
518
519   /**
520    * @brief Animate a property between keyframes.
521    *
522    * @SINCE_1_0.0
523    * @param [in] target The target object/property to animate.
524    * @param [in] keyFrames The key frames
525    * @param [in] period The effect will occur during this time period.
526    */
527   void AnimateBetween(Property target, KeyFrames& keyFrames, TimePeriod period);
528
529   /**
530    * @brief Animate a property between keyframes.
531    *
532    * @SINCE_1_0.0
533    * @param [in] target The target object + property to animate
534    * @param [in] keyFrames The set of time / value pairs between which to animate.
535    * @param [in] period The effect will occur duing this time period.
536    * @param [in] interpolation The method used to interpolate between values.
537    */
538   void AnimateBetween(Property target, KeyFrames& keyFrames, TimePeriod period, Interpolation interpolation);
539
540   /**
541    * @brief Animate a property between keyframes.
542    *
543    * @SINCE_1_0.0
544    * @param [in] target The target object/property to animate.
545    * @param [in] keyFrames The key frames
546    * @param [in] alpha The alpha function to apply.
547    * @param [in] period The effect will occur during this time period.
548    */
549   void AnimateBetween(Property target, KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period);
550
551   /**
552    * @brief Animate a property between keyframes.
553    *
554    * @SINCE_1_0.0
555    * @param [in] target The target object + property to animate
556    * @param [in] keyFrames The set of time / value pairs between which to animate.
557    * @param [in] alpha The alpha function to apply to the overall progress.
558    * @param [in] period The effect will occur duing this time period.
559    * @param [in] interpolation The method used to interpolate between values.
560    */
561   void AnimateBetween(Property target, KeyFrames& keyFrames, AlphaFunction alpha, TimePeriod period, Interpolation interpolation);
562
563
564   // Actor-specific convenience methods
565
566   /**
567    * @brief Animate an actor's position and orientation through a predefined path. The actor will rotate to orient the supplied
568    * forward vector with the path's tangent. If forward is the zero vector then no rotation will happen.
569    *
570    * @SINCE_1_0.0
571    * @param[in] actor The actor to animate
572    * @param[in] path The path. It defines position and orientation
573    * @param[in] forward The vector (in local space coordinate system) that will be oriented with the path's tangent direction
574    */
575   void Animate( Actor actor, Path path, const Vector3& forward );
576
577   /**
578    * @brief Animate an actor's position and orientation through a predefined path. The actor will rotate to orient the supplied
579    * forward vector with the path's tangent. If forward is the zero vector then no rotation will happen.
580    *
581    * @SINCE_1_0.0
582    * @param[in] actor The actor to animate
583    * @param[in] path The path. It defines position and orientation
584    * @param[in] forward The vector (in local space coordinate system) that will be oriented with the path's tangent direction
585    * @param [in] alpha The alpha function to apply.
586    */
587   void Animate( Actor actor, Path path, const Vector3& forward, AlphaFunction alpha );
588
589   /**
590    * @brief Animate an actor's position and orientation through a predefined path. The actor will rotate to orient the supplied
591    * forward vector with the path's tangent. If forward is the zero vector then no rotation will happen.
592    *
593    * @SINCE_1_0.0
594    * @param[in] actor The actor to animate
595    * @param[in] path The path. It defines position and orientation
596    * @param[in] forward The vector (in local space coordinate system) that will be oriented with the path's tangent direction
597    * @param [in] period The effect will occur during this time period.
598    */
599   void Animate( Actor actor, Path path, const Vector3& forward, TimePeriod period );
600
601   /**
602    * @brief Animate an actor's position and orientation through a predefined path. The actor will rotate to orient the supplied
603    * forward vector with the path's tangent. If forward is the zero vector then no rotation will happen.
604    *
605    * @SINCE_1_0.0
606    * @param[in] actor The actor to animate
607    * @param[in] path The path. It defines position and orientation
608    * @param[in] forward The vector (in local space coordinate system) that will be oriented with the path's tangent direction
609    * @param [in] alpha The alpha function to apply.
610    * @param [in] period The effect will occur during this time period.
611    */
612   void Animate( Actor actor, Path path, const Vector3& forward, AlphaFunction alpha, TimePeriod period);
613
614   /**
615    * @brief Show an actor during the animation.
616    *
617    * @SINCE_1_0.0
618    * @param [in] actor The actor to animate.
619    * @param [in] delaySeconds The initial delay from the start of the animation.
620    */
621   void Show(Actor actor, float delaySeconds);
622
623   /**
624    * @brief Hide an actor during the animation.
625    *
626    * @SINCE_1_0.0
627    * @param [in] actor The actor to animate.
628    * @param [in] delaySeconds The initial delay from the start of the animation.
629    */
630   void Hide(Actor actor, float delaySeconds);
631
632 public: // Not intended for use by Application developers
633
634   /**
635    * @brief This constructor is used by Dali New() methods
636    * @SINCE_1_0.0
637    * @param [in] animation A pointer to a newly allocated Dali resource
638    */
639   explicit DALI_INTERNAL Animation(Internal::Animation* animation);
640
641 };
642
643 /**
644  * @}
645  */
646 } // namespace Dali
647
648 #endif // __DALI_ANIMATION_H__