2 * Copyright (c) 2017 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.
18 using Tizen.NUI.Binding;
24 /// RelativeVector4 is a four-dimensional vector.
25 /// All values (x, y, and z) should be between [0, 1].
27 /// <since_tizen> 3 </since_tizen>
28 [TypeConverter(typeof(RelativeVector4TypeConverter))]
29 public class RelativeVector4 : global::System.IDisposable
31 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
35 /// <since_tizen> 3 </since_tizen>
36 protected bool swigCMemOwn;
38 internal RelativeVector4(global::System.IntPtr cPtr, bool cMemoryOwn)
40 swigCMemOwn = cMemoryOwn;
41 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
44 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(RelativeVector4 obj)
46 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
49 //A Flag to check who called Dispose(). (By User or DisposeQueue)
50 private bool isDisposeQueued = false;
52 /// A Flat to check if it is already disposed.
54 /// <since_tizen> 3 </since_tizen>
55 protected bool disposed = false;
60 /// <since_tizen> 3 </since_tizen>
65 isDisposeQueued = true;
66 DisposeQueue.Instance.Add(this);
73 /// <since_tizen> 3 </since_tizen>
76 //Throw excpetion if Dispose() is called in separate thread.
77 if (!Window.IsInstalled())
79 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
84 Dispose(DisposeTypes.Implicit);
88 Dispose(DisposeTypes.Explicit);
89 System.GC.SuppressFinalize(this);
96 /// <since_tizen> 3 </since_tizen>
97 protected virtual void Dispose(DisposeTypes type)
104 if(type == DisposeTypes.Explicit)
107 //Release your own managed resources here.
108 //You should release all of your own disposable objects here.
111 //Release your own unmanaged resources here.
112 //You should not access any managed member here except static instance.
113 //because the execution order of Finalizes is non-deterministic.
115 if (swigCPtr.Handle != global::System.IntPtr.Zero)
120 NDalicPINVOKE.delete_Vector4(swigCPtr);
122 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
129 /// The addition operator.
131 /// <param name="arg1">The vector to add.</param>
132 /// <param name="arg2">The vector to add.</param>
133 /// <returns>The vector containing the result of the addition.</returns>
134 /// <since_tizen> 3 </since_tizen>
135 public static RelativeVector4 operator +(RelativeVector4 arg1, RelativeVector4 arg2)
137 RelativeVector4 result = arg1.Add(arg2);
138 return ValueCheck(result);
142 /// The subtraction operator.
144 /// <param name="arg1">The vector to subtract.</param>
145 /// <param name="arg2">The vector to subtract.</param>
146 /// <returns>The vector containing the result of the subtraction.</returns>
147 /// <since_tizen> 3 </since_tizen>
148 public static RelativeVector4 operator -(RelativeVector4 arg1, RelativeVector4 arg2)
150 RelativeVector4 result = arg1.Subtract(arg2);
151 return ValueCheck(result);
155 /// The multiplication operator.
157 /// <param name="arg1">The vector to multiply.</param>
158 /// <param name="arg2">The vector to multiply.</param>
159 /// <returns>The vector containing the result of the multiplication.</returns>
160 /// <since_tizen> 3 </since_tizen>
161 public static RelativeVector4 operator *(RelativeVector4 arg1, RelativeVector4 arg2)
163 RelativeVector4 result = arg1.Multiply(arg2);
164 return ValueCheck(result);
168 /// The multiplication operator.
170 /// <param name="arg1">The vector to multiply.</param>
171 /// <param name="arg2">The float value to scale the vector.</param>
172 /// <returns>The vector containing the result of the scaling.</returns>
173 /// <since_tizen> 3 </since_tizen>
174 public static RelativeVector4 operator *(RelativeVector4 arg1, float arg2)
176 RelativeVector4 result = arg1.Multiply(arg2);
177 return ValueCheck(result);
181 /// The division operator.
183 /// <param name="arg1">The vector to divide.</param>
184 /// <param name="arg2">The vector to divide.</param>
185 /// <returns>The vector containing the result of the division.</returns>
186 /// <since_tizen> 3 </since_tizen>
187 public static RelativeVector4 operator /(RelativeVector4 arg1, RelativeVector4 arg2)
189 RelativeVector4 result = arg1.Divide(arg2);
190 return ValueCheck(result);
194 /// The division operator.
196 /// <param name="arg1">The vector to divide.</param>
197 /// <param name="arg2">The float value to scale the vector by.</param>
198 /// <returns>The vector containing the result of the scaling.</returns>
199 /// <since_tizen> 3 </since_tizen>
200 public static RelativeVector4 operator /(RelativeVector4 arg1, float arg2)
202 RelativeVector4 result = arg1.Divide(arg2);
203 return ValueCheck(result);
208 /// The const array subscript operator overload. Should be 0, 1 3 or 3.
210 /// <param name="index">The subscript index.</param>
211 /// <returns>The float at the given index.</returns>
212 /// <since_tizen> 3 </since_tizen>
213 public float this[uint index]
217 return ValueOfIndex(index);
223 internal static RelativeVector4 GetRelativeVector4FromPtr(global::System.IntPtr cPtr)
225 RelativeVector4 ret = new RelativeVector4(cPtr, false);
226 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
234 /// <since_tizen> 3 </since_tizen>
235 public RelativeVector4() : this(NDalicPINVOKE.new_Vector4__SWIG_0(), true)
237 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
243 /// <param name="x">The x component.</param>
244 /// <param name="y">The y component.</param>
245 /// <param name="z">The z component.</param>
246 /// <param name="w">The w component.</param>
247 /// <since_tizen> 3 </since_tizen>
248 public RelativeVector4(float x, float y, float z, float w) : this(NDalicPINVOKE.new_Vector4__SWIG_1(ValueCheck(x), ValueCheck(y),ValueCheck(z), ValueCheck(w)), true)
250 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
256 /// <param name="relativeVector2">The RelativeVector2 to create this vector from.</param>
257 /// <since_tizen> 3 </since_tizen>
258 public RelativeVector4(RelativeVector2 relativeVector2) : this(NDalicPINVOKE.new_Vector4__SWIG_3(RelativeVector2.getCPtr(relativeVector2)), true)
260 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
266 /// <param name="relativeVector3">The RelativeVector3 to create this vector from.</param>
267 /// <since_tizen> 3 </since_tizen>
268 public RelativeVector4(RelativeVector3 relativeVector3) : this(NDalicPINVOKE.new_Vector4__SWIG_4(RelativeVector3.getCPtr(relativeVector3)), true)
270 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
273 private RelativeVector4 Add(RelativeVector4 rhs)
275 RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Add(swigCPtr, RelativeVector4.getCPtr(rhs)), true);
276 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
280 private RelativeVector4 Subtract(RelativeVector4 rhs)
282 RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Subtract__SWIG_0(swigCPtr, RelativeVector4.getCPtr(rhs)), true);
283 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
287 private RelativeVector4 Multiply(RelativeVector4 rhs)
289 RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Multiply__SWIG_0(swigCPtr, RelativeVector4.getCPtr(rhs)), true);
290 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
294 private RelativeVector4 Multiply(float rhs)
296 RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Multiply__SWIG_1(swigCPtr, rhs), true);
297 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
301 private RelativeVector4 Divide(RelativeVector4 rhs)
303 RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Divide__SWIG_0(swigCPtr, RelativeVector4.getCPtr(rhs)), true);
304 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
308 private RelativeVector4 Divide(float rhs)
310 RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Divide__SWIG_1(swigCPtr, rhs), true);
311 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
315 private float ValueOfIndex(uint index)
317 float ret = NDalicPINVOKE.Vector4_ValueOfIndex__SWIG_0(swigCPtr, index);
318 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
323 /// Compares if the rhs is equal to.
325 /// <param name="rhs">The vector to compare.</param>
326 /// <returns>Returns true if the two vectors are equal, otherwise false.</returns>
327 /// <since_tizen> 3 </since_tizen>
328 public bool EqualTo(RelativeVector4 rhs)
330 bool ret = NDalicPINVOKE.Vector4_EqualTo(swigCPtr, RelativeVector4.getCPtr(rhs));
331 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
336 /// Compares if the rhs is not equal to.
338 /// <param name="rhs">The vector to compare.</param>
339 /// <returns>Returns true if the two vectors are not equal, otherwise false.</returns>
340 /// <since_tizen> 3 </since_tizen>
341 public bool NotEqualTo(RelativeVector4 rhs)
343 bool ret = NDalicPINVOKE.Vector4_NotEqualTo(swigCPtr, RelativeVector4.getCPtr(rhs));
344 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
352 /// <since_tizen> 3 </since_tizen>
357 NDalicPINVOKE.Vector4_X_set(swigCPtr, ValueCheck(value));
358 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
362 float ret = NDalicPINVOKE.Vector4_X_get(swigCPtr);
363 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
371 /// <since_tizen> 3 </since_tizen>
376 NDalicPINVOKE.Vector4_Y_set(swigCPtr, ValueCheck(value));
377 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
381 float ret = NDalicPINVOKE.Vector4_Y_get(swigCPtr);
382 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
390 /// <since_tizen> 3 </since_tizen>
395 NDalicPINVOKE.Vector4_Z_set(swigCPtr, ValueCheck(value));
396 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
400 float ret = NDalicPINVOKE.Vector4_Z_get(swigCPtr);
401 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
409 /// <since_tizen> 3 </since_tizen>
414 NDalicPINVOKE.Vector4_W_set(swigCPtr, ValueCheck(value));
415 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
419 float ret = NDalicPINVOKE.Vector4_W_get(swigCPtr);
420 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
427 /// <since_tizen> 3 </since_tizen>
428 public static implicit operator Vector4(RelativeVector4 relativeVector4)
430 return new Vector4(relativeVector4.X, relativeVector4.Y, relativeVector4.Z, relativeVector4.W);
435 /// <since_tizen> 3 </since_tizen>
436 public static implicit operator RelativeVector4(Vector4 vec)
438 return new RelativeVector4(ValueCheck(vec.X), ValueCheck(vec.Y), ValueCheck(vec.Z), ValueCheck(vec.W));
441 internal static RelativeVector4 ValueCheck(RelativeVector4 relativeVector4)
443 if(relativeVector4.X < 0.0f)
445 relativeVector4.X = 0.0f;
446 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
448 else if(relativeVector4.X > 1.0f)
450 relativeVector4.X = 1.0f;
451 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
453 if(relativeVector4.Y < 0.0f)
455 relativeVector4.Y = 0.0f;
456 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
458 else if(relativeVector4.Y > 1.0f)
460 relativeVector4.Y = 1.0f;
461 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
463 if(relativeVector4.Z < 0.0f)
465 relativeVector4.Z = 0.0f;
466 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
468 else if(relativeVector4.Z > 1.0f)
470 relativeVector4.Z = 1.0f;
471 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
473 if(relativeVector4.W < 0.0f)
475 relativeVector4.W = 0.0f;
476 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
478 else if(relativeVector4.W > 1.0f)
480 relativeVector4.W = 1.0f;
481 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
483 return relativeVector4;
486 internal static float ValueCheck(float value)
491 NUILog.Error( "The value of Parameters is invalid! Should be between [0, 1].");
493 else if(value > 1.0f)
496 NUILog.Error( "The value of Parameters is invalid! Should be between [0, 1].");