From: seungho Date: Wed, 2 Jun 2021 09:38:35 +0000 (+0900) Subject: Add Fade Transition X-Git-Tag: dali_2.0.32~9^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=82f0fa0fcdede94b7114bef9b15277ba5e41ad4a Add Fade Transition Change-Id: Ic906ebf56b3cd21e3cf1877da54039f3e0550049 Signed-off-by: seungho --- diff --git a/automated-tests/src/dali-toolkit/CMakeLists.txt b/automated-tests/src/dali-toolkit/CMakeLists.txt index 2b73142..9b2691c 100755 --- a/automated-tests/src/dali-toolkit/CMakeLists.txt +++ b/automated-tests/src/dali-toolkit/CMakeLists.txt @@ -19,6 +19,7 @@ SET(TC_SOURCES utc-Dali-ConfirmationPopup.cpp utc-Dali-CubeTransitionEffect.cpp utc-Dali-EffectsView.cpp + utc-Dali-Fade.cpp utc-Dali-FlexContainer.cpp utc-Dali-FlexNode.cpp utc-Dali-GaussianBlurView.cpp diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Fade.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Fade.cpp new file mode 100755 index 0000000..8fc8fba --- /dev/null +++ b/automated-tests/src/dali-toolkit/utc-Dali-Fade.cpp @@ -0,0 +1,264 @@ +/* + * Copyright (c) 2021 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace Dali; +using namespace Dali::Toolkit; + +// Functor to test whether a Finish signal is emitted +struct TransitionFinishCheck +{ + TransitionFinishCheck(bool& signalReceived) + : mSignalReceived(signalReceived) + { + } + + void operator()(TransitionSet& transitionSet) + { + mSignalReceived = true; + } + + void Reset() + { + mSignalReceived = false; + } + + void CheckSignalReceived() + { + if(!mSignalReceived) + { + tet_printf("Expected Finish signal was not received\n"); + tet_result(TET_FAIL); + } + else + { + tet_result(TET_PASS); + } + } + + void CheckSignalNotReceived() + { + if(mSignalReceived) + { + tet_printf("Unexpected Finish signal was received\n"); + tet_result(TET_FAIL); + } + else + { + tet_result(TET_PASS); + } + } + + bool& mSignalReceived; // owned by individual tests +}; + +int UtcDaliFadeSetGetProperty(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliFadeSetGetProperty"); + + Control control = Control::New(); + + Fade fade = Fade::New(control, 0.5, TimePeriod(-0.5f, -0.5f)); + + TimePeriod timePeriod = fade.GetTimePeriod(); + DALI_TEST_EQUALS(0.0f, timePeriod.delaySeconds, TEST_LOCATION); + DALI_TEST_EQUALS(0.0f, timePeriod.durationSeconds, TEST_LOCATION); + + END_TEST; +} + +int UtcDaliFadeWithOffScene(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliFadeWithOffScene"); + + Control control = Control::New(); + control.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + control.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + control.SetProperty(Actor::Property::POSITION, Vector3(100, 200, 0)); + control.SetProperty(Actor::Property::SIZE, Vector3(150, 150, 0)); + control.SetProperty(Actor::Property::OPACITY, 1.0f); + Property::Map controlProperty; + controlProperty.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR); + controlProperty.Insert(Toolkit::ColorVisual::Property::MIX_COLOR, Vector4(1.0f, 0.0f, 0.0f, 1.0f)); + control.SetProperty(Toolkit::Control::Property::BACKGROUND, controlProperty); + + application.SendNotification(); + application.Render(20); + + DALI_TEST_EQUALS(1.0f, control.GetCurrentProperty(Actor::Property::OPACITY), TEST_LOCATION); + + Fade fade = Fade::New(control, 0.5, TimePeriod(0.5f)); + fade.SetAppearingTransition(false); // set fade out + TransitionSet transitionSet = TransitionSet::New(); + transitionSet.AddTransition(fade); + transitionSet.Play(); + + bool signalReceived(false); + TransitionFinishCheck finishCheck(signalReceived); + transitionSet.FinishedSignal().Connect(&application, finishCheck); + + application.SendNotification(); + application.Render(400); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + + DALI_TEST_EQUALS(1.0f, control.GetCurrentProperty(Actor::Property::OPACITY), TEST_LOCATION); + + application.SendNotification(); + application.Render(200); + + // We did expect the animation to finish + application.SendNotification(); + finishCheck.CheckSignalReceived(); + + application.SendNotification(); + application.Render(20); + + DALI_TEST_EQUALS(1.0f, control.GetCurrentProperty(Actor::Property::OPACITY), TEST_LOCATION); + + END_TEST; +} + +int UtcDaliFadeOut(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliFadeOut"); + + Control control = Control::New(); + control.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + control.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + control.SetProperty(Actor::Property::POSITION, Vector3(100, 200, 0)); + control.SetProperty(Actor::Property::SIZE, Vector3(150, 150, 0)); + control.SetProperty(Actor::Property::OPACITY, 1.0f); + Property::Map controlProperty; + controlProperty.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR); + controlProperty.Insert(Toolkit::ColorVisual::Property::MIX_COLOR, Vector4(1.0f, 0.0f, 0.0f, 1.0f)); + control.SetProperty(Toolkit::Control::Property::BACKGROUND, controlProperty); + + application.GetScene().Add(control); + + application.SendNotification(); + application.Render(20); + + DALI_TEST_EQUALS(1.0f, control.GetCurrentProperty(Actor::Property::OPACITY), TEST_LOCATION); + + Fade fade = Fade::New(control, 0.5, TimePeriod(0.5f)); + fade.SetAppearingTransition(false); // set fade out + TransitionSet transitionSet = TransitionSet::New(); + transitionSet.AddTransition(fade); + transitionSet.Play(); + + bool signalReceived(false); + TransitionFinishCheck finishCheck(signalReceived); + transitionSet.FinishedSignal().Connect(&application, finishCheck); + + application.SendNotification(); + application.Render(400); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + + float currentOpacity = control.GetCurrentProperty(Actor::Property::OPACITY); + DALI_TEST_CHECK(currentOpacity <= 0.7 && currentOpacity >= 0.5); + + application.SendNotification(); + application.Render(200); + + // We did expect the animation to finish + application.SendNotification(); + finishCheck.CheckSignalReceived(); + + application.SendNotification(); + application.Render(20); + + // Property is reset after animation. + DALI_TEST_EQUALS(1.0f, control.GetCurrentProperty(Actor::Property::OPACITY), TEST_LOCATION); + + END_TEST; +} + +int UtcDaliFadeIn(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliFadeIn"); + + Control control = Control::New(); + control.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + control.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + control.SetProperty(Actor::Property::POSITION, Vector3(100, 200, 0)); + control.SetProperty(Actor::Property::SIZE, Vector3(150, 150, 0)); + control.SetProperty(Actor::Property::OPACITY, 1.0f); + Property::Map controlProperty; + controlProperty.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR); + controlProperty.Insert(Toolkit::ColorVisual::Property::MIX_COLOR, Vector4(1.0f, 0.0f, 0.0f, 1.0f)); + control.SetProperty(Toolkit::Control::Property::BACKGROUND, controlProperty); + + application.GetScene().Add(control); + + application.SendNotification(); + application.Render(20); + + DALI_TEST_EQUALS(1.0f, control.GetCurrentProperty(Actor::Property::OPACITY), TEST_LOCATION); + + Fade fade = Fade::New(control, 0.5, TimePeriod(0.5f)); + fade.SetAppearingTransition(true); // set fade in + TransitionSet transitionSet = TransitionSet::New(); + transitionSet.AddTransition(fade); + transitionSet.Play(); + + bool signalReceived(false); + TransitionFinishCheck finishCheck(signalReceived); + transitionSet.FinishedSignal().Connect(&application, finishCheck); + + application.SendNotification(); + application.Render(400); + + // We didn't expect the animation to finish yet + application.SendNotification(); + finishCheck.CheckSignalNotReceived(); + + float currentOpacity = control.GetCurrentProperty(Actor::Property::OPACITY); + DALI_TEST_CHECK(currentOpacity <= 1.0 && currentOpacity >= 0.8); + + application.SendNotification(); + application.Render(200); + + // We did expect the animation to finish + application.SendNotification(); + finishCheck.CheckSignalReceived(); + + application.SendNotification(); + application.Render(20); + + DALI_TEST_EQUALS(1.0f, control.GetCurrentProperty(Actor::Property::OPACITY), TEST_LOCATION); + + END_TEST; +} diff --git a/dali-toolkit/internal/file.list b/dali-toolkit/internal/file.list index aabd0c0..30435f8 100644 --- a/dali-toolkit/internal/file.list +++ b/dali-toolkit/internal/file.list @@ -178,6 +178,7 @@ SET( toolkit_src_files ${toolkit_src_dir}/text/rendering/text-backend-impl.cpp ${toolkit_src_dir}/text/rendering/text-typesetter.cpp ${toolkit_src_dir}/text/rendering/view-model.cpp + ${toolkit_src_dir}/transition/fade-impl.cpp ${toolkit_src_dir}/transition/transition-base-impl.cpp ${toolkit_src_dir}/transition/transition-impl.cpp ${toolkit_src_dir}/transition/transition-lifecycle-controller.cpp diff --git a/dali-toolkit/internal/transition/fade-impl.cpp b/dali-toolkit/internal/transition/fade-impl.cpp new file mode 100644 index 0000000..30edc3e --- /dev/null +++ b/dali-toolkit/internal/transition/fade-impl.cpp @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2021 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// CLASS HEADER +#include + +// EXTERNAL INCLUDES +#include +#include +#include +#include +#include + +namespace Dali +{ +namespace Toolkit +{ +namespace Internal +{ +namespace +{ +const Dali::AlphaFunction DEFAULT_ALPHA_FUNCTION(Dali::AlphaFunction::DEFAULT); + +} // anonymous namespace + +FadePtr Fade::New(Dali::Toolkit::Control control, float opacity, TimePeriod timePeriod) +{ + float delaySeconds = timePeriod.delaySeconds; + if(delaySeconds < 0.0f) + { + DALI_LOG_WARNING("delay should be greater than 0.0f.\n"); + delaySeconds = 0.0f; + } + + float durationSeconds = timePeriod.durationSeconds; + if(durationSeconds < 0.0f) + { + DALI_LOG_WARNING("duration should be greater than 0.0f.\n"); + durationSeconds = 0.0f; + } + + FadePtr fade = new Fade(control, Dali::Clamp(opacity, 0.0f, 1.0f), TimePeriod(delaySeconds, durationSeconds)); + + // Second-phase construction + fade->Initialize(); + + return fade; +} + +Fade::Fade(Dali::Toolkit::Control control, float opacity, TimePeriod timePeriod) +: TransitionBase(), + mTargetControl(control), + mOpacity(opacity) +{ + SetTarget(control); + SetTimePeriod(timePeriod); +} + +Fade::~Fade() +{ +} + +void Fade::OnPlay() +{ + Dali::Toolkit::Control targetControl = mTargetControl.GetHandle(); + if(!targetControl || !targetControl[Dali::Actor::Property::CONNECTED_TO_SCENE]) + { + DALI_LOG_ERROR("The Control is not added on the window\n"); + return; + } + + Property::Map initialPropertyMap; + Property::Map startPropertyMap; + Property::Map finishPropertyMap; + + if(IsAppearingTransition()) + { + initialPropertyMap.Insert(Dali::Actor::Property::OPACITY, 0.0f); + startPropertyMap.Insert(Dali::Actor::Property::OPACITY, mOpacity); + finishPropertyMap.Insert(Dali::Actor::Property::OPACITY, targetControl[Dali::Actor::Property::OPACITY]); + } + else + { + initialPropertyMap.Insert(Dali::Actor::Property::OPACITY, targetControl[Dali::Actor::Property::OPACITY]); + startPropertyMap.Insert(Dali::Actor::Property::OPACITY, targetControl[Dali::Actor::Property::OPACITY]); + finishPropertyMap.Insert(Dali::Actor::Property::OPACITY, mOpacity); + } + + SetInitialPropertyMap(initialPropertyMap); + SetStartPropertyMap(startPropertyMap); + SetFinishPropertyMap(finishPropertyMap); +} + +} // namespace Internal + +} // namespace Toolkit + +} // namespace Dali diff --git a/dali-toolkit/internal/transition/fade-impl.h b/dali-toolkit/internal/transition/fade-impl.h new file mode 100644 index 0000000..0ac5c73 --- /dev/null +++ b/dali-toolkit/internal/transition/fade-impl.h @@ -0,0 +1,106 @@ +#ifndef DALI_TOOLKIT_INTERNAL_FADE_H +#define DALI_TOOLKIT_INTERNAL_FADE_H + +/* + * Copyright (c) 2021 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// INTERNAL INCLUDES +#include +#include +#include + +// EXTERNAL INCLUDES +#include + +namespace Dali +{ +namespace Toolkit +{ +namespace Internal +{ +using FadePtr = IntrusivePtr; + +class Fade : public TransitionBase +{ +public: + /** + * @brief Create a new Fade object. + * @param[in] control A control of this transition. + * @param[in] opacity opacity value the control Opacity property will be changed from/to. + * @param[in] timePeriod The duration of the animation. + * @return A smart-pointer to the newly allocated Fade. + */ + static FadePtr New(Dali::Toolkit::Control control, float opacity, TimePeriod timePeriod); + +protected: + /** + * @copydoc Dali::Toolkit::Fade::OnPlay() + */ + void OnPlay() override; + +protected: + /** + * @brief Construct a new Fade. + */ + Fade(Dali::Toolkit::Control control, + float opacity, + TimePeriod timePeriod); + + /** + * @brief A reference counted object may only be deleted by calling Unreference() + */ + ~Fade() override; + +private: + // Undefined + Fade(const Fade&); + + // Undefined + Fade& operator=(const Fade& rhs); + +private: + WeakHandle mTargetControl; + float mOpacity; +}; + +} // namespace Internal + +// Helpers for public-api forwarding methods + +inline Internal::Fade& GetImplementation(Dali::Toolkit::Fade& fade) +{ + DALI_ASSERT_ALWAYS(fade && "Fade handle is empty"); + + BaseObject& handle = fade.GetBaseObject(); + + return static_cast(handle); +} + +inline const Internal::Fade& GetImplementation(const Dali::Toolkit::Fade& fade) +{ + DALI_ASSERT_ALWAYS(fade && "Fade handle is empty"); + + const BaseObject& handle = fade.GetBaseObject(); + + return static_cast(handle); +} + +} // namespace Toolkit + +} // namespace Dali + +#endif // DALI_TOOLKIT_INTERNAL_FADE_H diff --git a/dali-toolkit/internal/transition/transition-base-impl.cpp b/dali-toolkit/internal/transition/transition-base-impl.cpp index 42fb10d..241eb06 100644 --- a/dali-toolkit/internal/transition/transition-base-impl.cpp +++ b/dali-toolkit/internal/transition/transition-base-impl.cpp @@ -104,7 +104,8 @@ TransitionBase::TransitionBase() : mAlphaFunction(DEFAULT_ALPHA_FUNCTION), mTimePeriod(TimePeriod(0.0f)), mTransitionWithChild(false), - mMoveTargetChildren(false) + mMoveTargetChildren(false), + mIsAppearingTransition(true) { } diff --git a/dali-toolkit/internal/transition/transition-base-impl.h b/dali-toolkit/internal/transition/transition-base-impl.h index 84ef316..b3289ec 100644 --- a/dali-toolkit/internal/transition/transition-base-impl.h +++ b/dali-toolkit/internal/transition/transition-base-impl.h @@ -92,6 +92,15 @@ public: */ void TransitionFinished(); + /** + * @brief Set this transition is appearing transition or not. + * @param[in] appearingTransition True if this transition is appearing transition. + */ + void SetAppearingTransition(bool appearingTransition) + { + mIsAppearingTransition = appearingTransition; + } + protected: /** * @brief Set property map which will be used as a initial properties. @@ -151,11 +160,19 @@ protected: /** * @brief Returns whether this transition will be applied to children of target or not. */ - bool IsTransitionWithChild() + bool IsTransitionWithChild() const { return mTransitionWithChild; } + /** + * @brief Returns whether this transition is appearing transition or not + */ + bool IsAppearingTransition() const + { + return mIsAppearingTransition; + } + protected: /** * Construct a new TransitionBase. @@ -234,6 +251,7 @@ private: 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. }; } // namespace Internal diff --git a/dali-toolkit/internal/transition/transition-impl.cpp b/dali-toolkit/internal/transition/transition-impl.cpp index ef193f6..a465433 100644 --- a/dali-toolkit/internal/transition/transition-impl.cpp +++ b/dali-toolkit/internal/transition/transition-impl.cpp @@ -79,37 +79,39 @@ Transition::~Transition() void Transition::OnPlay() { - if(!mSourceControl[Dali::Actor::Property::CONNECTED_TO_SCENE] || - !mDestinationControl[Dali::Actor::Property::CONNECTED_TO_SCENE]) + 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]) { DALI_LOG_ERROR("The source or destination is not added on the window\n"); return; } //Make startPropertyMap and finishPropertyMap to use for property animation. - Matrix sourceWorldTransform = mSourceControl[Dali::Actor::Property::WORLD_MATRIX]; + Matrix sourceWorldTransform = sourceControl[Dali::Actor::Property::WORLD_MATRIX]; Vector3 sourcePosition, sourceScale; Quaternion sourceOrientation; sourceWorldTransform.GetTransformComponents(sourcePosition, sourceOrientation, sourceScale); - Matrix destinationWorldTransform = GetWorldTransform(mDestinationControl); + Matrix destinationWorldTransform = GetWorldTransform(destinationControl); Vector3 destinationPosition, destinationScale; Quaternion destinationOrientation; destinationWorldTransform.GetTransformComponents(destinationPosition, destinationOrientation, destinationScale); - Vector3 targetSize = mDestinationControl[Dali::Actor::Property::SIZE]; - Vector4 targetColor = GetWorldColor(mDestinationControl); + Vector3 targetSize = destinationControl[Dali::Actor::Property::SIZE]; + Vector4 targetColor = GetWorldColor(destinationControl); Property::Map startPropertyMap; Property::Map finishPropertyMap; // Use world transform if this transition requires animation of transform. - mDestinationControl[Dali::Actor::Property::ANCHOR_POINT] = AnchorPoint::CENTER; - mDestinationControl[Dali::Actor::Property::PARENT_ORIGIN] = ParentOrigin::CENTER; - mDestinationControl[Dali::Actor::Property::POSITION_USES_ANCHOR_POINT] = true; - mDestinationControl[Dali::Actor::Property::INHERIT_POSITION] = false; - mDestinationControl[Dali::Actor::Property::INHERIT_ORIENTATION] = false; - mDestinationControl[Dali::Actor::Property::INHERIT_SCALE] = false; - mDestinationControl[Dali::Actor::Property::COLOR_MODE] = Dali::ColorMode::USE_OWN_COLOR; + destinationControl[Dali::Actor::Property::ANCHOR_POINT] = AnchorPoint::CENTER; + destinationControl[Dali::Actor::Property::PARENT_ORIGIN] = ParentOrigin::CENTER; + destinationControl[Dali::Actor::Property::POSITION_USES_ANCHOR_POINT] = true; + destinationControl[Dali::Actor::Property::INHERIT_POSITION] = false; + destinationControl[Dali::Actor::Property::INHERIT_ORIENTATION] = false; + destinationControl[Dali::Actor::Property::INHERIT_SCALE] = false; + destinationControl[Dali::Actor::Property::COLOR_MODE] = Dali::ColorMode::USE_OWN_COLOR; // Set animation of Transform startPropertyMap.Insert(Dali::Actor::Property::POSITION, sourcePosition); @@ -121,12 +123,12 @@ void Transition::OnPlay() startPropertyMap.Insert(Dali::Actor::Property::SCALE, sourceScale); finishPropertyMap.Insert(Dali::Actor::Property::SCALE, destinationScale); - Vector4 sourceColor = mSourceControl.GetCurrentProperty(Dali::Actor::Property::WORLD_COLOR); + Vector4 sourceColor = sourceControl.GetCurrentProperty(Dali::Actor::Property::WORLD_COLOR); startPropertyMap.Insert(Dali::Actor::Property::COLOR, sourceColor); finishPropertyMap.Insert(Dali::Actor::Property::COLOR, targetColor); // Set animation for other properties if source and destination is different. - Vector3 sourceSize = mSourceControl.GetCurrentProperty(Dali::Actor::Property::SIZE); + Vector3 sourceSize = sourceControl.GetCurrentProperty(Dali::Actor::Property::SIZE); if(sourceSize != targetSize) { startPropertyMap.Insert(Dali::Actor::Property::SIZE, sourceSize); @@ -139,11 +141,11 @@ void Transition::OnPlay() // source View becomes transparent during transition. if(IsTransitionWithChild()) { - mSourceControl[Dali::Actor::Property::VISIBLE] = false; + sourceControl[Dali::Actor::Property::VISIBLE] = false; } else { - GetImplementation(mSourceControl).SetTransparent(true); + GetImplementation(sourceControl).SetTransparent(true); } Dali::Animation animation = GetAnimation(); @@ -152,18 +154,24 @@ void Transition::OnPlay() DALI_LOG_ERROR("animation is still not initialized\n"); return; } - Dali::Toolkit::DevelControl::CreateTransitions(mDestinationControl, animation, mSourceControl, GetAlphaFunction(), GetTimePeriod()); + Dali::Toolkit::DevelControl::CreateTransitions(destinationControl, animation, sourceControl, GetAlphaFunction(), GetTimePeriod()); } void Transition::OnFinished() { + Dali::Toolkit::Control sourceControl = mSourceControl.GetHandle(); + if(!sourceControl) + { + return; + } + if(IsTransitionWithChild()) { - mSourceControl[Dali::Actor::Property::VISIBLE] = true; + sourceControl[Dali::Actor::Property::VISIBLE] = true; } else { - GetImplementation(mSourceControl).SetTransparent(false); + GetImplementation(sourceControl).SetTransparent(false); } } diff --git a/dali-toolkit/internal/transition/transition-impl.h b/dali-toolkit/internal/transition/transition-impl.h index d9120bf..6aa1374 100644 --- a/dali-toolkit/internal/transition/transition-impl.h +++ b/dali-toolkit/internal/transition/transition-impl.h @@ -23,6 +23,9 @@ #include #include +// EXTERNAL INCLUDES +#include + namespace Dali { namespace Toolkit @@ -38,7 +41,7 @@ public: * @brief Create a new Transition object. * @param[in] source A source control of this transition. * @param[in] destination A destination control of this transition. - * @param[in] durationSeconds The duration of the animation. + * @param[in] timePeriod The timePeriod of the animation. * @return A smart-pointer to the newly allocated Transition. */ static TransitionPtr New(Dali::Toolkit::Control source, Dali::Toolkit::Control destination, TimePeriod timePeriod); @@ -75,8 +78,8 @@ private: Transition& operator=(const Transition& rhs); private: - Dali::Toolkit::Control mSourceControl; - Dali::Toolkit::Control mDestinationControl; + WeakHandle mSourceControl; + WeakHandle mDestinationControl; }; } // namespace Internal diff --git a/dali-toolkit/public-api/file.list b/dali-toolkit/public-api/file.list index 071b602..895bfc7 100644 --- a/dali-toolkit/public-api/file.list +++ b/dali-toolkit/public-api/file.list @@ -31,6 +31,7 @@ SET( public_api_src_files ${public_api_src_dir}/image-loader/async-image-loader.cpp ${public_api_src_dir}/image-loader/sync-image-loader.cpp ${public_api_src_dir}/styling/style-manager.cpp + ${public_api_src_dir}/transition/fade.cpp ${public_api_src_dir}/transition/transition-base.cpp ${public_api_src_dir}/transition/transition-set.cpp ${public_api_src_dir}/transition/transition.cpp @@ -147,6 +148,7 @@ SET( public_api_visuals_header_files ) SET( public_api_transition_header_files + ${public_api_src_dir}/transition/fade.h ${public_api_src_dir}/transition/transition-base.h ${public_api_src_dir}/transition/transition-set.h ${public_api_src_dir}/transition/transition.h diff --git a/dali-toolkit/public-api/transition/fade.cpp b/dali-toolkit/public-api/transition/fade.cpp new file mode 100644 index 0000000..b5e54dc --- /dev/null +++ b/dali-toolkit/public-api/transition/fade.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2021 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// CLASS HEADER +#include + +// INTERNAL INCLUDES +#include + +namespace Dali +{ +namespace Toolkit +{ +Fade::Fade() = default; + +Fade::Fade(Internal::Fade* fade) +: TransitionBase(fade) +{ +} + +Fade Fade::New(Dali::Toolkit::Control control, float opacity, TimePeriod timePeriod) +{ + Internal::FadePtr internal = Dali::Toolkit::Internal::Fade::New(control, opacity, timePeriod); + + return Fade(internal.Get()); +} + +Fade Fade::DownCast(BaseHandle handle) +{ + return Fade(dynamic_cast(handle.GetObjectPtr())); +} + +Fade::~Fade() = default; + +Fade::Fade(const Fade& handle) = default; + +Fade& Fade::operator=(const Fade& rhs) = default; + +Fade::Fade(Fade&& rhs) = default; + +Fade& Fade::operator=(Fade&& rhs) = default; + +} // namespace Toolkit + +} // namespace Dali diff --git a/dali-toolkit/public-api/transition/fade.h b/dali-toolkit/public-api/transition/fade.h new file mode 100644 index 0000000..dbafb7b --- /dev/null +++ b/dali-toolkit/public-api/transition/fade.h @@ -0,0 +1,119 @@ +#ifndef DALI_TOOLKIT_FADE_H +#define DALI_TOOLKIT_FADE_H + +/* + * Copyright (c) 2021 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// INTERNAL INCLUDES +#include +#include + +namespace Dali +{ +namespace Toolkit +{ +namespace Internal DALI_INTERNAL +{ +class Fade; +} + +/** + * @brief Fade provides smoothly appearing/disappearing effects for target Control. + */ +class DALI_TOOLKIT_API Fade : public TransitionBase +{ +public: + /** + * @brief Creates an uninitialized Fade; this can be initialized with Fade::New(). + * + * Calling member functions with an uninitialized Fade handle is not allowed. + */ + Fade(); + + /** + * @brief Creates an initialized Fade. + * + * @param[in] control A control of this transition. + * @param[in] opacity opacity value the control Opacity property will be changed from/to. Opacity must be between [0, 1]. + * @param[in] timePeriod The duration of the animation. + * @return A handle to a newly allocated Dali resource + */ + static Fade New(Dali::Toolkit::Control control, float opacity, TimePeriod timePeriod); + + /** + * @brief Downcasts a handle to Fade handle. + * + * If handle points to an Fade object, the downcast produces valid handle. + * If not, the returned handle is left uninitialized. + * + * @param[in] handle Handle to an object + * @return Handle to an Fade object or an uninitialized handle + */ + static Fade DownCast(BaseHandle handle); + + /** + * @brief Destructor. + * + * This is non-virtual since derived Handle types must not contain data or virtual methods. + */ + ~Fade(); + + /** + * @brief This copy constructor is required for (smart) pointer semantics. + * + * @param[in] handle A reference to the copied handle + */ + Fade(const Fade& handle); + + /** + * @brief This assignment operator is required for (smart) pointer semantics. + * + * @param[in] rhs A reference to the copied handle + * @return A reference to this + */ + Fade& operator=(const Fade& rhs); + + /** + * @brief Move constructor. + * + * @param[in] rhs A reference to the moved handle + */ + Fade(Fade&& rhs); + + /** + * @brief Move assignment operator. + * + * @param[in] rhs A reference to the moved handle + * @return A reference to this handle + */ + Fade& operator=(Fade&& rhs); + +public: // Not intended for use by Application developers + /// @cond internal + /** + * @brief This constructor is used by Fade::New() methods. + * @param[in] fade A pointer to a newly allocated Dali resource + */ + explicit DALI_INTERNAL Fade(Internal::Fade* fade); + /// @endcond +}; + +} // namespace Toolkit + +} // namespace Dali + +#endif // DALI_TOOLKIT_FADE_H diff --git a/dali-toolkit/public-api/transition/transition-base.cpp b/dali-toolkit/public-api/transition/transition-base.cpp index 5e70e21..6b88c84 100644 --- a/dali-toolkit/public-api/transition/transition-base.cpp +++ b/dali-toolkit/public-api/transition/transition-base.cpp @@ -76,7 +76,12 @@ AlphaFunction TransitionBase::GetAlphaFunction() const void TransitionBase::TransitionWithChild(bool transitionWithChild) { - return GetImplementation(*this).TransitionWithChild(transitionWithChild); + GetImplementation(*this).TransitionWithChild(transitionWithChild); +} + +void TransitionBase::SetAppearingTransition(bool appearingTransition) +{ + GetImplementation(*this).SetAppearingTransition(appearingTransition); } } // namespace Toolkit diff --git a/dali-toolkit/public-api/transition/transition-base.h b/dali-toolkit/public-api/transition/transition-base.h index 9a274ac..6deaeff 100644 --- a/dali-toolkit/public-api/transition/transition-base.h +++ b/dali-toolkit/public-api/transition/transition-base.h @@ -131,10 +131,17 @@ public: AlphaFunction GetAlphaFunction() const; /** - * @brief A View could be transition with its child Views or without them. + * @brief A Control could be transition with its child Controls or without them. + * @param[in] transitionWithChild True if the Control is transitioned with children. */ void TransitionWithChild(bool transitionWithChild); + /** + * @brief Set this transition is appearing transition or not. + * @param[in] appearingTransition True if this transition is appearing transition. + */ + void SetAppearingTransition(bool appearingTransition); + public: // Not intended for use by Application developers /// @cond internal /**