Add KeyFrames APIs 74/252974/10
authorJiyun Yang <ji.yang@samsung.com>
Wed, 3 Feb 2021 12:14:03 +0000 (21:14 +0900)
committerJiyun Yang <ji.yang@samsung.com>
Mon, 8 Feb 2021 04:11:05 +0000 (13:11 +0900)
* GetKeyFrameCount
* GetKeyFrame

This method creates a new KeyFrames with difference type from the original.

Change-Id: I03e1767958332c548c99a936da8e3779ef5b8b5e
Signed-off-by: Jiyun Yang <ji.yang@samsung.com>
automated-tests/src/dali/utc-Dali-Animation.cpp
dali/devel-api/animation/key-frames-devel.cpp [new file with mode: 0644]
dali/devel-api/animation/key-frames-devel.h [new file with mode: 0644]
dali/devel-api/file.list
dali/internal/event/animation/key-frames-impl.cpp
dali/internal/event/animation/key-frames-impl.h

index d453600..1f28227 100644 (file)
@@ -18,6 +18,7 @@
 #include <dali-test-suite-utils.h>
 #include <dali/devel-api/actors/actor-devel.h>
 #include <dali/devel-api/animation/animation-devel.h>
+#include <dali/devel-api/animation/key-frames-devel.h>
 #include <dali/public-api/dali-core.h>
 #include <stdlib.h>
 
@@ -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<Vector4>(), 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 (file)
index 0000000..f94c6b6
--- /dev/null
@@ -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 <dali/devel-api/animation/key-frames-devel.h>
+#include <dali/internal/event/animation/key-frames-impl.h>
+
+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 (file)
index 0000000..a24e48e
--- /dev/null
@@ -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 <dali/public-api/animation/key-frames.h>
+
+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
index 1973073..c28900e 100644 (file)
@@ -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
 )
 
 
index b7bfda3..bd486e5 100644 (file)
@@ -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
index 1c4dc45..919fedf 100644 (file)
@@ -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<KeyFrameSpec> 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;
   }
 
   /**