2fa07871c09ea992871ef457f595c7c9eca978f8
[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) 2019 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 private:
85
86   /**
87    * Create an AnimationPlaylist.
88    */
89   AnimationPlaylist();
90
91   // Undefined
92   AnimationPlaylist(const AnimationPlaylist&);
93
94   // Undefined
95   AnimationPlaylist& operator=(const AnimationPlaylist& rhs);
96
97 private: // from CompleteNotificationInterface
98
99   /**
100    * @copydoc CompleteNotificationInterface::NotifyCompleted()
101    */
102   virtual void NotifyCompleted();
103
104 private:
105
106   Dali::Vector< Animation* > mAnimations; ///< All existing animations (not owned)
107   std::vector< Dali::Animation > mPlaylist; ///< The currently playing animations (owned through handle)
108
109 };
110
111 /**
112  * Called when an animation reaches a progress marker
113  *
114  * Note animationPlaylist is of type CompleteNotificationInterface because of updateManager only knowing about the interface not actual playlist
115  */
116 inline MessageBase* NotifyProgressReachedMessage( CompleteNotificationInterface& animationPlaylist, const SceneGraph::Animation* animation )
117 {
118   return new MessageValue1< AnimationPlaylist, const SceneGraph::Animation* >( static_cast<AnimationPlaylist*>(&animationPlaylist), &AnimationPlaylist::NotifyProgressReached, animation );
119 }
120
121 } // namespace Internal
122
123 } // namespace Dali
124
125 #endif // DALI_INTERNAL_ANIMATION_PLAYLIST_H
126