[NUI] Add some API for KeyFrames
authorEunki, Hong <eunkiki.hong@samsung.com>
Wed, 21 Jun 2023 03:36:02 +0000 (12:36 +0900)
committerbshsqa <32317749+bshsqa@users.noreply.github.com>
Wed, 23 Aug 2023 07:06:57 +0000 (16:06 +0900)
1. `GetKeyFrameCount()` to know how many keyframes are added.
2. `GetKeyFrame()` to know the information of specific index.
3. `SetKeyFrameValue()` to change the value for specific index.

Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
src/Tizen.NUI/src/internal/Interop/Interop.KeyFrames.cs
src/Tizen.NUI/src/public/Animation/KeyFrames.cs
test/Tizen.NUI.Devel.Tests.Ubuntu/Tizen.NUI.Devel.Tests/testcase/TSKeyFrames.cs [new file with mode: 0755]

index 4047db6..da98110 100755 (executable)
@@ -42,6 +42,15 @@ namespace Tizen.NUI
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_KeyFrames_GetType")]
             public static extern int GetType(global::System.Runtime.InteropServices.HandleRef jarg1);
 
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_KeyFrames_GetKeyFrameCount")]
+            public static extern uint GetKeyFrameCount(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_KeyFrames_GetKeyFrame")]
+            public static extern void GetKeyFrame(global::System.Runtime.InteropServices.HandleRef jarg1, uint index, out float time, global::System.Runtime.InteropServices.HandleRef value);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_KeyFrames_SetKeyFrameValue")]
+            public static extern void SetKeyFrameValue(global::System.Runtime.InteropServices.HandleRef jarg1, uint index, global::System.Runtime.InteropServices.HandleRef value);
+
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_KeyFrames_Add__SWIG_0")]
             public static extern void Add(global::System.Runtime.InteropServices.HandleRef jarg1, float jarg2, global::System.Runtime.InteropServices.HandleRef jarg3);
 
index 1a9cb86..818e191 100755 (executable)
@@ -67,7 +67,9 @@ namespace Tizen.NUI
         }
 
         /// <summary>
-        /// Gets the type of the key frame.
+        /// Gets the type of the key frame.<br/>
+        /// An empty key frame will return PropertyType.None, wheras an initialised<br/>
+        /// key frame object will return the type of it's first element.
         /// </summary>
         /// <returns>The key frame property type</returns>
         /// <since_tizen> 3 </since_tizen>
