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