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