@@ -103,6 +105,47 @@ namespace Tizen.NUI
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
+        /// <summary>
+        /// Get the number of added key frame.
+        /// </summary>
+        /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public uint GetKeyFrameCount()
+        {
+            uint ret = Interop.KeyFrames.GetKeyFrameCount(SwigCPtr);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        /// <summary>
+        /// Get the progress and value from specific key frame.<br/>
+        /// If index is greater or equal than total key frame count, progress and value is not changed.
+        /// </summary>
+        /// <param name="index">The index of keyframe.</param>
+        /// <param name="progress">A progress value between 0.0 and 1.0.</param>
+        /// <param name="value">A value.</param>
+        /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void GetKeyFrame(uint index, out float progress, PropertyValue value)
+        {
+            Interop.KeyFrames.GetKeyFrame(SwigCPtr, index, out progress, PropertyValue.getCPtr(value));
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        /// <summary>
+        /// Set the value to specific key frame.<br/>
+        /// If index is greater or equal than total key frame count or value's PropertyType is not matched, Nothing happened.
+        /// </summary>
+        /// <param name="index">The index of keyframe.</param>
+        /// <param name="value">A value.</param>
+        /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void SetKeyFrameValue(uint index, PropertyValue value)
+        {
+            Interop.KeyFrames.SetKeyFrameValue(SwigCPtr, index, PropertyValue.getCPtr(value));
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
         /// This will not be public opened.
         [EditorBrowsable(EditorBrowsableState.Never)]
         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
diff --git a/test/Tizen.NUI.Devel.Tests.Ubuntu/Tizen.NUI.Devel.Tests/testcase/TSKeyFrames.cs b/test/Tizen.NUI.Devel.Tests.Ubuntu/Tizen.NUI.Devel.Tests/testcase/TSKeyFrames.cs
new file mode 100755 (executable)
index 0000000..0c51976
--- /dev/null
@@ -0,0 +1,122 @@
+using global::System;
+using NUnit.Framework;
+using NUnit.Framework.TUnit;
+using Tizen.NUI.Components;
+using Tizen.NUI.BaseComponents;
+
+namespace Tizen.NUI.Tests
+{
+    using tlog = Tizen.Log;
+
+    [TestFixture]
+    [Description("public/Animation/KeyFrames")]
+    public class InternalKeyFramesTests
+    {
+        private string tag = "NUITEST";
+
+        [SetUp]
+        public void Init()
+        {
+            tlog.Info(tag, "Init() is called!");
+        }
+
+        [TearDown]
+        public void Destroy()
+        {
+            tlog.Info(tag, "Destroy() is called!");
+        }
+
+        [Test]
+        [Category("P1")]
+        [Description("Test GetKeyFrameCount. Check whether it return the right value.")]
+        [Property("SPEC", "Tizen.NUI.KeyFrames.GetKeyFrameCount M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MR")]
+        [Property("AUTHOR", "Eunki Hong, eunkiki.hong@samsung.com")]
+        public void GetKeyFrameCount_CHECK_RETURN_VALUE()
+        {
+            /* TEST CODE */
+            var keyFrames = new KeyFrames();
+            Assert.AreEqual(0u, keyFrames.GetKeyFrameCount(), "The number of keyframes must be matched.");
+            keyFrames.Add(0.0f, new Position(0.1f, 0.2f, 0.3f));
+            Assert.AreEqual(1u, keyFrames.GetKeyFrameCount(), "The number of keyframes must be matched.");
+            keyFrames.Add(0.5f, new Position(0.9f, 0.8f, 0.7f));
+            Assert.AreEqual(2u, keyFrames.GetKeyFrameCount(), "The number of keyframes must be matched.");
+            keyFrames.Add(1.0f, new Position(1.0f, 1.0f, 1.0f));
+            Assert.AreEqual(3u, keyFrames.GetKeyFrameCount(), "The number of keyframes must be matched.");
+        }
+
+        [Test]
+        [Category("P1")]
+        [Description("Test GetKeyFrame. Check whether it return the right value.")]
+        [Property("SPEC", "Tizen.NUI.KeyFrames.GetKeyFrame M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MR")]
+        [Property("AUTHOR", "Eunki Hong, eunkiki.hong@samsung.com")]
+        public void GetKeyFrame_GET_VALUE()
+        {
+            /* TEST CODE */
+            var keyFrames = new KeyFrames();
+            float returnProgress = -1.0f;
+            PropertyValue returnValue = new PropertyValue();
+            float returnValueFloat = -1.0f;
+
+            keyFrames.GetKeyFrame(2u, out returnProgress, returnValue);
+            Assert.AreEqual(false, returnValue.Get(out returnValueFloat), "The value of keyframes must not be float.");
+            Assert.AreEqual(-1.0f, returnProgress, "The value of keyframes must be changed.");
+
+            keyFrames.Add(0.0f, 2.0f);
+            keyFrames.Add(0.5f, 4.0f);
+            keyFrames.Add(1.0f, 7.0f);
+
+            keyFrames.GetKeyFrame(0u, out returnProgress, returnValue);
+            Assert.AreEqual(true, returnValue.Get(out returnValueFloat), "The value of keyframes must be float.");
+            Assert.AreEqual(0.0f, returnProgress, "The value of keyframes must be matched.");
+            Assert.AreEqual(2.0f, returnValueFloat, "The value of keyframes must be matched.");
+
+            keyFrames.GetKeyFrame(1u, out returnProgress, returnValue);
+            Assert.AreEqual(true, returnValue.Get(out returnValueFloat), "The value of keyframes must be float.");
+            Assert.AreEqual(0.5f, returnProgress, "The value of keyframes must be matched.");
+            Assert.AreEqual(4.0f, returnValueFloat, "The value of keyframes must be matched.");
+
+            keyFrames.GetKeyFrame(2u, out returnProgress, returnValue);
+            Assert.AreEqual(true, returnValue.Get(out returnValueFloat), "The value of keyframes must be float.");
+            Assert.AreEqual(1.0f, returnProgress, "The value of keyframes must be matched.");
+            Assert.AreEqual(7.0f, returnValueFloat, "The value of keyframes must be matched.");
+        }
+
+        [Test]
+        [Category("P1")]
+        [Description("Test SetKeyFrameValue. Check whether it setup the right value.")]
+        [Property("SPEC", "Tizen.NUI.KeyFrames.SetKeyFrameValue M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MR")]
+        [Property("AUTHOR", "Eunki Hong, eunkiki.hong@samsung.com")]
+        public void SetKeyFrameValue_SET_VALUE()
+        {
+            /* TEST CODE */
+            var keyFrames = new KeyFrames();
+            float returnProgress = -1.0f;
+            PropertyValue returnValue = new PropertyValue();
+            float returnValueFloat = -1.0f;
+
+            keyFrames.SetKeyFrameValue(1u, new PropertyValue(3.0f));
+
+            keyFrames.Add(0.0f, 2.0f);
+            keyFrames.Add(0.5f, 4.0f);
+            keyFrames.Add(1.0f, 7.0f);
+
+            keyFrames.GetKeyFrame(1u, out returnProgress, returnValue);
+            Assert.AreEqual(true, returnValue.Get(out returnValueFloat), "The value of keyframes must be float.");
+            Assert.AreEqual(0.5f, returnProgress, "The value of keyframes must be matched.");
+            Assert.AreEqual(4.0f, returnValueFloat, "The value of keyframes must be matched.");
+
+            keyFrames.SetKeyFrameValue(1u, new PropertyValue(1.0f));
+
+            keyFrames.GetKeyFrame(1u, out returnProgress, returnValue);
+            Assert.AreEqual(true, returnValue.Get(out returnValueFloat), "The value of keyframes must be float.");
+            Assert.AreEqual(0.5f, returnProgress, "The value of keyframes must be matched.");
+            Assert.AreEqual(1.0f, returnValueFloat, "The value of keyframes must be matched.");
+        }
+    }
+}