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.
23 /// RelativeVector2 is a two-dimensional vector.
24 /// Both values (x and y) should be between [0, 1].
26 public class RelativeVector2 : global::System.IDisposable
28 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
32 /// <since_tizen> 3 </since_tizen>
33 protected bool swigCMemOwn;
35 internal RelativeVector2(global::System.IntPtr cPtr, bool cMemoryOwn)
37 swigCMemOwn = cMemoryOwn;
38 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
41 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(RelativeVector2 obj)
43 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
46 //A Flag to check who called Dispose(). (By User or DisposeQueue)
47 private bool isDisposeQueued = false;
49 /// A Flat to check if it is already disposed.
51 /// <since_tizen> 3 </since_tizen>
52 protected bool disposed = false;
57 /// <since_tizen> 3 </since_tizen>
62 isDisposeQueued = true;
63 DisposeQueue.Instance.Add(this);
70 /// <since_tizen> 3 </since_tizen>
73 //Throw excpetion if Dispose() is called in separate thread.
74 if (!Window.IsInstalled())
76 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
81 Dispose(DisposeTypes.Implicit);
85 Dispose(DisposeTypes.Explicit);
86 System.GC.SuppressFinalize(this);
93 /// <since_tizen> 3 </since_tizen>
94 protected virtual void Dispose(DisposeTypes type)
101 if(type == DisposeTypes.Explicit)
104 //Release your own managed resources here.
105 //You should release all of your own disposable objects here.
108 //Release your own unmanaged resources here.
109 //You should not access any managed member here except static instance.
110 //because the execution order of Finalizes is non-deterministic.
112 if (swigCPtr.Handle != global::System.IntPtr.Zero)
117 NDalicPINVOKE.delete_Vector2(swigCPtr);
119 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
126 /// The addition operator.
128 /// <param name="arg1">The vector to add.</param>
129 /// <param name="arg2">The vector to add.</param>
130 /// <returns>The vector containing the result of the addition.</returns>
131 /// <since_tizen> 3 </since_tizen>
132 public static RelativeVector2 operator +(RelativeVector2 arg1, RelativeVector2 arg2)
134 RelativeVector2 result = arg1.Add(arg2);
140 /// The subtraction operator.
142 /// <param name="arg1">The vector to subtract.</param>
143 /// <param name="arg2">The vector to subtract.</param>
144 /// <returns>The vector containing the result of the subtraction.</returns>
145 /// <since_tizen> 3 </since_tizen>
146 public static RelativeVector2 operator -(RelativeVector2 arg1, RelativeVector2 arg2)
148 RelativeVector2 result = arg1.Subtract(arg2);
154 /// The multiplication operator.
156 /// <param name="arg1">The vector to multiply.</param>
157 /// <param name="arg2">The vector to multiply.</param>
158 /// <returns>The vector containing the result of the multiplication.</returns>
159 /// <since_tizen> 3 </since_tizen>
160 public static RelativeVector2 operator *(RelativeVector2 arg1, RelativeVector2 arg2)
162 RelativeVector2 result = arg1.Multiply(arg2);
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 RelativeVector2 operator *(RelativeVector2 arg1, float arg2)
176 RelativeVector2 result = arg1.Multiply(arg2);
182 /// The division operator.
184 /// <param name="arg1">The vector to divide.</param>
185 /// <param name="arg2">The vector to divide.</param>
186 /// <returns>The vector containing the result of the division.</returns>
187 /// <since_tizen> 3 </since_tizen>
188 public static RelativeVector2 operator /(RelativeVector2 arg1, RelativeVector2 arg2)
190 RelativeVector2 result = arg1.Divide(arg2);
196 /// The division operator.
198 /// <param name="arg1">The vector to divide.</param>
199 /// <param name="arg2">The float value to scale the vector by.</param>
200 /// <returns>The vector containing the result of the scaling.</returns>
201 /// <since_tizen> 3 </since_tizen>
202 public static RelativeVector2 operator /(RelativeVector2 arg1, float arg2)
204 RelativeVector2 result = arg1.Divide(arg2);
211 /// The const array subscript operator overload. Should be 0, 1.
213 /// <param name="index">The subscript index.</param>
214 /// <returns>The float at the given index.</returns>
215 /// <since_tizen> 3 </since_tizen>
216 public float this[uint index]
220 return ValueOfIndex(index);
226 internal static RelativeVector2 GetRelativeVector2FromPtr(global::System.IntPtr cPtr)
228 RelativeVector2 ret = new RelativeVector2(cPtr, false);
229 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
237 /// <since_tizen> 3 </since_tizen>
238 public RelativeVector2() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
240 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
246 /// <param name="x">The x component.</param>
247 /// <param name="y">The y component.</param>
248 /// <since_tizen> 3 </since_tizen>
249 public RelativeVector2(float x, float y) : this(NDalicPINVOKE.new_Vector2__SWIG_1(x, y), true)
253 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
259 /// <param name="relativeVector3">The RelativeVector3 to create this vector from.</param>
260 /// <since_tizen> 3 </since_tizen>
261 public RelativeVector2(RelativeVector3 relativeVector3) : this(NDalicPINVOKE.new_Vector2__SWIG_3(RelativeVector3.getCPtr(relativeVector3)), true)
263 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
269 /// <param name="relativeVector4">The RelativeVector4 to create this vector from.</param>
270 /// <since_tizen> 3 </since_tizen>
271 public RelativeVector2(RelativeVector4 relativeVector4) : this(NDalicPINVOKE.new_Vector2__SWIG_4(RelativeVector4.getCPtr(relativeVector4)), true)
273 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
277 private RelativeVector2 Add(RelativeVector2 rhs)
279 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Add(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
280 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
284 private RelativeVector2 Subtract(RelativeVector2 rhs)
286 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
287 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
291 private RelativeVector2 Multiply(RelativeVector2 rhs)
293 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
294 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
298 private RelativeVector2 Multiply(float rhs)
300 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, rhs), true);
301 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
305 private RelativeVector2 Divide(RelativeVector2 rhs)
307 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
308 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
312 private RelativeVector2 Divide(float rhs)
314 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, rhs), true);
315 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
319 private float ValueOfIndex(uint index)
321 float ret = NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
322 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
327 /// Compares if the rhs is equal to.
329 /// <param name="rhs">The vector to compare.</param>
330 /// <returns>Returns true if the two vectors are equal, otherwise false.</returns>
331 /// <since_tizen> 3 </since_tizen>
332 public bool EqualTo(RelativeVector2 rhs)
334 bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, RelativeVector2.getCPtr(rhs));
335 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
340 /// Compares if the rhs is not equal to.
342 /// <param name="rhs">The vector to compare.</param>
343 /// <returns>Returns true if the two vectors are not equal, otherwise false.</returns>
344 /// <since_tizen> 3 </since_tizen>
345 public bool NotEqualTo(RelativeVector2 rhs)
347 bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, RelativeVector2.getCPtr(rhs));
348 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
356 /// <since_tizen> 3 </since_tizen>
362 NDalicPINVOKE.Vector2_X_set(swigCPtr, value);
363 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
367 float ret = NDalicPINVOKE.Vector2_X_get(swigCPtr);
368 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
376 /// <since_tizen> 3 </since_tizen>
382 NDalicPINVOKE.Vector2_Y_set(swigCPtr, value);
383 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
387 float ret = NDalicPINVOKE.Vector2_Y_get(swigCPtr);
388 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
395 /// <since_tizen> 3 </since_tizen>
396 public static implicit operator Vector2(RelativeVector2 relativeVector2)
398 return new Vector2(relativeVector2.X, relativeVector2.Y);
403 /// <since_tizen> 3 </since_tizen>
404 public static implicit operator RelativeVector2(Vector2 vec)
408 return new RelativeVector2(vec.X, vec.Y);
411 internal static void ValueCheck(RelativeVector2 relativeVector2)
413 if(relativeVector2.X < 0.0f)
415 relativeVector2.X = 0.0f;
416 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
418 else if(relativeVector2.X > 1.0f)
420 relativeVector2.X = 1.0f;
421 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
423 if(relativeVector2.Y < 0.0f)
425 relativeVector2.Y = 0.0f;
426 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
428 else if(relativeVector2.Y > 1.0f)
430 relativeVector2.Y = 1.0f;
431 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
435 internal static void ValueCheck(float value)
440 Tizen.Log.Fatal("NUI", "The value of Parameters is invalid! Should be between [0, 1].");
442 else if(value > 1.0f)
445 Tizen.Log.Fatal("NUI", "The value of Parameters is invalid! Should be between [0, 1].");