b3289ec4d0b97e37e8d964011259de98c1eae69c
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / transition / transition-base-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_TRANSITION_BASE_H
2 #define DALI_TOOLKIT_INTERNAL_TRANSITION_BASE_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/public-api/controls/control.h>
23 #include <dali-toolkit/public-api/transition/transition-base.h>
24 #include <dali-toolkit/public-api/transition/transition-set.h>
25
26 // EXTERNAL INCLUDES
27 #include <dali/public-api/animation/animation.h>
28 #include <dali/public-api/object/base-object.h>
29 #include <dali/public-api/object/property-map.h>
30
31 namespace Dali
32 {
33 namespace Toolkit
34 {
35 namespace Internal
36 {
37 using TransitionBasePtr = IntrusivePtr<TransitionBase>;
38
39 class TransitionBase : public BaseObject
40 {
41 public:
42   /**
43    * @brief Create a new TransitionBase object.
44    * @return A smart-pointer to the newly allocated TransitionBase.
45    */
46   static TransitionBasePtr New();
47
48   /**
49    * @copydoc Dali::Toolkit::TransitionBase::SetTimePeriod()
50    */
51   void SetTimePeriod(const Dali::TimePeriod& timePeriod);
52
53   /**
54    * @copydoc Dali::Toolkit::TransitionBase::GetTimePeriod()
55    */
56   Dali::TimePeriod GetTimePeriod() const;
57
58   /**
59    * @copydoc Dali::Toolkit::TransitionBase::SetAlphaFunction()
60    */
61   void SetAlphaFunction(AlphaFunction alphaFunction)
62   {
63     mAlphaFunction = alphaFunction;
64   }
65
66   /**
67    * @copydoc Dali::Toolkit::TransitionBase::GetAlphaFunction()
68    */
69   AlphaFunction GetAlphaFunction() const
70   {
71     return mAlphaFunction;
72   }
73
74   /**
75    * @copydoc Dali::Toolkit::TransitionBase::TransitionWithChild()
76    */
77   void TransitionWithChild(bool transitionWithChild);
78
79   /**
80    * @brief Run processes those are required done before size/position negotiation.
81    * @param[in] animation animation for the transition
82    */
83   void PreProcess(Dali::Animation animation);
84
85   /**
86    * @brief Make property animation for Transition
87    */
88   void Play();
89
90   /**
91    * Emit the Finished signal
92    */
93   void TransitionFinished();
94
95   /**
96    * @brief Set this transition is appearing transition or not.
97    * @param[in] appearingTransition True if this transition is appearing transition.
98    */
99   void SetAppearingTransition(bool appearingTransition)
100   {
101     mIsAppearingTransition = appearingTransition;
102   }
103
104 protected:
105   /**
106    * @brief Set property map which will be used as a initial properties.
107    * @param[in] propertyMap propertyMap that will be used as a start value of transition.
108    */
109   void SetInitialPropertyMap(const Property::Map& propertyMap)
110   {
111     mInitialPropertyMap = propertyMap;
112   }
113   /**
114    * @brief Set property map which will be used as a animation start properties.
115    * @param[in] propertyMap propertyMap that will be used as a start value of transition.
116    */
117   void SetStartPropertyMap(const Property::Map& propertyMap)
118   {
119     mStartPropertyMap = propertyMap;
120   }
121
122   /**
123    * @brief Set property map which will be used as a animation finish properties.
124    * @param[in] propertyMap propertyMap that will be used as a finish value of transition.
125    */
126   void SetFinishPropertyMap(const Property::Map& propertyMap)
127   {
128     mFinishPropertyMap = propertyMap;
129   }
130
131   /**
132    * @brief Retrieve animation.
133    */
134   Dali::Animation GetAnimation()
135   {
136     return mAnimation;
137   }
138
139   /**
140    * @brief Set target which will be transition.
141    * @param[in] target control that will be transition.
142    */
143   void SetTarget(Dali::Toolkit::Control target)
144   {
145     mTarget = target;
146   }
147
148   /**
149    * @brief Gets world transform of input Actor.
150    * @param[in] actor actor for get world transform.
151    */
152   Matrix GetWorldTransform(Dali::Actor actor);
153
154   /**
155    * @brief Gets world color of input Actor.
156    * @param[in] actor actor for get world color.
157    */
158   Vector4 GetWorldColor(Dali::Actor actor);
159
160   /**
161    * @brief Returns whether this transition will be applied to children of target or not.
162    */
163   bool IsTransitionWithChild() const
164   {
165     return mTransitionWithChild;
166   }
167
168   /**
169    * @brief Returns whether this transition is appearing transition or not
170    */
171   bool IsAppearingTransition() const
172   {
173     return mIsAppearingTransition;
174   }
175
176 protected:
177   /**
178    * Construct a new TransitionBase.
179    */
180   TransitionBase();
181
182   /**
183    * Second-phase constructor.
184    */
185   void Initialize();
186
187   /**
188    * Destructor
189    */
190   ~TransitionBase() = default;
191
192 private:
193   // Undefined
194   TransitionBase(const TransitionBase&);
195
196   // Undefined
197   TransitionBase& operator=(const TransitionBase& rhs);
198
199 private:
200   /**
201    * @brief Makes property animation for transition.
202    */
203   void SetAnimation();
204
205   /**
206    * @brief Adds a property on an animation between sourceValue and destimationValue.
207    * @param[in] target target control to be animated.
208    * @param[in] index property index for animation.
209    * @param[in] initialValue initial value of animation.
210    * @param[in] sourceValue source value of animation.
211    * @param[in] destinationValue destination value of animation.
212    */
213   void AnimateBetween(Dali::Toolkit::Control target, Property::Index index, Property::Value initialValue, Property::Value sourceValue, Property::Value destinationValue);
214
215   /**
216    * @brief Copy target to make clone for the child Actors
217    */
218   void CopyTarget();
219
220   /**
221    * @brief Make pair of Property::Map to be used for transition animation.
222    * Set the pair of Property::Map by using SetStartPropertyMap() and SetFinishPropertyMap(),
223    * then the properties of mTarget will be animated between them during transition duration.
224    * If the transition requires the information of world transform, let them be in this method.
225    * World transform and World color can be retrieved by using GetWorldTransform() and GetWorldColor() methods.
226    * And If it is needed to add additional custom animation than use GetAnimation() and add them.
227    *
228    * @note Do not set any properties in this methods.
229    */
230   virtual void OnPlay()
231   {
232   }
233
234   /**
235    * @brief If the transition is needed to do something after the transition is finished, let them be in this method.
236    */
237   virtual void OnFinished()
238   {
239   }
240
241 private:
242   Dali::Toolkit::Control       mTarget;              ///< Target that will be animated.
243   Dali::Actor                  mCopiedActor;         ///< Copied View that will replace mTarget during transition
244   Dali::Animation              mAnimation;           ///< Property animations for the transition of mTarget
245   AlphaFunction                mAlphaFunction;       ///< Alpha function that will applied for the property animation
246   Property::Map                mInitialPropertyMap;  ///< Initial properties to be animated. (world transform)
247   Property::Map                mStartPropertyMap;    ///< Start properties to be animated. (world transform)
248   Property::Map                mFinishPropertyMap;   ///< Finish properties to be animated. (world transform)
249   Property::Map                mOriginalPropertyMap; ///< Original properties of mTarget to be used to restore after the transition is finished.
250   Dali::TimePeriod             mTimePeriod;          ///< TimePeriod of transition
251   bool                         mTransitionWithChild; ///< True, if mTarget transition is inherit to its child Actors.
252                                                      ///< If this is false, the child Actors are moved to the child of mCopiedActor that will have original properties of target Actor during Transition.
253   bool mMoveTargetChildren;                          ///< Flag, if mTransitionWithChild is false and mTarget has children than True.
254   bool mIsAppearingTransition;                       ///< True, if this transition is appearing transition.
255 };
256
257 } // namespace Internal
258
259 // Helpers for public-api forwarding methods
260
261 inline Internal::TransitionBase& GetImplementation(Dali::Toolkit::TransitionBase& animation)
262 {
263   DALI_ASSERT_ALWAYS(animation && "TransitionBase handle is empty");
264
265   BaseObject& handle = animation.GetBaseObject();
266
267   return static_cast<Internal::TransitionBase&>(handle);
268 }
269
270 inline const Internal::TransitionBase& GetImplementation(const Dali::Toolkit::TransitionBase& animation)
271 {
272   DALI_ASSERT_ALWAYS(animation && "TransitionBase handle is empty");
273
274   const BaseObject& handle = animation.GetBaseObject();
275
276   return static_cast<const Internal::TransitionBase&>(handle);
277 }
278
279 } // namespace Toolkit
280
281 } // namespace Dali
282
283 #endif // DALI_TOOLKIT_INTERNAL_TRANSITION_BASE_H