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 /// <since_tizen> 3 </since_tizen>
27 public class RelativeVector2 : global::System.IDisposable
29 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
33 /// <since_tizen> 3 </since_tizen>
34 protected bool swigCMemOwn;
36 internal RelativeVector2(global::System.IntPtr cPtr, bool cMemoryOwn)
38 swigCMemOwn = cMemoryOwn;
39 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
42 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(RelativeVector2 obj)
44 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
47 //A Flag to check who called Dispose(). (By User or DisposeQueue)
48 private bool isDisposeQueued = false;
50 /// A Flat to check if it is already disposed.
52 /// <since_tizen> 3 </since_tizen>
53 protected bool disposed = false;
58 /// <since_tizen> 3 </since_tizen>
63 isDisposeQueued = true;
64 DisposeQueue.Instance.Add(this);
71 /// <since_tizen> 3 </since_tizen>
74 //Throw excpetion if Dispose() is called in separate thread.
75 if (!Window.IsInstalled())
77 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
82 Dispose(DisposeTypes.Implicit);
86 Dispose(DisposeTypes.Explicit);
87 System.GC.SuppressFinalize(this);
94 /// <since_tizen> 3 </since_tizen>
95 protected virtual void Dispose(DisposeTypes type)
102 if(type == DisposeTypes.Explicit)
105 //Release your own managed resources here.
106 //You should release all of your own disposable objects here.
109 //Release your own unmanaged resources here.
110 //You should not access any managed member here except static instance.
111 //because the execution order of Finalizes is non-deterministic.
113 if (swigCPtr.Handle != global::System.IntPtr.Zero)
118 NDalicPINVOKE.delete_Vector2(swigCPtr);
120 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
127 /// The addition operator.
129 /// <param name="arg1">The vector to add.</param>
130 /// <param name="arg2">The vector to add.</param>
131 /// <returns>The vector containing the result of the addition.</returns>
132 /// <since_tizen> 3 </since_tizen>
133 public static RelativeVector2 operator +(RelativeVector2 arg1, RelativeVector2 arg2)
135 RelativeVector2 result = arg1.Add(arg2);
136 return ValueCheck(result);
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);
149 return ValueCheck(result);
153 /// The multiplication operator.
155 /// <param name="arg1">The vector to multiply.</param>
156 /// <param name="arg2">The vector to multiply.</param>
157 /// <returns>The vector containing the result of the multiplication.</returns>
158 /// <since_tizen> 3 </since_tizen>
159 public static RelativeVector2 operator *(RelativeVector2 arg1, RelativeVector2 arg2)
161 RelativeVector2 result = arg1.Multiply(arg2);
162 return ValueCheck(result);
166 /// The multiplication operator.
168 /// <param name="arg1">The vector to multiply.</param>
169 /// <param name="arg2">The float value to scale the vector.</param>
170 /// <returns>The vector containing the result of the scaling.</returns>
171 /// <since_tizen> 3 </since_tizen>
172 public static RelativeVector2 operator *(RelativeVector2 arg1, float arg2)
174 RelativeVector2 result = arg1.Multiply(arg2);
175 return ValueCheck(result);
179 /// The division operator.
181 /// <param name="arg1">The vector to divide.</param>
182 /// <param name="arg2">The vector to divide.</param>
183 /// <returns>The vector containing the result of the division.</returns>
184 /// <since_tizen> 3 </since_tizen>
185 public static RelativeVector2 operator /(RelativeVector2 arg1, RelativeVector2 arg2)
187 RelativeVector2 result = arg1.Divide(arg2);
188 return ValueCheck(result);
192 /// The division operator.
194 /// <param name="arg1">The vector to divide.</param>
195 /// <param name="arg2">The float value to scale the vector by.</param>
196 /// <returns>The vector containing the result of the scaling.</returns>
197 /// <since_tizen> 3 </since_tizen>
198 public static RelativeVector2 operator /(RelativeVector2 arg1, float arg2)
200 RelativeVector2 result = arg1.Divide(arg2);
201 return ValueCheck(result);
206 /// The const array subscript operator overload. Should be 0, 1.
208 /// <param name="index">The subscript index.</param>
209 /// <returns>The float at the given index.</returns>
210 /// <since_tizen> 3 </since_tizen>
211 public float this[uint index]
215 return ValueOfIndex(index);
221 internal static RelativeVector2 GetRelativeVector2FromPtr(global::System.IntPtr cPtr)
223 RelativeVector2 ret = new RelativeVector2(cPtr, false);
224 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
232 /// <since_tizen> 3 </since_tizen>
233 public RelativeVector2() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
235 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
241 /// <param name="x">The x component.</param>
242 /// <param name="y">The y component.</param>
243 /// <since_tizen> 3 </since_tizen>
244 public RelativeVector2(float x, float y) : this(NDalicPINVOKE.new_Vector2__SWIG_1(ValueCheck(x), ValueCheck(y)), true)
246 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
252 /// <param name="relativeVector3">The RelativeVector3 to create this vector from.</param>
253 /// <since_tizen> 3 </since_tizen>
254 public RelativeVector2(RelativeVector3 relativeVector3) : this(NDalicPINVOKE.new_Vector2__SWIG_3(RelativeVector3.getCPtr(relativeVector3)), true)
256 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
262 /// <param name="relativeVector4">The RelativeVector4 to create this vector from.</param>
263 /// <since_tizen> 3 </since_tizen>
264 public RelativeVector2(RelativeVector4 relativeVector4) : this(NDalicPINVOKE.new_Vector2__SWIG_4(RelativeVector4.getCPtr(relativeVector4)), true)
266 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
270 private RelativeVector2 Add(RelativeVector2 rhs)
272 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Add(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
273 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
277 private RelativeVector2 Subtract(RelativeVector2 rhs)
279 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
280 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
284 private RelativeVector2 Multiply(RelativeVector2 rhs)
286 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
287 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
291 private RelativeVector2 Multiply(float rhs)
293 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, rhs), true);
294 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
298 private RelativeVector2 Divide(RelativeVector2 rhs)
300 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
301 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
305 private RelativeVector2 Divide(float rhs)
307 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, rhs), true);
308 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
312 private float ValueOfIndex(uint index)
314 float ret = NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
315 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
320 /// Compares if the rhs is equal to.
322 /// <param name="rhs">The vector to compare.</param>
323 /// <returns>Returns true if the two vectors are equal, otherwise false.</returns>
324 /// <since_tizen> 3 </since_tizen>
325 public bool EqualTo(RelativeVector2 rhs)
327 bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, RelativeVector2.getCPtr(rhs));
328 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
333 /// Compares if the rhs is not equal to.
335 /// <param name="rhs">The vector to compare.</param>
336 /// <returns>Returns true if the two vectors are not equal, otherwise false.</returns>
337 /// <since_tizen> 3 </since_tizen>
338 public bool NotEqualTo(RelativeVector2 rhs)
340 bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, RelativeVector2.getCPtr(rhs));
341 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
349 /// <since_tizen> 3 </since_tizen>
354 NDalicPINVOKE.Vector2_X_set(swigCPtr, ValueCheck(value));
355 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
359 float ret = NDalicPINVOKE.Vector2_X_get(swigCPtr);
360 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
368 /// <since_tizen> 3 </since_tizen>
373 NDalicPINVOKE.Vector2_Y_set(swigCPtr, ValueCheck(value));
374 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
378 float ret = NDalicPINVOKE.Vector2_Y_get(swigCPtr);
379 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
386 /// <since_tizen> 3 </since_tizen>
387 public static implicit operator Vector2(RelativeVector2 relativeVector2)
389 return new Vector2(relativeVector2.X, relativeVector2.Y);
394 /// <since_tizen> 3 </since_tizen>
395 public static implicit operator RelativeVector2(Vector2 vec)
397 return new RelativeVector2(ValueCheck(vec.X), ValueCheck(vec.Y));
400 internal static RelativeVector2 ValueCheck(RelativeVector2 relativeVector2)
402 if(relativeVector2.X < 0.0f)
404 relativeVector2.X = 0.0f;
405 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
407 else if(relativeVector2.X > 1.0f)
409 relativeVector2.X = 1.0f;
410 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
412 if(relativeVector2.Y < 0.0f)
414 relativeVector2.Y = 0.0f;
415 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
417 else if(relativeVector2.Y > 1.0f)
419 relativeVector2.Y = 1.0f;
420 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
422 return relativeVector2;
425 internal static float ValueCheck(float value)
430 NUILog.Error( "The value of Parameters is invalid! Should be between [0, 1].");
432 else if(value > 1.0f)
435 NUILog.Error( "The value of Parameters is invalid! Should be between [0, 1].");