/*
* 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.
* 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.
*
*/
using System;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Collections.Generic;
using Tizen.NUI;
namespace Tizen.NUI.Scene3D
{
///
/// This MotionValue be used for target value of each .
/// We can get and set MotionValue as 2 types : PropertyValue and KeyFrames.
///
/// Each types will be cross-converted internally.
/// For example, when we set PropertyValue, we can get KeyFrames with 2 frames, and target value is set.
///
///
/// The type of property should be matched with MotionIndex required.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public class MotionValue : BaseHandle
{
///
/// Determine whether current stored value is PropertyValue, or KeyFrames.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public enum ValueType
{
///
/// Value is null, or invalid class.
///
[EditorBrowsable(EditorBrowsableState.Never)]
Invalid = -1,
///
/// Value is PropertyValue.
///
[EditorBrowsable(EditorBrowsableState.Never)]
Property = 0,
///
/// Value is KeyFrames.
///
[EditorBrowsable(EditorBrowsableState.Never)]
KeyFrames,
}
///
/// Create an initialized motion value with invalid.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public MotionValue() : this(Interop.MotionValue.MotionValueNew(), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
///
/// Create an initialized motion value with PropertyValue.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public MotionValue(PropertyValue propertyValue) : this(Interop.MotionValue.MotionValueNewPropertyValue(PropertyValue.getCPtr(propertyValue)), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
///
/// Create an initialized motion value with KeyFrames.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public MotionValue(KeyFrames keyFrames) : this(Interop.MotionValue.MotionValueNewKeyFrames(KeyFrames.getCPtr(keyFrames)), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
///
/// Copy constructor.
///
/// Source object to copy.
[EditorBrowsable(EditorBrowsableState.Never)]
public MotionValue(MotionValue motionValue) : this(Interop.MotionValue.NewMotionValue(MotionValue.getCPtr(motionValue)), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
///
/// Assignment operator.
///
/// Source object to be assigned.
/// Reference to this.
internal MotionValue Assign(MotionValue motionValue)
{
MotionValue ret = new MotionValue(Interop.MotionValue.MotionValueAssign(SwigCPtr, MotionValue.getCPtr(motionValue)), false);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal MotionValue(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
{
}
///
/// Get or set the value as PropertyValue type.
/// If ValueType is ValueType.KeyFrames, it will return last value of stored KeyFrames.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public PropertyValue PropertyValue
{
get
{
return GetPropertyValue();
}
set
{
SetPropertyValue(value);
}
}
///
/// Get or set the value as KeyFrames type.
/// If ValueType is ValueType.PropertyValue, it will create new KeyFrames by stored PropertyValue.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public KeyFrames KeyFramesValue
{
get
{
return GetKeyFrames();
}
set
{
SetKeyFrames(value);
}
}
///
/// Get the type of value what we set.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public ValueType Type
{
get
{
return GetMotionValueType();
}
}
///
/// Invalidate the value what we set.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public void Invalidate()
{
Interop.MotionValue.Clear(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
internal void SetPropertyValue(PropertyValue propertyValue)
{
Interop.MotionValue.SetValuePropertyValue(SwigCPtr, PropertyValue.getCPtr(propertyValue));
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
internal PropertyValue GetPropertyValue()
{
IntPtr cPtr = Interop.MotionValue.GetPropertyValue(SwigCPtr);
PropertyValue ret = new PropertyValue(cPtr, true);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal void SetKeyFrames(KeyFrames keyFrames)
{
Interop.MotionValue.SetValueKeyFrames(SwigCPtr, KeyFrames.getCPtr(keyFrames));
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
internal KeyFrames GetKeyFrames()
{
IntPtr cPtr = Interop.MotionValue.GetKeyFrames(SwigCPtr);
KeyFrames ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as KeyFrames;
if (ret == null)
{
// Register new animation into Registry.
ret = new KeyFrames(cPtr, true);
}
else
{
// We found matched NUI animation. Reduce cPtr reference count.
HandleRef handle = new HandleRef(this, cPtr);
Tizen.NUI.Interop.KeyFrames.DeleteKeyFrames(handle);
handle = new HandleRef(null, IntPtr.Zero);
}
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal ValueType GetMotionValueType()
{
int ret = Interop.MotionValue.GetValueType(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return (ValueType)ret;
}
///
/// Release swigCPtr.
///
// This will be public opened.
[EditorBrowsable(EditorBrowsableState.Never)]
protected override void ReleaseSwigCPtr(global::System.Runtime.InteropServices.HandleRef swigCPtr)
{
Interop.MotionValue.DeleteMotionValue(swigCPtr);
}
}
}