Merge "Add TOUCH_FOCUSABLE property" into devel/master
[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 protected:
96   /**
97    * @brief Set property map which will be used as a initial properties.
98    * @param[in] propertyMap propertyMap that will be used as a start value of transition.
99    */
100   void SetInitialPropertyMap(const Property::Map& propertyMap)
101   {
102     mInitialPropertyMap = propertyMap;
103   }
104   /**
105    * @brief Set property map which will be used as a animation start properties.
106    * @param[in] propertyMap propertyMap that will be used as a start value of transition.
107    */
108   void SetStartPropertyMap(const Property::Map& propertyMap)
109   {
110     mStartPropertyMap = propertyMap;
111   }
112
113   /**
114    * @brief Set property map which will be used as a animation finish properties.
115    * @param[in] propertyMap propertyMap that will be used as a finish value of transition.
116    */
117   void SetFinishPropertyMap(const Property::Map& propertyMap)
118   {
119     mFinishPropertyMap = propertyMap;
120   }
121
122   /**
123    * @brief Retrieve animation.
124    */
125   Dali::Animation GetAnimation()
126   {
127     return mAnimation;
128   }
129
130   /**
131    * @brief Set target which will be transition.
132    * @param[in] target control that will be transition.
133    */
134   void SetTarget(Dali::Toolkit::Control target)
135   {
136     mTarget = target;
137   }
138
139   /**
140    * @brief Gets world transform of input Actor.
141    * @param[in] actor actor for get world transform.
142    */
143   Matrix GetWorldTransform(Dali::Actor actor);
144
145   /**
146    * @brief Gets world color of input Actor.
147    * @param[in] actor actor for get world color.
148    */
149   Vector4 GetWorldColor(Dali::Actor actor);
150
151   /**
152    * @brief Returns whether this transition will be applied to children of target or not.
153    */
154   bool IsTransitionWithChild()
155   {
156     return mTransitionWithChild;
157   }
158
159 protected:
160   /**
161    * Construct a new TransitionBase.
162    */
163   TransitionBase();
164
165   /**
166    * Second-phase constructor.
167    */
168   void Initialize();
169
170   /**
171    * Destructor
172    */
173   ~TransitionBase() = default;
174
175 private:
176   // Undefined
177   TransitionBase(const TransitionBase&);
178
179   // Undefined
180   TransitionBase& operator=(const TransitionBase& rhs);
181
182 private:
183   /**
184    * @brief Makes property animation for transition.
185    */
186   void SetAnimation();
187
188   /**
189    * @brief Adds a property on an animation between sourceValue and destimationValue.
190    * @param[in] target target control to be animated.
191    * @param[in] index property index for animation.
192    * @param[in] initialValue initial value of animation.
193    * @param[in] sourceValue source value of animation.
194    * @param[in] destinationValue destination value of animation.
195    */
196   void AnimateBetween(Dali::Toolkit::Control target, Property::Index index, Property::Value initialValue, Property::Value sourceValue, Property::Value destinationValue);
197
198   /**
199    * @brief Copy target to make clone for the child Actors
200    */
201   void CopyTarget();
202
203   /**
204    * @brief Make pair of Property::Map to be used for transition animation.
205    * Set the pair of Property::Map by using SetStartPropertyMap() and SetFinishPropertyMap(),
206    * then the properties of mTarget will be animated between them during transition duration.
207    * If the transition requires the information of world transform, let them be in this method.
208    * World transform and World color can be retrieved by using GetWorldTransform() and GetWorldColor() methods.
209    * And If it is needed to add additional custom animation than use GetAnimation() and add them.
210    *
211    * @note Do not set any properties in this methods.
212    */
213   virtual void OnPlay()
214   {
215   }
216
217   /**
218    * @brief If the transition is needed to do something after the transition is finished, let them be in this method.
219    */
220   virtual void OnFinished()
221   {
222   }
223
224 private:
225   Dali::Toolkit::Control       mTarget;              ///< Target that will be animated.
226   Dali::Actor                  mCopiedActor;         ///< Copied View that will replace mTarget during transition
227   Dali::Animation              mAnimation;           ///< Property animations for the transition of mTarget
228   AlphaFunction                mAlphaFunction;       ///< Alpha function that will applied for the property animation
229   Property::Map                mInitialPropertyMap;  ///< Initial properties to be animated. (world transform)
230   Property::Map                mStartPropertyMap;    ///< Start properties to be animated. (world transform)
231   Property::Map                mFinishPropertyMap;   ///< Finish properties to be animated. (world transform)
232   Property::Map                mOriginalPropertyMap; ///< Original properties of mTarget to be used to restore after the transition is finished.
233   Dali::TimePeriod             mTimePeriod;          ///< TimePeriod of transition
234   bool                         mTransitionWithChild; ///< True, if mTarget transition is inherit to its child Actors.
235                                                      ///< If this is false, the child Actors are moved to the child of mCopiedActor that will have original properties of target Actor during Transition.
236   bool mMoveTargetChildren;                          ///< Flag, if mTransitionWithChild is false and mTarget has children than True.
237 };
238
239 } // namespace Internal
240
241 // Helpers for public-api forwarding methods
242
243 inline Internal::TransitionBase& GetImplementation(Dali::Toolkit::TransitionBase& animation)
244 {
245   DALI_ASSERT_ALWAYS(animation && "TransitionBase handle is empty");
246
247   BaseObject& handle = animation.GetBaseObject();
248
249   return static_cast<Internal::TransitionBase&>(handle);
250 }
251
252 inline const Internal::TransitionBase& GetImplementation(const Dali::Toolkit::TransitionBase& animation)
253 {
254   DALI_ASSERT_ALWAYS(animation && "TransitionBase handle is empty");
255
256   const BaseObject& handle = animation.GetBaseObject();
257
258   return static_cast<const Internal::TransitionBase&>(handle);
259 }
260
261 } // namespace Toolkit
262
263 } // namespace Dali
264
265 #endif // DALI_TOOLKIT_INTERNAL_TRANSITION_BASE_H