[dali_2.3.34] 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/set-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    * @param[in] animation The animation that is cleared.
79    * @param[in] ignoreRequired Whether to ignore the notify for current event loop, or not.
80    * @post The animation will no longer be referenced by AnimationPlaylist.
81    */
82   void OnClear(Animation& animation, bool ignoreRequired);
83
84   /**
85    * Notify from core that current event loop finisehd.
86    * It will clear all ignored animations at OnClear.
87    */
88   void EventLoopFinished();
89
90   /**
91    * @brief Notify that an animation has reached a progress marker
92    * @param[in] notifyId scene graph animation's notifyId that has reached progress
93    */
94   void NotifyProgressReached(NotifierInterface::NotifyId notifyId);
95
96   /**
97    * @brief Retrive the number of Animations.
98    *
99    * @return The number of Animations.
100    */
101   uint32_t GetAnimationCount();
102
103   /**
104    * @brief Retrieve an Animation by index.
105    *
106    * @param[in] index The index of the Animation to retrieve
107    * @return The Dali::Animation for the given index or empty handle
108    */
109   Dali::Animation GetAnimationAt(uint32_t index);
110
111 private:
112   /**
113    * Create an AnimationPlaylist.
114    */
115   AnimationPlaylist();
116
117   // Undefined
118   AnimationPlaylist(const AnimationPlaylist&);
119
120   // Undefined
121   AnimationPlaylist& operator=(const AnimationPlaylist& rhs);
122
123 private: // from CompleteNotificationInterface
124   /**
125    * @copydoc CompleteNotificationInterface::NotifyCompleted()
126    */
127   void NotifyCompleted(CompleteNotificationInterface::ParameterList notifierList) override;
128
129 private:
130   Integration::OrderedSet<Animation, false> mAnimations;        ///< All existing animations (not owned)
131   std::set<Dali::Animation>                 mPlaylist;          ///< The currently playing animations (owned through handle).
132   std::set<NotifierInterface::NotifyId>     mIgnoredAnimations; ///< The currently cleard animations. We should not send notification at NotifyCompleted.
133 };
134
135 /**
136  * Called when an animation reaches a progress marker
137  *
138  * Note animationPlaylist is of type CompleteNotificationInterface because of updateManager only knowing about the interface not actual playlist
139  */
140 inline MessageBase* NotifyProgressReachedMessage(CompleteNotificationInterface& animationPlaylist, NotifierInterface::NotifyId notifyId)
141 {
142   return new MessageValue1<AnimationPlaylist, NotifierInterface::NotifyId>(static_cast<AnimationPlaylist*>(&animationPlaylist), &AnimationPlaylist::NotifyProgressReached, notifyId);
143 }
144
145 } // namespace Internal
146
147 } // namespace Dali
148
149 #endif // DALI_INTERNAL_ANIMATION_PLAYLIST_H