Return Animation information
[platform/core/uifw/dali-core.git] / dali / internal / event / animation / animation-playlist.h
1 #ifndef DALI_INTERNAL_ANIMATION_PLAYLIST_H
2 #define DALI_INTERNAL_ANIMATION_PLAYLIST_H
3
4 /*
5  * Copyright (c) 2020 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/animation.h>
23 #include <dali/public-api/common/dali-vector.h>
24 #include <dali/public-api/common/vector-wrapper.h>
25 #include <dali/internal/common/message.h>
26 #include <dali/internal/event/common/complete-notification-interface.h>
27 #include <dali/internal/update/animation/scene-graph-animation.h>
28
29 namespace Dali
30 {
31
32 namespace Internal
33 {
34
35 class Animation;
36
37 /**
38  * AnimationPlaylist provides notifications to applications when animations are finished.
39  * It reference-counts playing animations, to allow "fire and forget" behaviour.
40  */
41 class AnimationPlaylist : public CompleteNotificationInterface
42 {
43 public:
44
45   /**
46    * Create an AnimationPlaylist.
47    * @return A newly allocated animation playlist.
48    */
49   static AnimationPlaylist* New();
50
51   /**
52    * Virtual destructor.
53    */
54   virtual ~AnimationPlaylist();
55
56   /**
57    * Called when an animation is constructed.
58    */
59   void AnimationCreated( Animation& animation );
60
61   /**
62    * Called when an animation is destroyed.
63    */
64   void AnimationDestroyed( Animation& animation );
65
66   /**
67    * Called when an animation is playing.
68    * @post The animation will be referenced by AnimationPlaylist, until the "Finished" signal is emitted.
69    */
70   void OnPlay( Animation& animation );
71
72   /**
73    * Called when an animation is cleared.
74    * @post The animation will no longer be referenced by AnimationPlaylist.
75    */
76   void OnClear( Animation& animation );
77
78   /**
79    * @brief Notify that an animation has reached a progress marker
80    * @param[in] sceneGraphAnimation scene graph animation that has reached progress
81    */
82   void NotifyProgressReached( const SceneGraph::Animation* sceneGraphAnimation );
83
84   /**
85    * @brief Retrive the number of Animations.
86    *
87    * @return The number of Animations.
88    */
89   uint32_t GetAnimationCount();
90
91   /**
92    * @brief Retrieve an Animation by index.
93    *
94    * @param[in] index The index of the Animation to retrieve
95    * @return The Dali::Animation for the given index or empty handle
96    */
97   Dali::Animation GetAnimationAt( uint32_t index );
98
99 private:
100
101   /**
102    * Create an AnimationPlaylist.
103    */
104   AnimationPlaylist();
105
106   // Undefined
107   AnimationPlaylist(const AnimationPlaylist&);
108
109   // Undefined
110   AnimationPlaylist& operator=(const AnimationPlaylist& rhs);
111
112 private: // from CompleteNotificationInterface
113
114   /**
115    * @copydoc CompleteNotificationInterface::NotifyCompleted()
116    */
117   virtual void NotifyCompleted();
118
119 private:
120
121   Dali::Vector< Animation* > mAnimations; ///< All existing animations (not owned)
122   std::vector< Dali::Animation > mPlaylist; ///< The currently playing animations (owned through handle)
123
124 };
125
126 /**
127  * Called when an animation reaches a progress marker
128  *
129  * Note animationPlaylist is of type CompleteNotificationInterface because of updateManager only knowing about the interface not actual playlist
130  */
131 inline MessageBase* NotifyProgressReachedMessage( CompleteNotificationInterface& animationPlaylist, const SceneGraph::Animation* animation )
132 {
133   return new MessageValue1< AnimationPlaylist, const SceneGraph::Animation* >( static_cast<AnimationPlaylist*>(&animationPlaylist), &AnimationPlaylist::NotifyProgressReached, animation );
134 }
135
136 } // namespace Internal
137
138 } // namespace Dali
139
140 #endif // DALI_INTERNAL_ANIMATION_PLAYLIST_H
141