2 * Copyright(c) 2023 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using System.Runtime.InteropServices;
20 using System.ComponentModel;
21 using System.Collections.Generic;
24 namespace Tizen.NUI.Scene3D
27 /// This MotionValue be used for target value of each <see cref="MotionIndex"/>.
28 /// We can get and set MotionValue as 2 types : PropertyValue and KeyFrames.
30 /// Each types will be cross-converted internally.
31 /// For example, when we set PropertyValue, we can get KeyFrames with 2 frames, and target value is set.
34 /// The type of property should be matched with MotionIndex required.
36 [EditorBrowsable(EditorBrowsableState.Never)]
37 public class MotionValue : BaseHandle
40 /// Determine whether current stored value is PropertyValue, or KeyFrames.
42 [EditorBrowsable(EditorBrowsableState.Never)]
46 /// Value is null, or invalid class.
48 [EditorBrowsable(EditorBrowsableState.Never)]
52 /// Value is PropertyValue.
54 [EditorBrowsable(EditorBrowsableState.Never)]
58 /// Value is KeyFrames.
60 [EditorBrowsable(EditorBrowsableState.Never)]
65 /// Create an initialized motion value with invalid.
67 [EditorBrowsable(EditorBrowsableState.Never)]
68 public MotionValue() : this(Interop.MotionValue.MotionValueNew(), true)
70 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
74 /// Create an initialized motion value with PropertyValue.
76 [EditorBrowsable(EditorBrowsableState.Never)]
77 public MotionValue(PropertyValue propertyValue) : this(Interop.MotionValue.MotionValueNewPropertyValue(PropertyValue.getCPtr(propertyValue)), true)
79 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
83 /// Create an initialized motion value with KeyFrames.
85 [EditorBrowsable(EditorBrowsableState.Never)]
86 public MotionValue(KeyFrames keyFrames) : this(Interop.MotionValue.MotionValueNewKeyFrames(KeyFrames.getCPtr(keyFrames)), true)
88 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
94 /// <param name="motionValue">Source object to copy.</param>
95 [EditorBrowsable(EditorBrowsableState.Never)]
96 public MotionValue(MotionValue motionValue) : this(Interop.MotionValue.NewMotionValue(MotionValue.getCPtr(motionValue)), true)
98 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
102 /// Assignment operator.
104 /// <param name="motionValue">Source object to be assigned.</param>
105 /// <returns>Reference to this.</returns>
106 internal MotionValue Assign(MotionValue motionValue)
108 MotionValue ret = new MotionValue(Interop.MotionValue.MotionValueAssign(SwigCPtr, MotionValue.getCPtr(motionValue)), false);
109 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
113 internal MotionValue(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
119 /// Get or set the value as PropertyValue type.
120 /// If ValueType is ValueType.KeyFrames, it will return last value of stored KeyFrames.
122 [EditorBrowsable(EditorBrowsableState.Never)]
123 public PropertyValue PropertyValue
127 return GetPropertyValue();
131 SetPropertyValue(value);
136 /// Get or set the value as KeyFrames type.
137 /// If ValueType is ValueType.PropertyValue, it will create new KeyFrames by stored PropertyValue.
139 [EditorBrowsable(EditorBrowsableState.Never)]
140 public KeyFrames KeyFramesValue
144 return GetKeyFrames();
153 /// Get the type of value what we set.
155 [EditorBrowsable(EditorBrowsableState.Never)]
156 public ValueType Type
160 return GetMotionValueType();
165 /// Invalidate the value what we set.
167 [EditorBrowsable(EditorBrowsableState.Never)]
168 public void Invalidate()
170 Interop.MotionValue.Clear(SwigCPtr);
171 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
174 internal void SetPropertyValue(PropertyValue propertyValue)
176 Interop.MotionValue.SetValuePropertyValue(SwigCPtr, PropertyValue.getCPtr(propertyValue));
177 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
180 internal PropertyValue GetPropertyValue()
182 IntPtr cPtr = Interop.MotionValue.GetPropertyValue(SwigCPtr);
183 PropertyValue ret = new PropertyValue(cPtr, true);
184 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
187 internal void SetKeyFrames(KeyFrames keyFrames)
189 Interop.MotionValue.SetValueKeyFrames(SwigCPtr, KeyFrames.getCPtr(keyFrames));
190 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
193 internal KeyFrames GetKeyFrames()
195 IntPtr cPtr = Interop.MotionValue.GetKeyFrames(SwigCPtr);
196 KeyFrames ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as KeyFrames;
199 // Register new animation into Registry.
200 ret = new KeyFrames(cPtr, true);
204 // We found matched NUI animation. Reduce cPtr reference count.
205 HandleRef handle = new HandleRef(this, cPtr);
206 Tizen.NUI.Interop.KeyFrames.DeleteKeyFrames(handle);
207 handle = new HandleRef(null, IntPtr.Zero);
209 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
213 internal ValueType GetMotionValueType()
215 int ret = Interop.MotionValue.GetValueType(SwigCPtr);
216 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
217 return (ValueType)ret;
221 /// Release swigCPtr.
223 // This will be public opened.
224 [EditorBrowsable(EditorBrowsableState.Never)]
225 protected override void ReleaseSwigCPtr(global::System.Runtime.InteropServices.HandleRef swigCPtr)
227 Interop.MotionValue.DeleteMotionValue(swigCPtr);