Set KeyFrame's frame value 66/292066/2
authorEunki, Hong <eunkiki.hong@samsung.com>
Thu, 27 Apr 2023 02:37:18 +0000 (11:37 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Thu, 27 Apr 2023 04:59:48 +0000 (13:59 +0900)
Let we make the API to change the value of specific KeyFrame data

Change-Id: Iecd9cb3b9118083dfa6d4ab812bf31dac4e1d38a
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
automated-tests/src/dali/utc-Dali-Animation.cpp
dali/devel-api/animation/key-frames-devel.cpp
dali/devel-api/animation/key-frames-devel.h
dali/internal/event/animation/key-frames-impl.cpp
dali/internal/event/animation/key-frames-impl.h

index af55979..e09941a 100644 (file)
@@ -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<Vector4>(), 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<Vector4>(), newValue, TEST_LOCATION);
+
+  END_TEST;
+}
+
 int UtcDaliAnimationAnimateBetweenActorColorAlphaP(void)
 {
   TestApplication application;
index ebf3787..37ec9a1 100644 (file)
@@ -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
index a24e48e..936cf44 100644 (file)
@@ -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
index bd486e5..e68e18c 100644 (file)
@@ -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
index 919fedf..9c84d06 100644 (file)
@@ -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<KeyFrameSpec> 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<V>();
+  }
+
+  /**
    * 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