DALi Version 2.1.5
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / transition / transition-set-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_TRANSITION_SET_H
2 #define DALI_TOOLKIT_INTERNAL_TRANSITION_SET_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-toolkit/internal/transition/transition-impl.h>
23 #include <dali-toolkit/public-api/transition/transition-set.h>
24
25 // EXTERNAL INCLUDES
26 #include <dali/integration-api/processor-interface.h>
27 #include <dali/public-api/object/base-object.h>
28 #include <dali/public-api/signals/connection-tracker.h>
29
30 namespace Dali
31 {
32 namespace Toolkit
33 {
34 namespace Internal
35 {
36 using TransitionSetPtr = IntrusivePtr<TransitionSet>;
37
38 class TransitionSet : public BaseObject, public ConnectionTracker, public Integration::Processor
39 {
40 public:
41   /**
42    * Create a new TransitionSet object.
43    * @return A smart-pointer to the newly allocated TransitionSet.
44    */
45   static TransitionSetPtr New();
46
47   /**
48    * @copydoc Dali::Toolkit::TransitionSet::AddTransition(TransitionPtr transition)
49    */
50   void AddTransition(TransitionBasePtr transition);
51
52   /**
53    * @copydoc Dali::Toolkit::TransitionSet::GetTransitionAt(uint32_t index)
54    */
55   TransitionBase* GetTransitionAt(uint32_t index) const;
56
57   /**
58    * @copydoc Dali::Toolkit::TransitionSet::GetTransitionCount()
59    */
60   uint32_t GetTransitionCount() const;
61
62   /**
63    * @brief Make ready this transition set to play.
64    * Transitions in this transition set will be create property animations at the end of this tick of main thread.
65    */
66   void Play();
67
68   /**
69    * @copydoc Dali::Toolkit::TransitionSet::FinishedSignal()
70    */
71   Dali::Toolkit::TransitionSet::TransitionSetSignalType& FinishedSignal();
72
73   /**
74    * Connects a callback function with the object's signals.
75    * @param[in] object The object providing the signal.
76    * @param[in] tracker Used to disconnect the signal.
77    * @param[in] signalName The signal to connect to.
78    * @param[in] functor A newly allocated FunctorDelegate.
79    * @return True if the signal was connected.
80    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
81    */
82   static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
83
84 private:
85   /**
86    * @brief Set pre process of each transition.
87    */
88   void TransitionPreProcess();
89
90   /**
91    * @brief Start to play each of Transition.
92    * This method called at the end of event thread tick, and this method call OnPlay method of TransitionBase internally.
93    */
94   void TransitionStart();
95
96   /**
97    * @brief Remove each finished TransitionBase from play list.
98    * If all transitions are finished emit Finished signal.
99    */
100   void TransitionFinished(Dali::Animation& source);
101
102   /**
103    * Emit the Finished signal
104    */
105   void EmitFinishedSignal();
106
107 protected: // Implementation of Processor
108   /**
109    * @copydoc Dali::Integration::Processor::Process()
110    */
111   void Process(bool postProcessor) override;
112
113 protected:
114   /**
115    * Construct a new TransitionSet.
116    */
117   TransitionSet();
118
119   /**
120    * A reference counted object may only be deleted by calling Unreference()
121    */
122   ~TransitionSet() override;
123
124 private:
125   // Undefined
126   TransitionSet(const TransitionSet&);
127
128   // Undefined
129   TransitionSet& operator=(const TransitionSet& rhs);
130
131 private:
132   Dali::Toolkit::TransitionSet::TransitionSetSignalType mFinishedSignal{};
133   std::vector<TransitionBasePtr>                        mTransitions;
134   Dali::Animation                                       mAnimation;
135 };
136
137 } // namespace Internal
138
139 // Helpers for public-api forwarding methods
140
141 inline Internal::TransitionSet& GetImplementation(Dali::Toolkit::TransitionSet& transitionSet)
142 {
143   DALI_ASSERT_ALWAYS(transitionSet && "TransitionSet handle is empty");
144
145   BaseObject& handle = transitionSet.GetBaseObject();
146
147   return static_cast<Internal::TransitionSet&>(handle);
148 }
149
150 inline const Internal::TransitionSet& GetImplementation(const Dali::Toolkit::TransitionSet& transitionSet)
151 {
152   DALI_ASSERT_ALWAYS(transitionSet && "TransitionSet handle is empty");
153
154   const BaseObject& handle = transitionSet.GetBaseObject();
155
156   return static_cast<const Internal::TransitionSet&>(handle);
157 }
158
159 } // namespace Toolkit
160
161 } // namespace Dali
162
163 #endif // DALI_TOOLKIT_INTERNAL_TRANSITION_SET_H