Skip to content

Commit

Permalink
[NUI] Add some API for KeyFrames
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Eunki, Hong committed Jun 21, 2023
1 parent 514ea05 commit b3f71b3
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/Tizen.NUI/src/internal/Interop/Interop.KeyFrames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ internal static partial class KeyFrames
[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);

Expand Down
45 changes: 44 additions & 1 deletion src/Tizen.NUI/src/public/Animation/KeyFrames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ public void Add(float progress, object value, AlphaFunction alpha)
}

/// <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>
Expand Down Expand Up @@ -103,6 +105,47 @@ public void Add(float progress, PropertyValue value, AlphaFunction alpha)
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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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, [email protected]")]
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, [email protected]")]
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, [email protected]")]
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.");
}
}
}

0 comments on commit b3f71b3

Please sign in to comment.