From: David Steele Date: Thu, 22 Sep 2022 15:50:35 +0000 (+0100) Subject: Moved world transform/color calc to Core. X-Git-Tag: dali_2.1.42~5^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=52fe5407846caa7c68e8cdb24f557339c8aecfe0 Moved world transform/color calc to Core. Moved the actor world transform event side calculation and the actor world color event side calculation to Devel API in dali-core. Change-Id: If3fb5bdb44eea493ce9743c7c20c51eb4c587e89 Signed-off-by: David Steele --- diff --git a/dali-toolkit/internal/transition/transition-base-impl.cpp b/dali-toolkit/internal/transition/transition-base-impl.cpp index 5ee926e..5a88901 100644 --- a/dali-toolkit/internal/transition/transition-base-impl.cpp +++ b/dali-toolkit/internal/transition/transition-base-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -70,36 +70,6 @@ Property::Map GetOriginalProperties(Dali::Toolkit::Control control) return propertyMap; } -/** - * @brief Computes and center position by using transform properties. - * @param[in] anchorPoint anchorPoint of an actor. - * @param[in] positionUsesAnchorPoint positionUsesAnchorPoint of an actor. - * @param[in] size size of an actor. - * @param[in] scale scale of an actor. - * @param[in] orientation orientation of an actor. - */ -Vector3 CalculateCenterPosition( - const Vector3& anchorPoint, - const bool positionUsesAnchorPoint, - const Vector3& size, - const Vector3& scale, - const Quaternion& orientation) -{ - Vector3 centerPosition; - const Vector3 half(0.5f, 0.5f, 0.5f); - const Vector3 topLeft(0.0f, 0.0f, 0.5f); - // Calculate the center-point by applying the scale and rotation on the anchor point. - centerPosition = (half - anchorPoint) * size * scale; - centerPosition *= orientation; - - // If the position is ignoring the anchor-point, then remove the anchor-point shift from the position. - if(!positionUsesAnchorPoint) - { - centerPosition -= (topLeft - anchorPoint) * size; - } - return centerPosition; -} - } // anonymous namespace TransitionBasePtr TransitionBase::New() @@ -161,7 +131,7 @@ void TransitionBase::TransitionWithChild(bool transitionWithChild) void TransitionBase::PreProcess(Dali::Animation animation) { - mAnimation = animation; + mAnimation = animation; // Retrieve original property map of mTarget to backup and to reset after transition is finished. mOriginalPropertyMap = GetOriginalProperties(mTarget); mMoveTargetChildren = false; @@ -183,11 +153,11 @@ void TransitionBase::Play() // Set world transform and color to the target control to make it independent of the parent control and its transition. // The properties will be returned at the TransitionFinished() method. - Matrix targetWorldTransform = GetWorldTransform(mTarget); + Matrix targetWorldTransform = DevelActor::GetWorldTransform(mTarget); Vector3 targetPosition, targetScale; Quaternion targetOrientation; targetWorldTransform.GetTransformComponents(targetPosition, targetOrientation, targetScale); - Vector4 targetColor = GetWorldColor(mTarget); + Vector4 targetColor = DevelActor::GetWorldColor(mTarget); mTarget.SetProperties(PROPERTY_MAP_INDEPENDENT_CONTROL); mTarget[Dali::Actor::Property::POSITION] = targetPosition; @@ -282,141 +252,6 @@ void TransitionBase::TransitionFinished() mAnimation.Reset(); } -Matrix TransitionBase::GetWorldTransform(Dali::Actor actor) -{ - enum InheritanceMode - { - DONT_INHERIT_TRANSFORM = 0, - INHERIT_POSITION = 1, - INHERIT_SCALE = 2, - INHERIT_ORIENTATION = 4, - INHERIT_ALL = INHERIT_POSITION | INHERIT_SCALE | INHERIT_ORIENTATION, - }; - - std::vector descentList; - std::vector inheritanceModeList; - Dali::Actor currentActor = actor; - int inheritance = 0; - do - { - inheritance = (static_cast(currentActor.GetProperty(Dali::Actor::Property::INHERIT_ORIENTATION)) << 2) + - (static_cast(currentActor.GetProperty(Dali::Actor::Property::INHERIT_SCALE)) << 1) + - static_cast(currentActor.GetProperty(Dali::Actor::Property::INHERIT_POSITION)); - inheritanceModeList.push_back(static_cast(inheritance)); - descentList.push_back(currentActor); - currentActor = currentActor.GetParent(); - } while(inheritance != DONT_INHERIT_TRANSFORM && currentActor); - - Matrix worldMatrix; - Vector3 localPosition; - for(unsigned int i(descentList.size() - 1); i < descentList.size(); --i) - { - Vector3 anchorPoint = descentList[i].GetProperty(Dali::Actor::Property::ANCHOR_POINT); - Vector3 parentOrigin = descentList[i].GetProperty(Dali::Actor::Property::PARENT_ORIGIN); - bool positionUsesAnchorPoint = descentList[i].GetProperty(Dali::Actor::Property::POSITION_USES_ANCHOR_POINT); - Vector3 size = descentList[i].GetProperty(Dali::Actor::Property::SIZE); - Vector3 actorPosition = descentList[i].GetProperty(Dali::Actor::Property::POSITION); - Quaternion localOrientation = descentList[i].GetProperty(Dali::Actor::Property::ORIENTATION); - Vector3 localScale = descentList[i].GetProperty(Dali::Actor::Property::SCALE); - - Vector3 centerPosition = CalculateCenterPosition(anchorPoint, positionUsesAnchorPoint, size, localScale, localOrientation); - if(inheritanceModeList[i] != DONT_INHERIT_TRANSFORM && descentList[i].GetParent()) - { - Matrix localMatrix; - Vector3 parentSize = descentList[i + 1].GetProperty(Dali::Actor::Property::SIZE); - if(inheritanceModeList[i] == INHERIT_ALL) - { - localPosition = actorPosition + centerPosition + (parentOrigin - Vector3(0.5f, 0.5f, 0.5f)) * parentSize; - localMatrix.SetTransformComponents(localScale, localOrientation, localPosition); - - //Update the world matrix - Matrix tempMatrix; - Matrix::Multiply(tempMatrix, localMatrix, worldMatrix); - worldMatrix = tempMatrix; - } - else - { - Vector3 parentPosition, parentScale; - Quaternion parentOrientation; - worldMatrix.GetTransformComponents(parentPosition, parentOrientation, parentScale); - - if((inheritanceModeList[i] & INHERIT_SCALE) == 0) - { - //Don't inherit scale - localScale /= parentScale; - } - - if((inheritanceModeList[i] & INHERIT_ORIENTATION) == 0) - { - //Don't inherit orientation - parentOrientation.Invert(); - localOrientation = parentOrientation * localOrientation; - } - - if((inheritanceModeList[i] & INHERIT_POSITION) == 0) - { - localMatrix.SetTransformComponents(localScale, localOrientation, Vector3::ZERO); - Matrix tempMatrix; - Matrix::Multiply(tempMatrix, localMatrix, worldMatrix); - worldMatrix = tempMatrix; - worldMatrix.SetTranslation(actorPosition + centerPosition); - } - else - { - localPosition = actorPosition + centerPosition + (parentOrigin - Vector3(0.5f, 0.5f, 0.5f)) * parentSize; - localMatrix.SetTransformComponents(localScale, localOrientation, localPosition); - Matrix tempMatrix; - Matrix::Multiply(tempMatrix, localMatrix, worldMatrix); - worldMatrix = tempMatrix; - } - } - } - else - { - localPosition = actorPosition + centerPosition; - worldMatrix.SetTransformComponents(localScale, localOrientation, localPosition); - } - } - - return worldMatrix; -} - -Vector4 TransitionBase::GetWorldColor(Dali::Actor actor) -{ - std::vector descentList; - std::vector inheritanceModeList; - Dali::Actor currentActor = actor; - Dali::ColorMode inheritance = Dali::ColorMode::USE_OWN_MULTIPLY_PARENT_ALPHA; - do - { - inheritance = currentActor.GetProperty(Dali::Actor::Property::COLOR_MODE); - inheritanceModeList.push_back(inheritance); - descentList.push_back(currentActor); - currentActor = currentActor.GetParent(); - } while(inheritance != Dali::ColorMode::USE_OWN_COLOR && currentActor); - - Vector4 worldColor; - for(unsigned int i(descentList.size() - 1); i < descentList.size(); --i) - { - if(inheritanceModeList[i] == USE_OWN_COLOR || i == descentList.size() - 1) - { - worldColor = descentList[i].GetProperty(Dali::Actor::Property::COLOR); - } - else if(inheritanceModeList[i] == USE_OWN_MULTIPLY_PARENT_ALPHA) - { - Vector4 ownColor = descentList[i].GetProperty(Dali::Actor::Property::COLOR); - worldColor = Vector4(ownColor.r, ownColor.g, ownColor.b, ownColor.a * worldColor.a); - } - else if(inheritanceModeList[i] == USE_OWN_MULTIPLY_PARENT_COLOR) - { - Vector4 ownColor = descentList[i].GetProperty(Dali::Actor::Property::COLOR); - worldColor *= ownColor; - } - } - - return worldColor; -} - } // namespace Internal } // namespace Toolkit diff --git a/dali-toolkit/internal/transition/transition-base-impl.h b/dali-toolkit/internal/transition/transition-base-impl.h index b194e52..73e30dd 100644 --- a/dali-toolkit/internal/transition/transition-base-impl.h +++ b/dali-toolkit/internal/transition/transition-base-impl.h @@ -2,7 +2,7 @@ #define DALI_TOOLKIT_INTERNAL_TRANSITION_BASE_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -126,7 +126,6 @@ public: } protected: - /** * @brief Set property map which will be used as a animation start properties. * @param[in] propertyMap propertyMap that will be used as a start value of transition. @@ -163,18 +162,6 @@ protected: } /** - * @brief Gets world transform of input Actor. - * @param[in] actor actor for get world transform. - */ - Matrix GetWorldTransform(Dali::Actor actor); - - /** - * @brief Gets world color of input Actor. - * @param[in] actor actor for get world color. - */ - Vector4 GetWorldColor(Dali::Actor actor); - - /** * @brief Returns whether this transition will be applied to children of target or not. */ bool IsTransitionWithChild() const @@ -256,19 +243,19 @@ private: } private: - Dali::Toolkit::Control mTarget; ///< Target that will be animated. - Dali::Actor mCopiedActor; ///< Copied View that will replace mTarget during transition - Dali::Animation mAnimation; ///< Property animations for the transition of mTarget - AlphaFunction mAlphaFunction; ///< Alpha function that will applied for the property animation - Property::Map mStartPropertyMap; ///< Start properties to be animated. (world transform) - Property::Map mFinishPropertyMap; ///< Finish properties to be animated. (world transform) - Property::Map mOriginalPropertyMap; ///< Original properties of mTarget to be used to restore after the transition is finished. - Dali::TimePeriod mTimePeriod; ///< TimePeriod of transition - bool mTransitionWithChild; ///< True, if mTarget transition is inherit to its child Actors. - ///< If this is false, the child Actors are moved to the child of mCopiedActor that will have original properties of target Actor during Transition. - bool mMoveTargetChildren; ///< Flag, if mTransitionWithChild is false and mTarget has children than True. - bool mIsAppearingTransition; ///< True, if this transition is appearing transition. - bool mIsPairTransition; ///< True, if this transition is started from a Control to another Control. + Dali::Toolkit::Control mTarget; ///< Target that will be animated. + Dali::Actor mCopiedActor; ///< Copied View that will replace mTarget during transition + Dali::Animation mAnimation; ///< Property animations for the transition of mTarget + AlphaFunction mAlphaFunction; ///< Alpha function that will applied for the property animation + Property::Map mStartPropertyMap; ///< Start properties to be animated. (world transform) + Property::Map mFinishPropertyMap; ///< Finish properties to be animated. (world transform) + Property::Map mOriginalPropertyMap; ///< Original properties of mTarget to be used to restore after the transition is finished. + Dali::TimePeriod mTimePeriod; ///< TimePeriod of transition + bool mTransitionWithChild; ///< True, if mTarget transition is inherit to its child Actors. + ///< If this is false, the child Actors are moved to the child of mCopiedActor that will have original properties of target Actor during Transition. + bool mMoveTargetChildren; ///< Flag, if mTransitionWithChild is false and mTarget has children than True. + bool mIsAppearingTransition; ///< True, if this transition is appearing transition. + bool mIsPairTransition; ///< True, if this transition is started from a Control to another Control. }; } // namespace Internal diff --git a/dali-toolkit/internal/transition/transition-impl.cpp b/dali-toolkit/internal/transition/transition-impl.cpp index 78ba8db..3f78a6f 100644 --- a/dali-toolkit/internal/transition/transition-impl.cpp +++ b/dali-toolkit/internal/transition/transition-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -82,7 +82,7 @@ Transition::~Transition() void Transition::OnPlay() { - Dali::Toolkit::Control sourceControl = mSourceControl.GetHandle(); + Dali::Toolkit::Control sourceControl = mSourceControl.GetHandle(); Dali::Toolkit::Control destinationControl = mDestinationControl.GetHandle(); if(!sourceControl || !sourceControl[Dali::Actor::Property::CONNECTED_TO_SCENE] || !destinationControl || !destinationControl[Dali::Actor::Property::CONNECTED_TO_SCENE]) @@ -92,12 +92,12 @@ void Transition::OnPlay() } //Make startPropertyMap and finishPropertyMap to use for property animation. - Matrix sourceWorldTransform = GetWorldTransform(sourceControl); + Matrix sourceWorldTransform = DevelActor::GetWorldTransform(sourceControl); Vector3 sourcePosition, sourceScale; Quaternion sourceOrientation; sourceWorldTransform.GetTransformComponents(sourcePosition, sourceOrientation, sourceScale); - Matrix destinationWorldTransform = GetWorldTransform(destinationControl); + Matrix destinationWorldTransform = DevelActor::GetWorldTransform(destinationControl); Vector3 destinationPosition, destinationScale; Quaternion destinationOrientation; destinationWorldTransform.GetTransformComponents(destinationPosition, destinationOrientation, destinationScale); @@ -115,8 +115,8 @@ void Transition::OnPlay() startPropertyMap.Insert(Dali::Actor::Property::SCALE, sourceScale); finishPropertyMap.Insert(Dali::Actor::Property::SCALE, destinationScale); - Vector4 sourceColor = GetWorldColor(sourceControl); - Vector4 destinationColor = GetWorldColor(destinationControl); + Vector4 sourceColor = DevelActor::GetWorldColor(sourceControl); + Vector4 destinationColor = DevelActor::GetWorldColor(destinationControl); startPropertyMap.Insert(Dali::Actor::Property::COLOR, sourceColor); finishPropertyMap.Insert(Dali::Actor::Property::COLOR, destinationColor);