From 24fd3c88d89dd8b19fb0193c71cc78644082d019 Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Thu, 27 Apr 2023 11:37:18 +0900 Subject: [PATCH] Set KeyFrame's frame value Let we make the API to change the value of specific KeyFrame data Change-Id: Iecd9cb3b9118083dfa6d4ab812bf31dac4e1d38a Signed-off-by: Eunki, Hong --- automated-tests/src/dali/utc-Dali-Animation.cpp | 40 ++++++++++++++++++++++- dali/devel-api/animation/key-frames-devel.cpp | 7 +++- dali/devel-api/animation/key-frames-devel.h | 10 +++++- dali/internal/event/animation/key-frames-impl.cpp | 10 +++++- dali/internal/event/animation/key-frames-impl.h | 23 ++++++++++++- 5 files changed, 85 insertions(+), 5 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-Animation.cpp b/automated-tests/src/dali/utc-Dali-Animation.cpp index af55979..e09941a 100644 --- a/automated-tests/src/dali/utc-Dali-Animation.cpp +++ b/automated-tests/src/dali/utc-Dali-Animation.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -9230,6 +9230,44 @@ int UtcDaliAnimationKeyFramesGetKeyFrameP(void) END_TEST; } +int UtcDaliAnimationKeyFramesSetKeyFrameP(void) +{ + TestApplication application; + + float inputTime = 0.6f; + Vector4 inputValue = Vector4(0.0f, 0.0f, 0.0f, 0.3f); + + KeyFrames keyFrames = KeyFrames::New(); + keyFrames.Add(0.0f, Vector4(0.0f, 0.0f, 0.0f, 0.6f)); + keyFrames.Add(inputTime, inputValue); + keyFrames.Add(1.0f, Vector4(0.0f, 0.0f, 0.0f, 0.8f)); + + float outputTime; + Property::Value outputValue; + + DevelKeyFrames::GetKeyFrame(keyFrames, 3, outputTime, outputValue); + + DALI_TEST_EQUALS(outputValue.GetType(), Property::Type::NONE, TEST_LOCATION); + + DevelKeyFrames::GetKeyFrame(keyFrames, 1, outputTime, outputValue); + + DALI_TEST_EQUALS(outputTime, inputTime, TEST_LOCATION); + DALI_TEST_EQUALS(outputValue.GetType(), Property::Type::VECTOR4, TEST_LOCATION); + DALI_TEST_EQUALS(outputValue.Get(), inputValue, TEST_LOCATION); + + Vector4 newValue = Vector4(1.0f, 0.2f, 0.6f, 0.9f); + + DevelKeyFrames::SetKeyFrameValue(keyFrames, 1, newValue); + + DevelKeyFrames::GetKeyFrame(keyFrames, 1, outputTime, outputValue); + + DALI_TEST_EQUALS(outputTime, inputTime, TEST_LOCATION); + DALI_TEST_EQUALS(outputValue.GetType(), Property::Type::VECTOR4, TEST_LOCATION); + DALI_TEST_EQUALS(outputValue.Get(), newValue, TEST_LOCATION); + + END_TEST; +} + int UtcDaliAnimationAnimateBetweenActorColorAlphaP(void) { TestApplication application; diff --git a/dali/devel-api/animation/key-frames-devel.cpp b/dali/devel-api/animation/key-frames-devel.cpp index ebf3787..37ec9a1 100644 --- a/dali/devel-api/animation/key-frames-devel.cpp +++ b/dali/devel-api/animation/key-frames-devel.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -33,6 +33,11 @@ void GetKeyFrame(KeyFrames keyFrames, std::size_t index, float& time, Property:: GetImplementation(keyFrames).GetKeyFrame(index, time, value); } +void SetKeyFrameValue(KeyFrames keyFrames, std::size_t index, const Property::Value& value) +{ + GetImplementation(keyFrames).SetKeyFrameValue(index, value); +} + } // namespace DevelKeyFrames } // namespace Dali diff --git a/dali/devel-api/animation/key-frames-devel.h b/dali/devel-api/animation/key-frames-devel.h index a24e48e..936cf44 100644 --- a/dali/devel-api/animation/key-frames-devel.h +++ b/dali/devel-api/animation/key-frames-devel.h @@ -2,7 +2,7 @@ #define DALI_KEY_FRAMES_DEVEL_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -43,6 +43,14 @@ DALI_CORE_API std::size_t GetKeyFrameCount(KeyFrames keyFrames); */ DALI_CORE_API void GetKeyFrame(KeyFrames keyFrames, std::size_t index, float& time, Property::Value& value); +/** + * Set a key frame. + * @param[in] keyFrames The KeyFrames object to perform this operation on + * @param[in] index The index of the key frame to set + * @param[in] value The value of the given key frame + */ +DALI_CORE_API void SetKeyFrameValue(KeyFrames keyFrames, std::size_t index, const Property::Value& value); + } // namespace DevelKeyFrames } // namespace Dali diff --git a/dali/internal/event/animation/key-frames-impl.cpp b/dali/internal/event/animation/key-frames-impl.cpp index bd486e5..e68e18c 100644 --- a/dali/internal/event/animation/key-frames-impl.cpp +++ b/dali/internal/event/animation/key-frames-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -177,5 +177,13 @@ void KeyFrames::GetKeyFrame(std::size_t index, float& time, Property::Value& val } } +void KeyFrames::SetKeyFrameValue(std::size_t index, const Property::Value& value) +{ + if(index < mKeyFrames->GetNumberOfKeyFrames()) + { + mKeyFrames->SetKeyFrameValue(index, value); + } +} + } // namespace Internal } // namespace Dali diff --git a/dali/internal/event/animation/key-frames-impl.h b/dali/internal/event/animation/key-frames-impl.h index 919fedf..9c84d06 100644 --- a/dali/internal/event/animation/key-frames-impl.h +++ b/dali/internal/event/animation/key-frames-impl.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_KEY_FRAMES_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -92,6 +92,11 @@ public: */ void GetKeyFrame(std::size_t index, float& time, Property::Value& value) const; + /** + * @copydoc Dali::DevelKeyFrames::SetKeyFrameValue() + */ + void SetKeyFrameValue(std::size_t index, const Property::Value& value); + private: Dali::Property::Type mType{Property::NONE}; // Type of the specialization std::unique_ptr mKeyFrames; // Pointer to the specialized key frame object @@ -115,6 +120,13 @@ public: * @param[out] value The value of the given key frame */ virtual void GetKeyFrameAsValue(std::size_t index, float& time, Property::Value& value) const = 0; + + /** + * Set the key frame value as a Property::Value. + * @param[in] index The index of the key frame to set + * @param[in] value The value of the given key frame + */ + virtual void SetKeyFrameValue(std::size_t index, const Property::Value& value) = 0; }; /** @@ -172,6 +184,15 @@ public: } /** + * @copydoc KeyFrameSpec::SetKeyFrameValue() + */ + void SetKeyFrameValue(std::size_t index, const Property::Value& value) override + { + auto& element = mChannel.mValues[index]; + element.mValue = value.Get(); + } + + /** * Return whether the progress is valid for the range of keyframes. (The first * keyframe doesn't have to start at 0, and the last doesn't have to end at 1.0) * @param[in] progress The progress to test -- 2.7.4