1 #ifndef DALI_INTERNAL_TRANSITION_BASE_H
2 #define DALI_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::SetDuration()
51 void SetDuration(float seconds);
54 * @copydoc Dali::Toolkit::TransitionBase::GetDuration()
56 float GetDuration() const;
59 * @copydoc Dali::Toolkit::TransitionBase::SetDelay()
61 void SetDelay(float seconds);
64 * @copydoc Dali::Toolkit::TransitionBase::GetDelay()
66 float GetDelay() const;
69 * @copydoc Dali::Toolkit::TransitionBase::SetTimePeriod()
71 void SetTimePeriod(const Dali::TimePeriod& timePeriod);
74 * @copydoc Dali::Toolkit::TransitionBase::SetAlphaFunction()
76 void SetAlphaFunction(AlphaFunction alphaFunction)
78 mAlphaFunction = alphaFunction;
82 * @copydoc Dali::Toolkit::TransitionBase::GetAlphaFunction()
84 AlphaFunction GetAlphaFunction() const
86 return mAlphaFunction;
90 * @copydoc Dali::Toolkit::TransitionBase::TransitionWithChild()
92 void TransitionWithChild(bool transitionWithChild);
95 * @brief Request to play this transition.
96 * @param[in] transitionSet transitionSet that this transitionBase is added.
98 void SetPlay(Dali::Toolkit::TransitionSet transitionSet);
101 * @brief Run processes those are required done before size/position negotiation.
102 * @param[in] animation animation for the transition
104 void PreProcess(Dali::Animation animation);
107 * @brief Make property animation for Transition
112 * Emit the Finished signal
114 void TransitionFinished();
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.
121 void SetStartPropertyMap(Property::Map propertyMap)
123 mStartPropertyMap = propertyMap;
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.
130 void SetFinishPropertyMap(Property::Map propertyMap)
132 mFinishPropertyMap = propertyMap;
136 * @brief Retrieve animation.
138 Dali::Animation GetAnimation()
144 * @brief Set target view which will be transition.
145 * @param[in] targetView control that will be transition.
147 void SetTargetView(Dali::Toolkit::Control targetView)
149 mTargetView = targetView;
153 * @brief Gets world transform of input Actor.
154 * @param[in] actor actor for get world transform.
156 Matrix GetWorldTransform(Dali::Actor actor);
159 * @brief Gets world color of input Actor.
160 * @param[in] actor actor for get world color.
162 Vector4 GetWorldColor(Dali::Actor actor);
164 bool IsTransitionWithChild()
166 return mTransitionWithChild;
171 * Construct a new TransitionBase.
176 * Second-phase constructor.
183 ~TransitionBase() = default;
187 TransitionBase(const TransitionBase&);
190 TransitionBase& operator=(const TransitionBase& rhs);
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.
201 Vector3 CalculateCenterPosition(
202 const Vector3& anchorPoint,
203 const bool positionUsesAnchorPoint,
205 const Vector3& scale,
206 const Quaternion& orientation);
209 * @brief Makes property animation for transition.
214 * @brief Gets Properties of input control.
215 * @param[in] control control to get properties.
217 Property::Map GetProperties(Dali::Toolkit::Control control);
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.
226 void AnimateBetween(Dali::Toolkit::Control target, Property::Index index, Property::Value sourceValue, Property::Value destinationValue);
229 * @brief Copy target view to make clone for the child Actors
234 * @brief Make animators for Transform.
235 * If the transition requires the information of world transform, let them be in this method.
237 * @note Do not set any properties in this methods.
239 virtual void OnPlay()
244 * @brief Make animators for Transform.
245 * If the transition requires the information of world transform, let them be in this method.
247 * @note Do not set any properties in this methods.
249 virtual void OnFinished()
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.
269 } // namespace Internal
271 // Helpers for public-api forwarding methods
273 inline Internal::TransitionBase& GetImplementation(Dali::Toolkit::TransitionBase& animation)
275 DALI_ASSERT_ALWAYS(animation && "TransitionBase handle is empty");
277 BaseObject& handle = animation.GetBaseObject();
279 return static_cast<Internal::TransitionBase&>(handle);
282 inline const Internal::TransitionBase& GetImplementation(const Dali::Toolkit::TransitionBase& animation)
284 DALI_ASSERT_ALWAYS(animation && "TransitionBase handle is empty");
286 const BaseObject& handle = animation.GetBaseObject();
288 return static_cast<const Internal::TransitionBase&>(handle);
291 } // namespace Toolkit
295 #endif // DALI_INTERNAL_TRANSITION_BASE_H