[Tizen] Adds transition effect
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / transition / transition-base-impl.h
1 #ifndef DALI_INTERNAL_TRANSITION_BASE_H
2 #define DALI_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::SetDuration()
50    */
51   void SetDuration(float seconds);
52
53   /**
54    * @copydoc Dali::Toolkit::TransitionBase::GetDuration()
55    */
56   float GetDuration() const;
57
58   /**
59    * @copydoc Dali::Toolkit::TransitionBase::SetDelay()
60    */
61   void SetDelay(float seconds);
62
63   /**
64    * @copydoc Dali::Toolkit::TransitionBase::GetDelay()
65    */
66   float GetDelay() const;
67
68   /**
69    * @copydoc Dali::Toolkit::TransitionBase::SetTimePeriod()
70    */
71   void SetTimePeriod(const Dali::TimePeriod& timePeriod);
72
73   /**
74    * @copydoc Dali::Toolkit::TransitionBase::SetAlphaFunction()
75    */
76   void SetAlphaFunction(AlphaFunction alphaFunction)
77   {
78     mAlphaFunction = alphaFunction;
79   }
80
81   /**
82    * @copydoc Dali::Toolkit::TransitionBase::GetAlphaFunction()
83    */
84   AlphaFunction GetAlphaFunction() const
85   {
86     return mAlphaFunction;
87   }
88
89   /**
90    * @copydoc Dali::Toolkit::TransitionBase::TransitionWithChild()
91    */
92   void TransitionWithChild(bool transitionWithChild);
93
94   /**
95    * @brief Request to play this transition.
96    * @param[in] transitionSet transitionSet that this transitionBase is added.
97    */
98   void SetPlay(Dali::Toolkit::TransitionSet transitionSet);
99
100   /**
101    * @brief Run processes those are required done before size/position negotiation.
102    * @param[in] animation animation for the transition
103    */
104   void PreProcess(Dali::Animation animation);
105
106   /**
107    * @brief Make property animation for Transition
108    */
109   void Play();
110
111   /**
112    * Emit the Finished signal
113    */
114   void TransitionFinished();
115
116 protected:
117   /**
118    * @brief Set property map which will be used ad a animation start properties.
119    * @param[in] propertyMap propertyMap that will be used as a start value of transition.
120    */
121   void SetStartPropertyMap(Property::Map propertyMap)
122   {
123     mStartPropertyMap = propertyMap;
124   }
125
126   /**
127    * @brief Set property map which will be used ad a animation finish properties.
128    * @param[in] propertyMap propertyMap that will be used as a finish value of transition.
129    */
130   void SetFinishPropertyMap(Property::Map propertyMap)
131   {
132     mFinishPropertyMap = propertyMap;
133   }
134
135   /**
136    * @brief Retrieve animation.
137    */
138   Dali::Animation GetAnimation()
139   {
140     return mAnimation;
141   }
142
143   /**
144    * @brief Set target view which will be transition.
145    * @param[in] targetView control that will be transition.
146    */
147   void SetTargetView(Dali::Toolkit::Control targetView)
148   {
149     mTargetView = targetView;
150   }
151
152   /**
153    * @brief Gets world transform of input Actor.
154    * @param[in] actor actor for get world transform.
155    */
156   Matrix GetWorldTransform(Dali::Actor actor);
157
158   /**
159    * @brief Gets world color of input Actor.
160    * @param[in] actor actor for get world color.
161    */
162   Vector4 GetWorldColor(Dali::Actor actor);
163
164   bool IsTransitionWithChild()
165   {
166     return mTransitionWithChild;
167   }
168
169 protected:
170   /**
171    * Construct a new TransitionBase.
172    */
173   TransitionBase();
174
175   /**
176    * Second-phase constructor.
177    */
178   void Initialize();
179
180   /**
181    * Destructor
182    */
183   ~TransitionBase() = default;
184
185 private:
186   // Undefined
187   TransitionBase(const TransitionBase&);
188
189   // Undefined
190   TransitionBase& operator=(const TransitionBase& rhs);
191
192 private:
193   /**
194    * @brief Computes and center position by using transform properties.
195    * @param[in] anchorPoint anchorPoint of an actor.
196    * @param[in] positionUsesAnchorPoint positionUsesAnchorPoint of an actor.
197    * @param[in] size size of an actor.
198    * @param[in] scale scale of an actor.
199    * @param[in] orientation orientation of an actor.
200    */
201   Vector3 CalculateCenterPosition(
202     const Vector3&    anchorPoint,
203     const bool        positionUsesAnchorPoint,
204     const Vector3&    size,
205     const Vector3&    scale,
206     const Quaternion& orientation);
207
208   /**
209    * @brief Makes property animation for transition.
210    */
211   void SetAnimation();
212
213   /**
214    * @brief Gets Properties of input control.
215    * @param[in] control control to get properties.
216    */
217   Property::Map GetProperties(Dali::Toolkit::Control control);
218
219   /**
220    * @brief Adds a property on an animation between sourceValue and destimationValue.
221    * @param[in] target target control to be animated.
222    * @param[in] index property index for animation.
223    * @param[in] sourceValue source value of animation.
224    * @param[in] destinationValue destination value of animation.
225    */
226   void AnimateBetween(Dali::Toolkit::Control target, Property::Index index, Property::Value sourceValue, Property::Value destinationValue);
227
228   /**
229    * @brief Copy target view to make clone for the child Actors
230    */
231   void CopyTarget();
232
233   /**
234    * @brief Make animators for Transform.
235    * If the transition requires the information of world transform, let them be in this method.
236    *
237    * @note Do not set any properties in this methods.
238    */
239   virtual void OnPlay()
240   {
241   }
242
243   /**
244    * @brief Make animators for Transform.
245    * If the transition requires the information of world transform, let them be in this method.
246    *
247    * @note Do not set any properties in this methods.
248    */
249   virtual void OnFinished()
250   {
251   }
252
253 private:
254   Dali::Toolkit::Control       mTargetView;           ///< Target View that will be animated.
255   Dali::Actor                  mCopiedActor;          ///< Copied View that will replace mTargetView during transition
256   Dali::Animation              mAnimation;            ///< Property animations for the transition of mTargetView
257   Dali::Toolkit::TransitionSet mTransitionSet;        ///< Handle of TransitionSet
258   AlphaFunction                mAlphaFunction;        ///< Alpha function that will applied for the property animation
259   Property::Map                mStartPropertyMap;     ///< Start properties to be animated. (world transform)
260   Property::Map                mFinishPropertyMap;    ///< Finish properties to be animated. (world transform)
261   Property::Map                mOriginialPropertyMap; ///< Original properties of mTargetView to be used to restore after the transition is finished.
262   float                        mDurationSeconds;      ///< Duration of transition (seconds)
263   float                        mDelaySeconds;         ///< Delay to be started to play transition (seconds)
264   bool                         mTransitionWithChild;  ///< True, if mTargetView transition is inherit to its child Actors.
265                                                       ///< If this is false, the child Actors are moved to the child of mCopiedActor that will have original properties of target Actor during Transition.
266   bool mMoveTargetChildren;                           ///< Flag, if mTransitionWithChild is false and mTargetView has children than True.
267 };
268
269 } // namespace Internal
270
271 // Helpers for public-api forwarding methods
272
273 inline Internal::TransitionBase& GetImplementation(Dali::Toolkit::TransitionBase& animation)
274 {
275   DALI_ASSERT_ALWAYS(animation && "TransitionBase handle is empty");
276
277   BaseObject& handle = animation.GetBaseObject();
278
279   return static_cast<Internal::TransitionBase&>(handle);
280 }
281
282 inline const Internal::TransitionBase& GetImplementation(const Dali::Toolkit::TransitionBase& animation)
283 {
284   DALI_ASSERT_ALWAYS(animation && "TransitionBase handle is empty");
285
286   const BaseObject& handle = animation.GetBaseObject();
287
288   return static_cast<const Internal::TransitionBase&>(handle);
289 }
290
291 } // namespace Toolkit
292
293 } // namespace Dali
294
295 #endif // DALI_INTERNAL_TRANSITION_BASE_H