From: JIYUN YANG Date: Tue, 9 Feb 2021 00:50:31 +0000 (+0000) Subject: Merge "Add KeyFrames APIs" into devel/master X-Git-Tag: dali_2.0.13~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9311c4e66c2fd3625455f29e6568c4292fac409d;hp=eb34d16d40ea0be23cbe1e64412f6fe3fa1c141c;p=platform%2Fcore%2Fuifw%2Fdali-core.git Merge "Add KeyFrames APIs" into devel/master --- diff --git a/automated-tests/src/dali/utc-Dali-Animation.cpp b/automated-tests/src/dali/utc-Dali-Animation.cpp index d453600..1f28227 100644 --- a/automated-tests/src/dali/utc-Dali-Animation.cpp +++ b/automated-tests/src/dali/utc-Dali-Animation.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -9187,6 +9188,48 @@ int UtcDaliAnimationKeyFrames07N(void) END_TEST; } +int UtcDaliAnimationKeyFramesGetKeyFrameCountP(void) +{ + TestApplication application; + + KeyFrames keyFrames = KeyFrames::New(); + keyFrames.Add(0.0f, Vector4(0.0f, 0.0f, 0.0f, 0.6f)); + keyFrames.Add(0.6f, Vector4(0.0f, 0.0f, 0.0f, 0.3f)); + keyFrames.Add(1.0f, Vector4(0.0f, 0.0f, 0.0f, 0.8f)); + + DALI_TEST_EQUALS(DevelKeyFrames::GetKeyFrameCount(keyFrames), 3, TEST_LOCATION); + + END_TEST; +} + +int UtcDaliAnimationKeyFramesGetKeyFrameP(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); + + 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 new file mode 100644 index 0000000..f94c6b6 --- /dev/null +++ b/dali/devel-api/animation/key-frames-devel.cpp @@ -0,0 +1,39 @@ +/* + * 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 DevelKeyFrames +{ + +std::size_t GetKeyFrameCount(KeyFrames keyFrames) +{ + return GetImplementation(keyFrames).GetKeyFrameCount(); +} + +void GetKeyFrame(KeyFrames keyFrames, std::size_t index, float& time, Property::Value& value) +{ + GetImplementation(keyFrames).GetKeyFrame(index, time, 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 new file mode 100644 index 0000000..a24e48e --- /dev/null +++ b/dali/devel-api/animation/key-frames-devel.h @@ -0,0 +1,50 @@ +#ifndef DALI_KEY_FRAMES_DEVEL_H +#define DALI_KEY_FRAMES_DEVEL_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 + +namespace Dali +{ +namespace DevelKeyFrames +{ +using ValueConvertor = Property::Value (*)(const Property::Value& input); + +/** + * @brief Get the number of key frames. + * @param[in] keyFrames The KeyFrames object to perform this operation on + * @return Total number of key frames + */ +DALI_CORE_API std::size_t GetKeyFrameCount(KeyFrames keyFrames); + +/** + * Get a key frame. + * @param[in] keyFrames The KeyFrames object to perform this operation on + * @param[in] index The index of the key frame to fetch + * @param[out] time The progress of the given key frame + * @param[out] value The value of the given key frame + */ +DALI_CORE_API void GetKeyFrame(KeyFrames keyFrames, std::size_t index, float& time, Property::Value& value); + +} // namespace DevelKeyFrames + +} // namespace Dali + +#endif // DALI_KEY_FRAMES_DEVEL_H diff --git a/dali/devel-api/file.list b/dali/devel-api/file.list index 1973073..c28900e 100644 --- a/dali/devel-api/file.list +++ b/dali/devel-api/file.list @@ -7,6 +7,7 @@ SET( devel_api_src_files ${devel_api_src_dir}/actors/custom-actor-devel.cpp ${devel_api_src_dir}/animation/animation-data.cpp ${devel_api_src_dir}/animation/animation-devel.cpp + ${devel_api_src_dir}/animation/key-frames-devel.cpp ${devel_api_src_dir}/animation/path-constrainer.cpp ${devel_api_src_dir}/common/addon-binder.cpp ${devel_api_src_dir}/common/capabilities.cpp @@ -59,6 +60,7 @@ SET( devel_api_core_animation_header_files ${devel_api_src_dir}/animation/animation-data.h ${devel_api_src_dir}/animation/path-constrainer.h ${devel_api_src_dir}/animation/animation-devel.h + ${devel_api_src_dir}/animation/key-frames-devel.h ) diff --git a/dali/internal/event/animation/key-frames-impl.cpp b/dali/internal/event/animation/key-frames-impl.cpp index b7bfda3..bd486e5 100644 --- a/dali/internal/event/animation/key-frames-impl.cpp +++ b/dali/internal/event/animation/key-frames-impl.cpp @@ -157,11 +157,25 @@ Property::Value KeyFrames::GetLastKeyFrameValue() const std::size_t noOfKeyFrames = mKeyFrames->GetNumberOfKeyFrames(); if(noOfKeyFrames) { - mKeyFrames->GetKeyFrameAsValue(noOfKeyFrames - 1, value); + float time; + mKeyFrames->GetKeyFrameAsValue(noOfKeyFrames - 1, time, value); } return value; } +std::size_t KeyFrames::GetKeyFrameCount() const +{ + return mKeyFrames->GetNumberOfKeyFrames(); +} + +void KeyFrames::GetKeyFrame(std::size_t index, float& time, Property::Value& value) const +{ + if(index < mKeyFrames->GetNumberOfKeyFrames()) + { + mKeyFrames->GetKeyFrameAsValue(index, time, 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 1c4dc45..919fedf 100644 --- a/dali/internal/event/animation/key-frames-impl.h +++ b/dali/internal/event/animation/key-frames-impl.h @@ -82,6 +82,16 @@ public: */ Dali::Property::Value GetLastKeyFrameValue() const; + /** + * @copydoc Dali::DevelKeyFrames::GetKeyFrameCount() + */ + std::size_t GetKeyFrameCount() const; + + /** + * @copydoc Dali::DevelKeyFrames::GetKeyFrame() + */ + void GetKeyFrame(std::size_t index, float& time, Property::Value& value) const; + private: Dali::Property::Type mType{Property::NONE}; // Type of the specialization std::unique_ptr mKeyFrames; // Pointer to the specialized key frame object @@ -101,9 +111,10 @@ public: /** * Get the key frame value as a Property::Value. * @param[in] index The index of the key frame to fetch + * @param[out] time The progress of the given key frame * @param[out] value The value of the given key frame */ - virtual void GetKeyFrameAsValue(std::size_t index, Property::Value& value) = 0; + virtual void GetKeyFrameAsValue(std::size_t index, float& time, Property::Value& value) const = 0; }; /** @@ -153,9 +164,11 @@ public: /** * @copydoc KeyFrameSpec::GetKeyFrameAsValue() */ - void GetKeyFrameAsValue(std::size_t index, Property::Value& value) override + void GetKeyFrameAsValue(std::size_t index, float& time, Property::Value& value) const override { - value = mChannel.mValues[index].mValue; + const auto& element = mChannel.mValues[index]; + time = element.mProgress; + value = element.mValue; } /**