1 #ifndef DALI_TOOLKIT_INTERNAL_TRANSITION_BASE_H
2 #define DALI_TOOLKIT_INTERNAL_TRANSITION_BASE_H
5 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
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>
37 using TransitionBasePtr = IntrusivePtr<TransitionBase>;
39 class TransitionBase : public BaseObject
43 * @brief Create a new TransitionBase object.
44 * @return A smart-pointer to the newly allocated TransitionBase.
46 static TransitionBasePtr New();
49 * @copydoc Dali::Toolkit::TransitionBase::SetTimePeriod()
51 void SetTimePeriod(const Dali::TimePeriod& timePeriod);
54 * @copydoc Dali::Toolkit::TransitionBase::GetTimePeriod()
56 Dali::TimePeriod GetTimePeriod() const;
59 * @copydoc Dali::Toolkit::TransitionBase::SetAlphaFunction()
61 void SetAlphaFunction(AlphaFunction alphaFunction)
63 mAlphaFunction = alphaFunction;
67 * @copydoc Dali::Toolkit::TransitionBase::GetAlphaFunction()
69 AlphaFunction GetAlphaFunction() const
71 return mAlphaFunction;
75 * @copydoc Dali::Toolkit::TransitionBase::TransitionWithChild()
77 void TransitionWithChild(bool transitionWithChild);
80 * @brief Run processes those are required done before size/position negotiation.
81 * @param[in] animation animation for the transition
83 void PreProcess(Dali::Animation animation);
86 * @brief Make property animation for Transition
91 * Emit the Finished signal
93 void TransitionFinished();
96 * @brief Set this transition is appearing transition or not.
97 * @param[in] appearingTransition True if this transition is appearing transition.
99 void SetAppearingTransition(bool appearingTransition)
101 mIsAppearingTransition = appearingTransition;
105 * @brief Returns whether this transition is appearing transition or not
107 bool IsAppearingTransition() const
109 return mIsAppearingTransition;
113 * @brief Returns whether this transition is a transition from a Control to another Control or effect to appearing or disappearing.
115 bool IsPairTransition() const
117 return mIsPairTransition;
121 * @brief Returns target which will be transition.
123 const Dali::Toolkit::Control GetTarget() const
131 * @brief Set property map which will be used as a animation start properties.
132 * @param[in] propertyMap propertyMap that will be used as a start value of transition.
134 void SetStartPropertyMap(const Property::Map& propertyMap)
136 mStartPropertyMap = propertyMap;
140 * @brief Set property map which will be used as a animation finish properties.
141 * @param[in] propertyMap propertyMap that will be used as a finish value of transition.
143 void SetFinishPropertyMap(const Property::Map& propertyMap)
145 mFinishPropertyMap = propertyMap;
149 * @brief Retrieve animation.
151 Dali::Animation GetAnimation()
157 * @brief Set target which will be transition.
158 * @param[in] target control that will be transition.
160 void SetTarget(Dali::Toolkit::Control target)
166 * @brief Gets world transform of input Actor.
167 * @param[in] actor actor for get world transform.
169 Matrix GetWorldTransform(Dali::Actor actor);
172 * @brief Gets world color of input Actor.
173 * @param[in] actor actor for get world color.
175 Vector4 GetWorldColor(Dali::Actor actor);
178 * @brief Returns whether this transition will be applied to children of target or not.
180 bool IsTransitionWithChild() const
182 return mTransitionWithChild;
186 * @brief Set whether this transition is a transition from a Control to another Control or effect to appearing or disappearing.
187 * @param[in] pairTransition True if this transition is appearing transition.
189 void SetPairTransition(bool pairTransition)
191 mIsPairTransition = pairTransition;
196 * Construct a new TransitionBase.
201 * Second-phase constructor.
208 ~TransitionBase() = default;
212 TransitionBase(const TransitionBase&);
215 TransitionBase& operator=(const TransitionBase& rhs);
219 * @brief Makes property animation for transition.
224 * @brief Adds a property on an animation between sourceValue and destimationValue.
225 * @param[in] target target control to be animated.
226 * @param[in] index property index for animation.
227 * @param[in] sourceValue source value of animation.
228 * @param[in] destinationValue destination value of animation.
230 void AnimateBetween(Dali::Toolkit::Control target, Property::Index index, Property::Value sourceValue, Property::Value destinationValue);
233 * @brief Copy target to make clone for the child Actors
238 * @brief Make pair of Property::Map to be used for transition animation.
239 * Set the pair of Property::Map by using SetStartPropertyMap() and SetFinishPropertyMap(),
240 * then the properties of mTarget will be animated between them during transition duration.
241 * If the transition requires the information of world transform, let them be in this method.
242 * World transform and World color can be retrieved by using GetWorldTransform() and GetWorldColor() methods.
243 * And If it is needed to add additional custom animation than use GetAnimation() and add them.
245 * @note Do not set any properties in this methods.
247 virtual void OnPlay()
252 * @brief If the transition is needed to do something after the transition is finished, let them be in this method.
254 virtual void OnFinished()
259 Dali::Toolkit::Control mTarget; ///< Target that will be animated.
260 Dali::Actor mCopiedActor; ///< Copied View that will replace mTarget during transition
261 Dali::Animation mAnimation; ///< Property animations for the transition of mTarget
262 AlphaFunction mAlphaFunction; ///< Alpha function that will applied for the property animation
263 Property::Map mStartPropertyMap; ///< Start properties to be animated. (world transform)
264 Property::Map mFinishPropertyMap; ///< Finish properties to be animated. (world transform)
265 Property::Map mOriginalPropertyMap; ///< Original properties of mTarget to be used to restore after the transition is finished.
266 Dali::TimePeriod mTimePeriod; ///< TimePeriod of transition
267 bool mTransitionWithChild; ///< True, if mTarget transition is inherit to its child Actors.
268 ///< If this is false, the child Actors are moved to the child of mCopiedActor that will have original properties of target Actor during Transition.
269 bool mMoveTargetChildren; ///< Flag, if mTransitionWithChild is false and mTarget has children than True.
270 bool mIsAppearingTransition; ///< True, if this transition is appearing transition.
271 bool mIsPairTransition; ///< True, if this transition is started from a Control to another Control.
274 } // namespace Internal
276 // Helpers for public-api forwarding methods
278 inline Internal::TransitionBase& GetImplementation(Dali::Toolkit::TransitionBase& animation)
280 DALI_ASSERT_ALWAYS(animation && "TransitionBase handle is empty");
282 BaseObject& handle = animation.GetBaseObject();
284 return static_cast<Internal::TransitionBase&>(handle);
287 inline const Internal::TransitionBase& GetImplementation(const Dali::Toolkit::TransitionBase& animation)
289 DALI_ASSERT_ALWAYS(animation && "TransitionBase handle is empty");
291 const BaseObject& handle = animation.GetBaseObject();
293 return static_cast<const Internal::TransitionBase&>(handle);
296 } // namespace Toolkit
300 #endif // DALI_TOOLKIT_INTERNAL_TRANSITION_BASE_H