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