/*
* 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
{
///
/// A two-dimensional size.
///
public class Size2D : global::System.IDisposable
{
private global::System.Runtime.InteropServices.HandleRef swigCPtr;
protected bool swigCMemOwn;
internal Size2D(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(Size2D 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;
~Size2D()
{
if(!isDisposeQueued)
{
isDisposeQueued = true;
DisposeQueue.Instance.Add(this);
}
}
///
/// Dispose.
///
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;
}
///
/// The addition operator for A+B.
///
/// Size A.
/// Size to assign B.
/// A size containing the result of the addition.
public static Size2D operator +(Size2D arg1, Size2D arg2)
{
return arg1.Add(arg2);
}
///
/// The subtraction operator for A-B.
///
/// Size A.
/// Size to subtract B.
/// A size containing the result of the subtraction.
public static Size2D operator -(Size2D arg1, Size2D arg2)
{
return arg1.Subtract(arg2);
}
///
/// The unary negation operator.
///
/// Size for unary negation.
/// A size containing the negation.
public static Size2D operator -(Size2D arg1)
{
return arg1.Subtract();
}
///
/// The multiplication operator.
///
/// Size for multiplication.
/// Size to multiply.
/// A size containing the result of the multiplication.
public static Size2D operator *(Size2D arg1, Size2D arg2)
{
return arg1.Multiply(arg2);
}
///
/// The multiplication operator.
///
/// Size for multiplication
/// The integer value to scale the size.
/// A size containing the result of the scaling.
public static Size2D operator *(Size2D arg1, int arg2)
{
return arg1.Multiply(arg2);
}
///
/// The division operator.
///
/// Size for division.
/// Size to divide.
/// A size containing the result of the division.
public static Size2D operator /(Size2D arg1, Size2D arg2)
{
return arg1.Divide(arg2);
}
///
/// The division operator.
///
/// Size for division.
/// The integer value to scale the size by.
/// A size containing the result of the scaling.
public static Size2D operator /(Size2D arg1, int arg2)
{
return arg1.Divide(arg2);
}
///
/// The array subscript operator.
///
/// The subscript index.
/// The float at the given index.
public float this[uint index]
{
get
{
return ValueOfIndex(index);
}
}
///
/// Gets the size from the pointer.
///
/// The pointer of the size.
/// Size
internal static Size2D GetSize2DFromPtr(global::System.IntPtr cPtr)
{
Size2D ret = new Size2D(cPtr, false);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
///
/// The constructor.
///
public Size2D() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
///
/// The constructor.
///
/// The x (or width) component.
/// The y (or height) component.
public Size2D(int x, int y) : this(NDalicPINVOKE.new_Vector2__SWIG_1((float)x, (float)y), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
private Size2D Add(Size2D rhs)
{
Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Add(swigCPtr, Size2D.getCPtr(rhs)), true);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
private Size2D Subtract(Size2D rhs)
{
Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
private Size2D Multiply(Size2D rhs)
{
Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
private Size2D Multiply(int rhs)
{
Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, (float)rhs), true);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
private Size2D Divide(Size2D rhs)
{
Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
private Size2D Divide(int rhs)
{
Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, (float)rhs), true);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
private Size2D Subtract()
{
Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Subtract__SWIG_1(swigCPtr), true);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
///
/// Checks equality.
/// Utilizes appropriate machine epsilon values.
///
/// The size to test against.
/// True if the sizes are equal.
public bool EqualTo(Size2D rhs)
{
bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, Size2D.getCPtr(rhs));
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
///
/// Checks inequality.
/// Utilizes appropriate machine epsilon values.
///
/// The size to test against.
/// True if the sizes are not equal.
public bool NotEqualTo(Size2D rhs)
{
bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, Size2D.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;
}
///
/// The property for the width component of a size.
///
public int Width
{
set
{
NDalicPINVOKE.Vector2_Width_set(swigCPtr, (float)value);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
get
{
float ret = NDalicPINVOKE.Vector2_Width_get(swigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return (int)ret;
}
}
///
/// The property for the height component of a size.
///
public int Height
{
set
{
NDalicPINVOKE.Vector2_Height_set(swigCPtr, (float)value);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
get
{
float ret = NDalicPINVOKE.Vector2_Height_get(swigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return (int)ret;
}
}
///
/// The type cast operator, Size2D to Vector2.
///
/// An object of the Size2D type.
public static implicit operator Vector2(Size2D size)
{
return new Vector2((float)size.Width, (float)size.Height);
}
///
/// The type cast operator, Vector2 to Size2D type.
///
/// An object of the Vector2 type.
public static implicit operator Size2D(Vector2 vec)
{
return new Size2D((int)vec.X, (int)vec.Y);
}
///
/// The type cast operator, Size2D to Uint16Pair.
///
/// An object of the Size2D type.
public static implicit operator Uint16Pair(Size2D size2d)
{
return new Uint16Pair((uint)size2d.Width, (uint)size2d.Height);
}
///
/// The type cast operator, Uint16Pair to Size2D type.
///
/// An object of the Vector2 type.
public static implicit operator Size2D(Uint16Pair pair)
{
return new Size2D((int)pair.GetWidth(), (int)pair.GetWidth());
}
}
}