2 * Copyright (c) 2018 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;
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 [TypeConverter(typeof(RelativeVector2TypeConverter))]
28 public class RelativeVector2 : global::System.IDisposable
33 /// <since_tizen> 3 </since_tizen>
34 protected bool swigCMemOwn;
37 /// A Flat to check if it is already disposed.
39 /// <since_tizen> 3 </since_tizen>
40 protected bool disposed = false;
42 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
44 //A Flag to check who called Dispose(). (By User or DisposeQueue)
45 private bool isDisposeQueued = false;
50 /// <since_tizen> 3 </since_tizen>
51 public RelativeVector2() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
53 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
59 /// <param name="x">The x component.</param>
60 /// <param name="y">The y component.</param>
61 /// <since_tizen> 3 </since_tizen>
62 public RelativeVector2(float x, float y) : this(NDalicPINVOKE.new_Vector2__SWIG_1(ValueCheck(x), ValueCheck(y)), true)
64 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
70 /// <param name="relativeVector3">The RelativeVector3 to create this vector from.</param>
71 /// <since_tizen> 3 </since_tizen>
72 public RelativeVector2(RelativeVector3 relativeVector3) : this(NDalicPINVOKE.new_Vector2__SWIG_3(RelativeVector3.getCPtr(relativeVector3)), true)
74 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
80 /// <param name="relativeVector4">The RelativeVector4 to create this vector from.</param>
81 /// <since_tizen> 3 </since_tizen>
82 public RelativeVector2(RelativeVector4 relativeVector4) : this(NDalicPINVOKE.new_Vector2__SWIG_4(RelativeVector4.getCPtr(relativeVector4)), true)
84 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
87 internal RelativeVector2(global::System.IntPtr cPtr, bool cMemoryOwn)
89 swigCMemOwn = cMemoryOwn;
90 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
96 /// <since_tizen> 3 </since_tizen>
101 isDisposeQueued = true;
102 DisposeQueue.Instance.Add(this);
109 /// <since_tizen> 3 </since_tizen>
114 NDalicPINVOKE.Vector2_X_set(swigCPtr, ValueCheck(value));
115 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
119 float ret = NDalicPINVOKE.Vector2_X_get(swigCPtr);
120 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
128 /// <since_tizen> 3 </since_tizen>
133 NDalicPINVOKE.Vector2_Y_set(swigCPtr, ValueCheck(value));
134 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
138 float ret = NDalicPINVOKE.Vector2_Y_get(swigCPtr);
139 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
144 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(RelativeVector2 obj)
146 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
150 /// The addition operator.
152 /// <param name="arg1">The vector to add.</param>
153 /// <param name="arg2">The vector to add.</param>
154 /// <returns>The vector containing the result of the addition.</returns>
155 /// <since_tizen> 3 </since_tizen>
156 public static RelativeVector2 operator +(RelativeVector2 arg1, RelativeVector2 arg2)
158 RelativeVector2 result = arg1.Add(arg2);
159 return ValueCheck(result);
163 /// The subtraction operator.
165 /// <param name="arg1">The vector to subtract.</param>
166 /// <param name="arg2">The vector to subtract.</param>
167 /// <returns>The vector containing the result of the subtraction.</returns>
168 /// <since_tizen> 3 </since_tizen>
169 public static RelativeVector2 operator -(RelativeVector2 arg1, RelativeVector2 arg2)
171 RelativeVector2 result = arg1.Subtract(arg2);
172 return ValueCheck(result);
176 /// The multiplication operator.
178 /// <param name="arg1">The vector to multiply.</param>
179 /// <param name="arg2">The vector to multiply.</param>
180 /// <returns>The vector containing the result of the multiplication.</returns>
181 /// <since_tizen> 3 </since_tizen>
182 public static RelativeVector2 operator *(RelativeVector2 arg1, RelativeVector2 arg2)
184 RelativeVector2 result = arg1.Multiply(arg2);
185 return ValueCheck(result);
189 /// The multiplication operator.
191 /// <param name="arg1">The vector to multiply.</param>
192 /// <param name="arg2">The float value to scale the vector.</param>
193 /// <returns>The vector containing the result of the scaling.</returns>
194 /// <since_tizen> 3 </since_tizen>
195 public static RelativeVector2 operator *(RelativeVector2 arg1, float arg2)
197 RelativeVector2 result = arg1.Multiply(arg2);
198 return ValueCheck(result);
202 /// The division operator.
204 /// <param name="arg1">The vector to divide.</param>
205 /// <param name="arg2">The vector to divide.</param>
206 /// <returns>The vector containing the result of the division.</returns>
207 /// <since_tizen> 3 </since_tizen>
208 public static RelativeVector2 operator /(RelativeVector2 arg1, RelativeVector2 arg2)
210 RelativeVector2 result = arg1.Divide(arg2);
211 return ValueCheck(result);
215 /// The division operator.
217 /// <param name="arg1">The vector to divide.</param>
218 /// <param name="arg2">The float value to scale the vector by.</param>
219 /// <returns>The vector containing the result of the scaling.</returns>
220 /// <since_tizen> 3 </since_tizen>
221 public static RelativeVector2 operator /(RelativeVector2 arg1, float arg2)
223 RelativeVector2 result = arg1.Divide(arg2);
224 return ValueCheck(result);
229 /// <since_tizen> 3 </since_tizen>
230 public static implicit operator Vector2(RelativeVector2 relativeVector2)
232 return new Vector2(relativeVector2.X, relativeVector2.Y);
237 /// <since_tizen> 3 </since_tizen>
238 public static implicit operator RelativeVector2(Vector2 vec)
240 return new RelativeVector2(ValueCheck(vec.X), ValueCheck(vec.Y));
246 /// <since_tizen> 3 </since_tizen>
247 public void Dispose()
249 //Throw excpetion if Dispose() is called in separate thread.
250 if (!Window.IsInstalled())
252 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
257 Dispose(DisposeTypes.Implicit);
261 Dispose(DisposeTypes.Explicit);
262 System.GC.SuppressFinalize(this);
267 /// The const array subscript operator overload. Should be 0, 1.
269 /// <param name="index">The subscript index.</param>
270 /// <returns>The float at the given index.</returns>
271 /// <since_tizen> 3 </since_tizen>
272 public float this[uint index]
276 return ValueOfIndex(index);
281 /// Determines whether the specified object is equal to the current object.
283 /// <param name="obj">The object to compare with the current object.</param>
284 /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
285 public override bool Equals(System.Object obj)
287 RelativeVector2 relativeRector2 = obj as RelativeVector2;
289 if (X == relativeRector2?.X && Y == relativeRector2?.Y)
297 /// Gets the the hash code of this RelativeVector2.
299 /// <returns>The Hash Code.</returns>
300 /// <since_tizen> 5 </since_tizen>
301 public override int GetHashCode()
303 return base.GetHashCode();
307 /// Compares if the rhs is equal to.
309 /// <param name="rhs">The vector to compare.</param>
310 /// <returns>Returns true if the two vectors are equal, otherwise false.</returns>
311 /// <since_tizen> 3 </since_tizen>
312 public bool EqualTo(RelativeVector2 rhs)
314 bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, RelativeVector2.getCPtr(rhs));
315 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
320 /// Compares if the rhs is not equal to.
322 /// <param name="rhs">The vector to compare.</param>
323 /// <returns>Returns true if the two vectors are not equal, otherwise false.</returns>
324 /// <since_tizen> 3 </since_tizen>
325 public bool NotEqualTo(RelativeVector2 rhs)
327 bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, RelativeVector2.getCPtr(rhs));
328 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
334 internal static RelativeVector2 GetRelativeVector2FromPtr(global::System.IntPtr cPtr)
336 RelativeVector2 ret = new RelativeVector2(cPtr, false);
337 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
341 internal static RelativeVector2 ValueCheck(RelativeVector2 relativeVector2)
343 if (relativeVector2.X < 0.0f)
345 relativeVector2.X = 0.0f;
346 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
348 else if (relativeVector2.X > 1.0f)
350 relativeVector2.X = 1.0f;
351 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
353 if (relativeVector2.Y < 0.0f)
355 relativeVector2.Y = 0.0f;
356 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
358 else if (relativeVector2.Y > 1.0f)
360 relativeVector2.Y = 1.0f;
361 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
363 return relativeVector2;
366 internal static float ValueCheck(float value)
371 NUILog.Error("The value of Parameters is invalid! Should be between [0, 1].");
373 else if (value > 1.0f)
376 NUILog.Error("The value of Parameters is invalid! Should be between [0, 1].");
384 /// <since_tizen> 3 </since_tizen>
385 protected virtual void Dispose(DisposeTypes type)
392 if (type == DisposeTypes.Explicit)
395 //Release your own managed resources here.
396 //You should release all of your own disposable objects here.
399 //Release your own unmanaged resources here.
400 //You should not access any managed member here except static instance.
401 //because the execution order of Finalizes is non-deterministic.
403 if (swigCPtr.Handle != global::System.IntPtr.Zero)
408 NDalicPINVOKE.delete_Vector2(swigCPtr);
410 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
415 private RelativeVector2 Add(RelativeVector2 rhs)
417 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Add(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
418 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
422 private RelativeVector2 Subtract(RelativeVector2 rhs)
424 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
425 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
429 private RelativeVector2 Multiply(RelativeVector2 rhs)
431 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
432 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
436 private RelativeVector2 Multiply(float rhs)
438 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, rhs), true);
439 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
443 private RelativeVector2 Divide(RelativeVector2 rhs)
445 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
446 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
450 private RelativeVector2 Divide(float rhs)
452 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, rhs), true);
453 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
457 private float ValueOfIndex(uint index)
459 float ret = NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
460 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();