/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
*/
using System;
+ using Tizen.NUI.Binding;
namespace Tizen.NUI
{
-
/// <summary>
- /// RelativeVector2 is a two dimensional vector.
- /// Both values(x and y) should be between [0, 1].
+ /// RelativeVector2 is a two-dimensional vector.
+ /// Both values (x and y) should be between [0, 1].
/// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ [TypeConverter(typeof(RelativeVector2TypeConverter))]
public class RelativeVector2 : global::System.IDisposable
{
- private global::System.Runtime.InteropServices.HandleRef swigCPtr;
+ /// <summary>
+ /// swigCMemOwn
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
protected bool swigCMemOwn;
+ /// <summary>
+ /// A Flat to check if it is already disposed.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ protected bool disposed = false;
+
+ private global::System.Runtime.InteropServices.HandleRef swigCPtr;
+
+ //A Flag to check who called Dispose(). (By User or DisposeQueue)
+ private bool isDisposeQueued = false;
+
+ /// <summary>
+ /// The constructor.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public RelativeVector2() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
+ {
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ }
+
+ /// <summary>
+ /// The constructor.
+ /// </summary>
+ /// <param name="x">The x component.</param>
+ /// <param name="y">The y component.</param>
+ /// <since_tizen> 3 </since_tizen>
+ public RelativeVector2(float x, float y) : this(NDalicPINVOKE.new_Vector2__SWIG_1(ValueCheck(x), ValueCheck(y)), true)
+ {
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ }
+
+ /// <summary>
+ /// The constructor.
+ /// </summary>
+ /// <param name="relativeVector3">The RelativeVector3 to create this vector from.</param>
+ /// <since_tizen> 3 </since_tizen>
+ public RelativeVector2(RelativeVector3 relativeVector3) : this(NDalicPINVOKE.new_Vector2__SWIG_3(RelativeVector3.getCPtr(relativeVector3)), true)
+ {
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ }
+
+ /// <summary>
+ /// The constructor.
+ /// </summary>
+ /// <param name="relativeVector4">The RelativeVector4 to create this vector from.</param>
+ /// <since_tizen> 3 </since_tizen>
+ public RelativeVector2(RelativeVector4 relativeVector4) : this(NDalicPINVOKE.new_Vector2__SWIG_4(RelativeVector4.getCPtr(relativeVector4)), true)
+ {
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ }
+
internal RelativeVector2(global::System.IntPtr cPtr, bool cMemoryOwn)
{
swigCMemOwn = cMemoryOwn;
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
}
- internal static global::System.Runtime.InteropServices.HandleRef getCPtr(RelativeVector2 obj)
+ /// <summary>
+ /// Dispose.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ ~RelativeVector2()
{
- return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
+ if (!isDisposeQueued)
+ {
+ isDisposeQueued = true;
+ DisposeQueue.Instance.Add(this);
+ }
}
- ~RelativeVector2()
+ /// <summary>
+ /// The x component.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public float X
{
- DisposeQueue.Instance.Add(this);
+ set
+ {
+ NDalicPINVOKE.Vector2_X_set(swigCPtr, ValueCheck(value));
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ }
+ get
+ {
+ float ret = NDalicPINVOKE.Vector2_X_get(swigCPtr);
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ return ret;
+ }
}
- public virtual void Dispose()
+ /// <summary>
+ /// The y component.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public float Y
{
- if (!Stage.IsInstalled())
+ set
{
- DisposeQueue.Instance.Add(this);
- return;
+ NDalicPINVOKE.Vector2_Y_set(swigCPtr, ValueCheck(value));
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
-
- lock (this)
+ get
{
- if (swigCPtr.Handle != global::System.IntPtr.Zero)
- {
- if (swigCMemOwn)
- {
- swigCMemOwn = false;
- NDalicPINVOKE.delete_Vector2(swigCPtr);
- }
- swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
- }
- global::System.GC.SuppressFinalize(this);
+ float ret = NDalicPINVOKE.Vector2_Y_get(swigCPtr);
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ return ret;
}
}
+ internal static global::System.Runtime.InteropServices.HandleRef getCPtr(RelativeVector2 obj)
+ {
+ return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
+ }
/// <summary>
- /// Addition operator.
+ /// The addition operator.
/// </summary>
- /// <param name="arg1">Vector to add</param>
- /// <param name="arg2">Vector to add</param>
- /// <returns>A vector containing the result of the addition</returns>
+ /// <param name="arg1">The vector to add.</param>
+ /// <param name="arg2">The vector to add.</param>
+ /// <returns>The vector containing the result of the addition.</returns>
+ /// <since_tizen> 3 </since_tizen>
public static RelativeVector2 operator +(RelativeVector2 arg1, RelativeVector2 arg2)
{
RelativeVector2 result = arg1.Add(arg2);
- ValueCheck(result);
- return result;
+ return ValueCheck(result);
}
/// <summary>
- /// Subtraction operator.
+ /// The subtraction operator.
/// </summary>
- /// <param name="arg1">Vector to subtract</param>
- /// <param name="arg2">Vector to subtract</param>
- /// <returns>A vector containing the result of the subtraction</returns>
+ /// <param name="arg1">The vector to subtract.</param>
+ /// <param name="arg2">The vector to subtract.</param>
+ /// <returns>The vector containing the result of the subtraction.</returns>
+ /// <since_tizen> 3 </since_tizen>
public static RelativeVector2 operator -(RelativeVector2 arg1, RelativeVector2 arg2)
{
RelativeVector2 result = arg1.Subtract(arg2);
- ValueCheck(result);
- return result;
+ return ValueCheck(result);
}
/// <summary>
- /// Multiplication operator.
+ /// The multiplication operator.
/// </summary>
- /// <param name="arg1">The vector to multiply</param>
- /// <param name="arg2">The vector to multiply</param>
- /// <returns>A vector containing the result of the multiplication</returns>
+ /// <param name="arg1">The vector to multiply.</param>
+ /// <param name="arg2">The vector to multiply.</param>
+ /// <returns>The vector containing the result of the multiplication.</returns>
+ /// <since_tizen> 3 </since_tizen>
public static RelativeVector2 operator *(RelativeVector2 arg1, RelativeVector2 arg2)
{
RelativeVector2 result = arg1.Multiply(arg2);
- ValueCheck(result);
- return result;
+ return ValueCheck(result);
}
/// <summary>
- /// Multiplication operator.
+ /// The multiplication operator.
/// </summary>
- /// <param name="arg1">The vector to multiply</param>
- /// <param name="arg2">The float value to scale the vector</param>
- /// <returns>A vector containing the result of the scaling</returns>
+ /// <param name="arg1">The vector to multiply.</param>
+ /// <param name="arg2">The float value to scale the vector.</param>
+ /// <returns>The vector containing the result of the scaling.</returns>
+ /// <since_tizen> 3 </since_tizen>
public static RelativeVector2 operator *(RelativeVector2 arg1, float arg2)
{
RelativeVector2 result = arg1.Multiply(arg2);
- ValueCheck(result);
- return result;
+ return ValueCheck(result);
}
/// <summary>
- /// Division operator.
+ /// The division operator.
/// </summary>
- /// <param name="arg1">The vector to divide</param>
- /// <param name="arg2">The vector to divide</param>
- /// <returns>A vector containing the result of the division</returns>
+ /// <param name="arg1">The vector to divide.</param>
+ /// <param name="arg2">The vector to divide.</param>
+ /// <returns>The vector containing the result of the division.</returns>
+ /// <since_tizen> 3 </since_tizen>
public static RelativeVector2 operator /(RelativeVector2 arg1, RelativeVector2 arg2)
{
RelativeVector2 result = arg1.Divide(arg2);
- ValueCheck(result);
- return result;
+ return ValueCheck(result);
}
/// <summary>
- /// Division operator.
+ /// The division operator.
/// </summary>
- /// <param name="arg1">The vector to divide</param>
- /// <param name="arg2">The float value to scale the vector by</param>
- /// <returns>A vector containing the result of the scaling</returns>
+ /// <param name="arg1">The vector to divide.</param>
+ /// <param name="arg2">The float value to scale the vector by.</param>
+ /// <returns>The vector containing the result of the scaling.</returns>
+ /// <since_tizen> 3 </since_tizen>
public static RelativeVector2 operator /(RelativeVector2 arg1, float arg2)
{
RelativeVector2 result = arg1.Divide(arg2);
- ValueCheck(result);
- return result;
+ return ValueCheck(result);
}
+ /// <summary>
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public static implicit operator Vector2(RelativeVector2 relativeVector2)
+ {
+ return new Vector2(relativeVector2.X, relativeVector2.Y);
+ }
+
+ /// <summary>
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public static implicit operator RelativeVector2(Vector2 vec)
+ {
+ return new RelativeVector2(ValueCheck(vec.X), ValueCheck(vec.Y));
+ }
+
+ /// <summary>
+ /// Dispose.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public void Dispose()
+ {
+ //Throw excpetion if Dispose() is called in separate thread.
+ if (!Window.IsInstalled())
+ {
+ throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
+ }
+
+ if (isDisposeQueued)
+ {
+ Dispose(DisposeTypes.Implicit);
+ }
+ else
+ {
+ Dispose(DisposeTypes.Explicit);
+ System.GC.SuppressFinalize(this);
+ }
+ }
/// <summary>
- /// Const array subscript operator overload. Should be 0, 1.
+ /// The const array subscript operator overload. Should be 0, 1.
/// </summary>
- /// <param name="index">Subscript index</param>
- /// <returns>The float at the given index</returns>
+ /// <param name="index">The subscript index.</param>
+ /// <returns>The float at the given index.</returns>
+ /// <since_tizen> 3 </since_tizen>
public float this[uint index]
{
get
}
/// <summary>
+ /// Determines whether the specified object is equal to the current object.
/// </summary>
- internal static RelativeVector2 GetRelativeVector2FromPtr(global::System.IntPtr cPtr)
+ /// <param name="obj">The object to compare with the current object.</param>
+ /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
+ public override bool Equals(System.Object obj)
{
- RelativeVector2 ret = new RelativeVector2(cPtr, false);
- if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
- return ret;
+ RelativeVector2 relativeRector2 = obj as RelativeVector2;
+ bool equal = false;
+ if (X == relativeRector2?.X && Y == relativeRector2?.Y)
+ {
+ equal = true;
+ }
+ return equal;
}
-
/// <summary>
- /// Constructor
+ /// Gets the the hash code of this RelativeVector2.
/// </summary>
- public RelativeVector2() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
+ /// <returns>The Hash Code.</returns>
+ /// <since_tizen> 6 </since_tizen>
+ public override int GetHashCode()
{
- if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ return swigCPtr.Handle.GetHashCode();
}
/// <summary>
- /// Constructor
+ /// Compares if the rhs is equal to.
/// </summary>
- /// <param name="x">x component</param>
- /// <param name="y">y component</param>
- public RelativeVector2(float x, float y) : this(NDalicPINVOKE.new_Vector2__SWIG_1(x, y), true)
+ /// <param name="rhs">The vector to compare.</param>
+ /// <returns>Returns true if the two vectors are equal, otherwise false.</returns>
+ /// <since_tizen> 3 </since_tizen>
+ public bool EqualTo(RelativeVector2 rhs)
{
- ValueCheck(x);
- ValueCheck(y);
+ bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, RelativeVector2.getCPtr(rhs));
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ return ret;
}
/// <summary>
- /// Constructor
+ /// Compares if the rhs is not equal to.
/// </summary>
- /// <param name="relativeVector3">RelativeVector3 to create this vector from</param>
- public RelativeVector2(RelativeVector3 relativeVector3) : this(NDalicPINVOKE.new_Vector2__SWIG_3(RelativeVector3.getCPtr(relativeVector3)), true)
+ /// <param name="rhs">The vector to compare.</param>
+ /// <returns>Returns true if the two vectors are not equal, otherwise false.</returns>
+ /// <since_tizen> 3 </since_tizen>
+ public bool NotEqualTo(RelativeVector2 rhs)
{
+ bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, RelativeVector2.getCPtr(rhs));
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ return ret;
}
/// <summary>
- /// Constructor
/// </summary>
- /// <param name="relativeVector4">RelativeVector4 to create this vector from</param>
- public RelativeVector2(RelativeVector4 relativeVector4) : this(NDalicPINVOKE.new_Vector2__SWIG_4(RelativeVector4.getCPtr(relativeVector4)), true)
+ internal static RelativeVector2 GetRelativeVector2FromPtr(global::System.IntPtr cPtr)
{
+ RelativeVector2 ret = new RelativeVector2(cPtr, false);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ return ret;
+ }
+
+ internal static RelativeVector2 ValueCheck(RelativeVector2 relativeVector2)
+ {
+ if (relativeVector2.X < 0.0f)
+ {
+ relativeVector2.X = 0.0f;
+ NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
+ }
+ else if (relativeVector2.X > 1.0f)
+ {
+ relativeVector2.X = 1.0f;
+ NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
+ }
+ if (relativeVector2.Y < 0.0f)
+ {
+ relativeVector2.Y = 0.0f;
+ NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
+ }
+ else if (relativeVector2.Y > 1.0f)
+ {
+ relativeVector2.Y = 1.0f;
+ NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
+ }
+ return relativeVector2;
+ }
+
+ internal static float ValueCheck(float value)
+ {
+ if (value < 0.0f)
+ {
+ value = 0.0f;
+ NUILog.Error("The value of Parameters is invalid! Should be between [0, 1].");
+ }
+ else if (value > 1.0f)
+ {
+ value = 1.0f;
+ NUILog.Error("The value of Parameters is invalid! Should be between [0, 1].");
+ }
+ return value;
}
+ /// <summary>
+ /// Dispose.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ protected virtual void Dispose(DisposeTypes type)
+ {
+ if (disposed)
+ {
+ return;
+ }
+
+ if (type == DisposeTypes.Explicit)
+ {
+ //Called by User
+ //Release your own managed resources here.
+ //You should release all of your own disposable objects here.
+ }
+
+ //Release your own unmanaged resources here.
+ //You should not access any managed member here except static instance.
+ //because the execution order of Finalizes is non-deterministic.
+
+ if (swigCPtr.Handle != global::System.IntPtr.Zero)
+ {
+ if (swigCMemOwn)
+ {
+ swigCMemOwn = false;
+ NDalicPINVOKE.delete_Vector2(swigCPtr);
+ }
+ swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+ }
+ disposed = true;
+ }
private RelativeVector2 Add(RelativeVector2 rhs)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
-
- /// <summary>
- /// Compare if rhs is equal to
- /// </summary>
- /// <param name="rhs">The vector to compare</param>
- /// <returns>Returns true if the two vectors are equal, otherwise false</returns>
- public bool EqualTo(RelativeVector2 rhs)
- {
- bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, RelativeVector2.getCPtr(rhs));
- if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
- return ret;
- }
-
- /// <summary>
- /// Compare if rhs is not equal to
- /// </summary>
- /// <param name="rhs">The vector to compare</param>
- /// <returns>Returns true if the two vectors are not equal, otherwise false</returns>
- public bool NotEqualTo(RelativeVector2 rhs)
- {
- bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, RelativeVector2.getCPtr(rhs));
- if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
- return ret;
- }
-
-
- /// <summary>
- /// x component
- /// </summary>
- public float X
- {
- set
- {
- ValueCheck(value);
- NDalicPINVOKE.Vector2_X_set(swigCPtr, value);
- if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
- }
- get
- {
- float ret = NDalicPINVOKE.Vector2_X_get(swigCPtr);
- if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
- return ret;
- }
- }
-
- /// <summary>
- /// y component
- /// </summary>
- public float Y
- {
- set
- {
- ValueCheck(value);
- NDalicPINVOKE.Vector2_Y_set(swigCPtr, value);
- if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
- }
- get
- {
- float ret = NDalicPINVOKE.Vector2_Y_get(swigCPtr);
- if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
- return ret;
- }
- }
-
- /// <summary>
- /// </summary>
- public static implicit operator Vector2(RelativeVector2 relativeVector2)
- {
- return new Vector2(relativeVector2.X, relativeVector2.Y);
- }
-
- /// <summary>
- /// </summary>
- public static implicit operator RelativeVector2(Vector2 vec)
- {
- ValueCheck(vec.X);
- ValueCheck(vec.Y);
- return new RelativeVector2(vec.X, vec.Y);
- }
-
- internal static void ValueCheck(RelativeVector2 relativeVector2)
- {
- if(relativeVector2.X < 0.0f)
- {
- relativeVector2.X = 0.0f;
- Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
- }
- else if(relativeVector2.X > 1.0f)
- {
- relativeVector2.X = 1.0f;
- Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
- }
- if(relativeVector2.Y < 0.0f)
- {
- relativeVector2.Y = 0.0f;
- Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
- }
- else if(relativeVector2.Y > 1.0f)
- {
- relativeVector2.Y = 1.0f;
- Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
- }
- }
-
- internal static void ValueCheck(float value)
- {
- if(value < 0.0f)
- {
- value = 0.0f;
- Tizen.Log.Fatal("NUI", "The value of Parameters is invalid! Should be between [0, 1].");
- }
- else if(value > 1.0f)
- {
- value = 1.0f;
- Tizen.Log.Fatal("NUI", "The value of Parameters is invalid! Should be between [0, 1].");
- }
- }
}
-
}