/*
* Copyright (c) 2017 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
namespace Tizen.NUI
{
///
/// Position2D is a two dimensional vector.
///
public class Position2D : global::System.IDisposable
{
private global::System.Runtime.InteropServices.HandleRef swigCPtr;
protected bool swigCMemOwn;
internal Position2D(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(Position2D obj)
{
return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
}
//A Flag to check who called Dispose(). (By User or DisposeQueue)
private bool isDisposeQueued = false;
//A Flat to check if it is already disposed.
protected bool disposed = false;
~Position2D()
{
if (!isDisposeQueued)
{
isDisposeQueued = true;
DisposeQueue.Instance.Add(this);
}
}
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);
}
}
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;
}
///
/// Addition operator.
///
/// Vector to add
/// Vector to add
/// A vector containing the result of the addition
public static Position2D operator +(Position2D arg1, Position2D arg2)
{
return arg1.Add(arg2);
}
///
/// Subtraction operator.
///
/// Vector to subtract
/// Vector to subtract
/// A vector containing the result of the subtraction
public static Position2D operator -(Position2D arg1, Position2D arg2)
{
return arg1.Subtract(arg2);
}
///
/// Unary negation operator.
///
/// Vector to netate
/// A vector containing the negation
public static Position2D operator -(Position2D arg1)
{
return arg1.Subtract();
}
///
/// Multiplication operator.
///
/// Vector to multiply
/// Vector to multiply
/// A vector containing the result of the multiplication
public static Position2D operator *(Position2D arg1, Position2D arg2)
{
return arg1.Multiply(arg2);
}
///
/// Multiplication operator.
///
/// Vector to multiply
/// The int value to scale the vector
/// A vector containing the result of the multiplication
public static Position2D operator *(Position2D arg1, int arg2)
{
return arg1.Multiply(arg2);
}
///
/// Division operator.
///
/// Vector to divide
/// Vector to divide
/// A vector containing the result of the division
public static Position2D operator /(Position2D arg1, Position2D arg2)
{
return arg1.Divide(arg2);
}
///
/// Division operator.
///
/// Vector to divide
/// The int value to scale the vector by
/// A vector containing the result of the division
public static Position2D operator /(Position2D arg1, int arg2)
{
return arg1.Divide(arg2);
}
///
/// Const array subscript operator overload. Should be 0, or 1.
///
/// Subscript index
/// The float at the given index
public float this[uint index]
{
get
{
return ValueOfIndex(index);
}
}
internal static Position2D GetPosition2DFromPtr(global::System.IntPtr cPtr)
{
Position2D ret = new Position2D(cPtr, false);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
///
/// Constructor
///
public Position2D() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
///
/// Constructor
///
/// x component
/// y component
public Position2D(int x, int y) : this(NDalicPINVOKE.new_Vector2__SWIG_1((float)x, (float)y), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
///
/// Constructor
///
/// Position to create this vector from
public Position2D(Position position) : this(NDalicPINVOKE.new_Vector2__SWIG_3(Position.getCPtr(position)), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
private Position2D Add(Position2D rhs)
{
Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Add(swigCPtr, Position2D.getCPtr(rhs)), true);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
private Position2D Subtract(Position2D rhs)
{
Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
private Position2D Multiply(Position2D rhs)
{
Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
private Position2D Multiply(int rhs)
{
Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, (float)rhs), true);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
private Position2D Divide(Position2D rhs)
{
Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
private Position2D Divide(int rhs)
{
Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, (float)rhs), true);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
private Position2D Subtract()
{
Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Subtract__SWIG_1(swigCPtr), true);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
///
/// Compare if rhs is equal to.
///
/// The vector to compare
/// Returns true if the two vectors are equal, otherwise false
public bool EqualTo(Position2D rhs)
{
bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, Position2D.getCPtr(rhs));
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
///
/// Compare if rhs is not equal to.
///
/// The vector to compare
/// Returns true if the two vectors are not equal, otherwise false
public bool NotEqualTo(Position2D rhs)
{
bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, Position2D.getCPtr(rhs));
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
private int ValueOfIndex(uint index)
{
int ret = (int)NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
///
/// x component.
///
public int X
{
set
{
NDalicPINVOKE.Vector2_X_set(swigCPtr, (float)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 (int)ret;
}
}
///
/// y component.
///
public int Y
{
set
{
NDalicPINVOKE.Vector2_Y_set(swigCPtr, (float)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 (int)ret;
}
}
///
/// Convert a position2D instance to a vector2 instance.
///
public static implicit operator Vector2(Position2D position2d)
{
return new Vector2((float)position2d.X, (float)position2d.Y);
}
///
/// Convert a vector2 instance to a position2D instance.
///
public static implicit operator Position2D(Vector2 vec)
{
return new Position2D((int)vec.X, (int)vec.Y);
}
///
/// Convert a Position2D instance to a Uint16Pair instance.
///
public static implicit operator Uint16Pair(Position2D position2d)
{
return new Uint16Pair((uint)position2d.X, (uint)position2d.Y);
}
///
/// Convert a Uint16Pair instance to a Position2D instance.
///
public static implicit operator Position2D(Uint16Pair pair)
{
return new Position2D((int)pair.GetX(), (int)pair.GetY());
}
}
}