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;
29 protected bool swigCMemOwn;
31 internal RelativeVector2(global::System.IntPtr cPtr, bool cMemoryOwn)
33 swigCMemOwn = cMemoryOwn;
34 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
37 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(RelativeVector2 obj)
39 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
42 //NUI Dispose Pattern written by Jinwoo Nam(jjw.nam)
44 //A Flag to check who called Dispose(). (By User or DisposeQueue)
45 private bool isDisposeQueued = false;
46 //A Flat to check if it is already disposed.
47 protected bool disposed = false;
53 isDisposeQueued = true;
54 DisposeQueue.Instance.Add(this);
60 //Throw excpetion if Dispose() is called in separate thread.
61 if (!Window.IsInstalled())
63 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
68 Dispose(DisposeTypes.Implicit);
72 Dispose(DisposeTypes.Explicit);
73 System.GC.SuppressFinalize(this);
77 protected virtual void Dispose(DisposeTypes type)
84 if(type == DisposeTypes.Explicit)
87 //Release your own managed resources here.
88 //You should release all of your own disposable objects here.
91 //Release your own unmanaged resources here.
92 //You should not access any managed member here except static instance.
93 //because the execution order of Finalizes is non-deterministic.
95 if (swigCPtr.Handle != global::System.IntPtr.Zero)
100 NDalicPINVOKE.delete_Vector2(swigCPtr);
102 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
109 /// Addition operator.
111 /// <param name="arg1">Vector to add</param>
112 /// <param name="arg2">Vector to add</param>
113 /// <returns>A vector containing the result of the addition</returns>
114 public static RelativeVector2 operator +(RelativeVector2 arg1, RelativeVector2 arg2)
116 RelativeVector2 result = arg1.Add(arg2);
122 /// Subtraction operator.
124 /// <param name="arg1">Vector to subtract</param>
125 /// <param name="arg2">Vector to subtract</param>
126 /// <returns>A vector containing the result of the subtraction</returns>
127 public static RelativeVector2 operator -(RelativeVector2 arg1, RelativeVector2 arg2)
129 RelativeVector2 result = arg1.Subtract(arg2);
135 /// Multiplication operator.
137 /// <param name="arg1">The vector to multiply</param>
138 /// <param name="arg2">The vector to multiply</param>
139 /// <returns>A vector containing the result of the multiplication</returns>
140 public static RelativeVector2 operator *(RelativeVector2 arg1, RelativeVector2 arg2)
142 RelativeVector2 result = arg1.Multiply(arg2);
148 /// Multiplication operator.
150 /// <param name="arg1">The vector to multiply</param>
151 /// <param name="arg2">The float value to scale the vector</param>
152 /// <returns>A vector containing the result of the scaling</returns>
153 public static RelativeVector2 operator *(RelativeVector2 arg1, float arg2)
155 RelativeVector2 result = arg1.Multiply(arg2);
161 /// Division operator.
163 /// <param name="arg1">The vector to divide</param>
164 /// <param name="arg2">The vector to divide</param>
165 /// <returns>A vector containing the result of the division</returns>
166 public static RelativeVector2 operator /(RelativeVector2 arg1, RelativeVector2 arg2)
168 RelativeVector2 result = arg1.Divide(arg2);
174 /// Division operator.
176 /// <param name="arg1">The vector to divide</param>
177 /// <param name="arg2">The float value to scale the vector by</param>
178 /// <returns>A vector containing the result of the scaling</returns>
179 public static RelativeVector2 operator /(RelativeVector2 arg1, float arg2)
181 RelativeVector2 result = arg1.Divide(arg2);
188 /// Const array subscript operator overload. Should be 0, 1.
190 /// <param name="index">Subscript index</param>
191 /// <returns>The float at the given index</returns>
192 public float this[uint index]
196 return ValueOfIndex(index);
202 internal static RelativeVector2 GetRelativeVector2FromPtr(global::System.IntPtr cPtr)
204 RelativeVector2 ret = new RelativeVector2(cPtr, false);
205 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
213 public RelativeVector2() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
215 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
221 /// <param name="x">x component</param>
222 /// <param name="y">y component</param>
223 public RelativeVector2(float x, float y) : this(NDalicPINVOKE.new_Vector2__SWIG_1(x, y), true)
227 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
233 /// <param name="relativeVector3">RelativeVector3 to create this vector from</param>
234 public RelativeVector2(RelativeVector3 relativeVector3) : this(NDalicPINVOKE.new_Vector2__SWIG_3(RelativeVector3.getCPtr(relativeVector3)), true)
236 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
242 /// <param name="relativeVector4">RelativeVector4 to create this vector from</param>
243 public RelativeVector2(RelativeVector4 relativeVector4) : this(NDalicPINVOKE.new_Vector2__SWIG_4(RelativeVector4.getCPtr(relativeVector4)), true)
245 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
249 private RelativeVector2 Add(RelativeVector2 rhs)
251 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Add(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
252 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
256 private RelativeVector2 Subtract(RelativeVector2 rhs)
258 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
259 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
263 private RelativeVector2 Multiply(RelativeVector2 rhs)
265 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
266 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
270 private RelativeVector2 Multiply(float rhs)
272 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, rhs), true);
273 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
277 private RelativeVector2 Divide(RelativeVector2 rhs)
279 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
280 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
284 private RelativeVector2 Divide(float rhs)
286 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, rhs), true);
287 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
291 private float ValueOfIndex(uint index)
293 float ret = NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
294 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
299 /// Compare if rhs is equal to
301 /// <param name="rhs">The vector to compare</param>
302 /// <returns>Returns true if the two vectors are equal, otherwise false</returns>
303 public bool EqualTo(RelativeVector2 rhs)
305 bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, RelativeVector2.getCPtr(rhs));
306 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
311 /// Compare if rhs is not equal to
313 /// <param name="rhs">The vector to compare</param>
314 /// <returns>Returns true if the two vectors are not equal, otherwise false</returns>
315 public bool NotEqualTo(RelativeVector2 rhs)
317 bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, RelativeVector2.getCPtr(rhs));
318 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
331 NDalicPINVOKE.Vector2_X_set(swigCPtr, value);
332 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
336 float ret = NDalicPINVOKE.Vector2_X_get(swigCPtr);
337 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
350 NDalicPINVOKE.Vector2_Y_set(swigCPtr, value);
351 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
355 float ret = NDalicPINVOKE.Vector2_Y_get(swigCPtr);
356 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
363 public static implicit operator Vector2(RelativeVector2 relativeVector2)
365 return new Vector2(relativeVector2.X, relativeVector2.Y);
370 public static implicit operator RelativeVector2(Vector2 vec)
374 return new RelativeVector2(vec.X, vec.Y);
377 internal static void ValueCheck(RelativeVector2 relativeVector2)
379 if(relativeVector2.X < 0.0f)
381 relativeVector2.X = 0.0f;
382 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
384 else if(relativeVector2.X > 1.0f)
386 relativeVector2.X = 1.0f;
387 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
389 if(relativeVector2.Y < 0.0f)
391 relativeVector2.Y = 0.0f;
392 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
394 else if(relativeVector2.Y > 1.0f)
396 relativeVector2.Y = 1.0f;
397 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
401 internal static void ValueCheck(float value)
406 Tizen.Log.Fatal("NUI", "The value of Parameters is invalid! Should be between [0, 1].");
408 else if(value > 1.0f)
411 Tizen.Log.Fatal("NUI", "The value of Parameters is invalid! Should be between [0, 1].");