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 //A Flag to check who called Dispose(). (By User or DisposeQueue)
43 private bool isDisposeQueued = false;
44 //A Flat to check if it is already disposed.
45 protected bool disposed = false;
51 isDisposeQueued = true;
52 DisposeQueue.Instance.Add(this);
58 //Throw excpetion if Dispose() is called in separate thread.
59 if (!Window.IsInstalled())
61 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
66 Dispose(DisposeTypes.Implicit);
70 Dispose(DisposeTypes.Explicit);
71 System.GC.SuppressFinalize(this);
75 protected virtual void Dispose(DisposeTypes type)
82 if(type == DisposeTypes.Explicit)
85 //Release your own managed resources here.
86 //You should release all of your own disposable objects here.
89 //Release your own unmanaged resources here.
90 //You should not access any managed member here except static instance.
91 //because the execution order of Finalizes is non-deterministic.
93 if (swigCPtr.Handle != global::System.IntPtr.Zero)
98 NDalicPINVOKE.delete_Vector2(swigCPtr);
100 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
107 /// Addition operator.
109 /// <param name="arg1">Vector to add</param>
110 /// <param name="arg2">Vector to add</param>
111 /// <returns>A vector containing the result of the addition</returns>
112 public static RelativeVector2 operator +(RelativeVector2 arg1, RelativeVector2 arg2)
114 RelativeVector2 result = arg1.Add(arg2);
120 /// Subtraction operator.
122 /// <param name="arg1">Vector to subtract</param>
123 /// <param name="arg2">Vector to subtract</param>
124 /// <returns>A vector containing the result of the subtraction</returns>
125 public static RelativeVector2 operator -(RelativeVector2 arg1, RelativeVector2 arg2)
127 RelativeVector2 result = arg1.Subtract(arg2);
133 /// Multiplication operator.
135 /// <param name="arg1">The vector to multiply</param>
136 /// <param name="arg2">The vector to multiply</param>
137 /// <returns>A vector containing the result of the multiplication</returns>
138 public static RelativeVector2 operator *(RelativeVector2 arg1, RelativeVector2 arg2)
140 RelativeVector2 result = arg1.Multiply(arg2);
146 /// Multiplication operator.
148 /// <param name="arg1">The vector to multiply</param>
149 /// <param name="arg2">The float value to scale the vector</param>
150 /// <returns>A vector containing the result of the scaling</returns>
151 public static RelativeVector2 operator *(RelativeVector2 arg1, float arg2)
153 RelativeVector2 result = arg1.Multiply(arg2);
159 /// Division operator.
161 /// <param name="arg1">The vector to divide</param>
162 /// <param name="arg2">The vector to divide</param>
163 /// <returns>A vector containing the result of the division</returns>
164 public static RelativeVector2 operator /(RelativeVector2 arg1, RelativeVector2 arg2)
166 RelativeVector2 result = arg1.Divide(arg2);
172 /// Division operator.
174 /// <param name="arg1">The vector to divide</param>
175 /// <param name="arg2">The float value to scale the vector by</param>
176 /// <returns>A vector containing the result of the scaling</returns>
177 public static RelativeVector2 operator /(RelativeVector2 arg1, float arg2)
179 RelativeVector2 result = arg1.Divide(arg2);
186 /// Const array subscript operator overload. Should be 0, 1.
188 /// <param name="index">Subscript index</param>
189 /// <returns>The float at the given index</returns>
190 public float this[uint index]
194 return ValueOfIndex(index);
200 internal static RelativeVector2 GetRelativeVector2FromPtr(global::System.IntPtr cPtr)
202 RelativeVector2 ret = new RelativeVector2(cPtr, false);
203 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
211 public RelativeVector2() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
213 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
219 /// <param name="x">x component</param>
220 /// <param name="y">y component</param>
221 public RelativeVector2(float x, float y) : this(NDalicPINVOKE.new_Vector2__SWIG_1(x, y), true)
225 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
231 /// <param name="relativeVector3">RelativeVector3 to create this vector from</param>
232 public RelativeVector2(RelativeVector3 relativeVector3) : this(NDalicPINVOKE.new_Vector2__SWIG_3(RelativeVector3.getCPtr(relativeVector3)), true)
234 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
240 /// <param name="relativeVector4">RelativeVector4 to create this vector from</param>
241 public RelativeVector2(RelativeVector4 relativeVector4) : this(NDalicPINVOKE.new_Vector2__SWIG_4(RelativeVector4.getCPtr(relativeVector4)), true)
243 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
247 private RelativeVector2 Add(RelativeVector2 rhs)
249 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Add(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
250 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
254 private RelativeVector2 Subtract(RelativeVector2 rhs)
256 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
257 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
261 private RelativeVector2 Multiply(RelativeVector2 rhs)
263 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
264 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
268 private RelativeVector2 Multiply(float rhs)
270 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, rhs), true);
271 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
275 private RelativeVector2 Divide(RelativeVector2 rhs)
277 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
278 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
282 private RelativeVector2 Divide(float rhs)
284 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, rhs), true);
285 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
289 private float ValueOfIndex(uint index)
291 float ret = NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
292 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
297 /// Compare if rhs is equal to
299 /// <param name="rhs">The vector to compare</param>
300 /// <returns>Returns true if the two vectors are equal, otherwise false</returns>
301 public bool EqualTo(RelativeVector2 rhs)
303 bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, RelativeVector2.getCPtr(rhs));
304 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
309 /// Compare if rhs is not equal to
311 /// <param name="rhs">The vector to compare</param>
312 /// <returns>Returns true if the two vectors are not equal, otherwise false</returns>
313 public bool NotEqualTo(RelativeVector2 rhs)
315 bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, RelativeVector2.getCPtr(rhs));
316 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
329 NDalicPINVOKE.Vector2_X_set(swigCPtr, value);
330 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
334 float ret = NDalicPINVOKE.Vector2_X_get(swigCPtr);
335 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
348 NDalicPINVOKE.Vector2_Y_set(swigCPtr, value);
349 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
353 float ret = NDalicPINVOKE.Vector2_Y_get(swigCPtr);
354 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
361 public static implicit operator Vector2(RelativeVector2 relativeVector2)
363 return new Vector2(relativeVector2.X, relativeVector2.Y);
368 public static implicit operator RelativeVector2(Vector2 vec)
372 return new RelativeVector2(vec.X, vec.Y);
375 internal static void ValueCheck(RelativeVector2 relativeVector2)
377 if(relativeVector2.X < 0.0f)
379 relativeVector2.X = 0.0f;
380 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
382 else if(relativeVector2.X > 1.0f)
384 relativeVector2.X = 1.0f;
385 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
387 if(relativeVector2.Y < 0.0f)
389 relativeVector2.Y = 0.0f;
390 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
392 else if(relativeVector2.Y > 1.0f)
394 relativeVector2.Y = 1.0f;
395 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
399 internal static void ValueCheck(float value)
404 Tizen.Log.Fatal("NUI", "The value of Parameters is invalid! Should be between [0, 1].");
406 else if(value > 1.0f)
409 Tizen.Log.Fatal("NUI", "The value of Parameters is invalid! Should be between [0, 1].");