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