/*
* 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.
*
*/
using System;
using Tizen.NUI.Binding;
namespace Tizen.NUI
{
///
/// The Rectangle class.
///
/// 3
[TypeConverter(typeof(RectangleTypeConverter))]
public class Rectangle : global::System.IDisposable
{
private global::System.Runtime.InteropServices.HandleRef swigCPtr;
///
/// swigCMemOwn
///
/// 3
protected bool swigCMemOwn;
internal Rectangle(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(Rectangle 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.
///
/// 3
protected bool disposed = false;
///
/// Dispose.
///
/// 3
~Rectangle()
{
if(!isDisposeQueued)
{
isDisposeQueued = true;
DisposeQueue.Instance.Add(this);
}
}
///
/// Dispose.
///
/// 3
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);
}
}
///
/// Dispose.
///
/// 3
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_Rectangle(swigCPtr);
}
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
}
disposed = true;
}
///
/// THe Equality operator.
///
/// The first operand.
/// The second operand.
/// True if the boxes are exactly the same.
/// 3
public static bool operator ==(Rectangle a, Rectangle b)
{
// If both are null, or both are same instance, return true.
if (System.Object.ReferenceEquals(a, b))
{
return true;
}
// If one is null, but not both, return false.
if (((object)a == null) || ((object)b == null))
{
return false;
}
// Return true if the fields match:
return a.X == b.X && a.Y == b.Y && a.Width == b.Width && a.Height == b.Height;
}
///
/// Equality operator.
///
/// The object to compare with the current object.
/// True if boxes are exactly same.
/// 4
public override bool Equals(object o)
{
if(o == null)
{
return false;
}
if(!(o is Rectangle))
{
return false;
}
Rectangle r = (Rectangle)o;
// Return true if the fields match:
return X == r.X && Y == r.Y && Width == r.Width && Height == r.Height;
}
///
/// Serves as the default hash function.
///
/// A hash code for the current object.
/// 4
public override int GetHashCode()
{
return base.GetHashCode();
}
///
/// Inequality operator.
///
/// The first rectangle.
/// The second rectangle.
/// True if the rectangles are not identical.
/// 3
public static bool operator !=(Rectangle a, Rectangle b)
{
return !(a == b);
}
///
/// The x position of the rectangle.
///
/// 3
public int X
{
set
{
x = ( value );
}
get
{
return x;
}
}
///
/// The Y position of the rectangle.
///
/// 3
public int Y
{
set
{
y = ( value );
}
get
{
return y;
}
}
///
/// The width of the rectangle.
///
/// 3
public int Width
{
set
{
width = ( value );
}
get
{
return width;
}
}
///
/// The height of the rectangle.
///
/// 3
public int Height
{
set
{
height = ( value );
}
get
{
return height;
}
}
///
/// The constructor.
///
/// 3
public Rectangle() : this(NDalicPINVOKE.new_Rectangle__SWIG_0(), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
///
/// The constructor.
///
/// The x coordinate (or left).
/// The y coordinate (or right).
/// The width (or bottom).
/// The height (or top).
/// 3
public Rectangle(int x, int y, int width, int height) : this(NDalicPINVOKE.new_Rectangle__SWIG_1(x, y, width, height), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
///
/// Assignment from individual values.
///
/// The x coordinate.
/// The y coordinate.
/// The width.
/// The height.
/// 3
public void Set(int newX, int newY, int newWidth, int newHeight)
{
NDalicPINVOKE.Rectangle_Set(swigCPtr, newX, newY, newWidth, newHeight);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
///
/// Determines whether or not this rectangle is empty.
///
/// True if width or height are zero.
/// 3
public bool IsEmpty()
{
bool ret = NDalicPINVOKE.Rectangle_IsEmpty(swigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
///
/// Gets the left of the rectangle.
///
/// The left edge of the rectangle.
/// 3
public int Left()
{
int ret = NDalicPINVOKE.Rectangle_Left(swigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
///
/// Gets the right of the rectangle.
///
/// The right edge of the rectangle.
/// 3
public int Right()
{
int ret = NDalicPINVOKE.Rectangle_Right(swigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
///
/// Gets the top of the rectangle.
///
/// The top of the rectangle.
/// 3
public int Top()
{
int ret = NDalicPINVOKE.Rectangle_Top(swigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
///
/// Gets the bottom of the rectangle.
///
/// The bottom of the rectangle.
/// 3
public int Bottom()
{
int ret = NDalicPINVOKE.Rectangle_Bottom(swigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
///
/// Gets the area of the rectangle.
///
/// The area of the rectangle.
/// 3
public int Area()
{
int ret = NDalicPINVOKE.Rectangle_Area(swigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
///
/// Determines whether or not this rectangle and the specified rectangle intersect.
///
/// The other rectangle to test against this rectangle.
/// True if the rectangles intersect.
/// 3
public bool Intersects(Rectangle other)
{
bool ret = NDalicPINVOKE.Rectangle_Intersects(swigCPtr, Rectangle.getCPtr(other));
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
///
/// Determines whether or not this rectangle contains the specified rectangle.
///
/// The other rectangle to test against this rectangle.
/// True if the specified rectangle is contained.
/// 3
public bool Contains(Rectangle other)
{
bool ret = NDalicPINVOKE.Rectangle_Contains(swigCPtr, Rectangle.getCPtr(other));
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
private int x
{
set
{
NDalicPINVOKE.Rectangle_x_set(swigCPtr, value);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
get
{
int ret = NDalicPINVOKE.Rectangle_x_get(swigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
}
private int left
{
set
{
NDalicPINVOKE.Rectangle_left_set(swigCPtr, value);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
get
{
int ret = NDalicPINVOKE.Rectangle_left_get(swigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
}
private int y
{
set
{
NDalicPINVOKE.Rectangle_y_set(swigCPtr, value);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
get
{
int ret = NDalicPINVOKE.Rectangle_y_get(swigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
}
private int right
{
set
{
NDalicPINVOKE.Rectangle_right_set(swigCPtr, value);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
get
{
int ret = NDalicPINVOKE.Rectangle_right_get(swigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
}
private int width
{
set
{
NDalicPINVOKE.Rectangle_width_set(swigCPtr, value);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
get
{
int ret = NDalicPINVOKE.Rectangle_width_get(swigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
}
private int bottom
{
set
{
NDalicPINVOKE.Rectangle_bottom_set(swigCPtr, value);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
get
{
int ret = NDalicPINVOKE.Rectangle_bottom_get(swigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
}
private int height
{
set
{
NDalicPINVOKE.Rectangle_height_set(swigCPtr, value);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
get
{
int ret = NDalicPINVOKE.Rectangle_height_get(swigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
}
private int top
{
set
{
NDalicPINVOKE.Rectangle_top_set(swigCPtr, value);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
get
{
int ret = NDalicPINVOKE.Rectangle_top_get(swigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
}
}
}