/*
- * Copyright(c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright(c) 2019 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.
* limitations under the License.
*
*/
+using System.ComponentModel;
+using Tizen.NUI.Binding;
namespace Tizen.NUI
{
-
/// <summary>
/// The Rectangle class.
/// </summary>
/// <since_tizen> 3 </since_tizen>
- public class Rectangle : global::System.IDisposable
+ [Binding.TypeConverter(typeof(RectangleTypeConverter))]
+ public class Rectangle : Disposable
{
- private global::System.Runtime.InteropServices.HandleRef swigCPtr;
/// <summary>
- /// swigCMemOwn
+ /// The constructor.
/// </summary>
/// <since_tizen> 3 </since_tizen>
- protected bool swigCMemOwn;
+ public Rectangle() : this(Interop.Rectangle.new_Rectangle__SWIG_0(), true)
+ {
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ }
- internal Rectangle(global::System.IntPtr cPtr, bool cMemoryOwn)
+ /// <summary>
+ /// The constructor.
+ /// </summary>
+ /// <param name="x">The x coordinate (or left).</param>
+ /// <param name="y">The y coordinate (or right).</param>
+ /// <param name="width">The width (or bottom).</param>
+ /// <param name="height">The height (or top).</param>
+ /// <since_tizen> 3 </since_tizen>
+ public Rectangle(int x, int y, int width, int height) : this(Interop.Rectangle.new_Rectangle__SWIG_1(x, y, width, height), true)
{
- swigCMemOwn = cMemoryOwn;
- swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
- internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Rectangle obj)
+ internal Rectangle(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
{
- 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;
- /// <summary>
- /// A Flat to check if it is already disposed.
- /// </summary>
- /// <since_tizen> 3 </since_tizen>
- protected bool disposed = false;
+ internal Rectangle(RectangleChangedCallback cb, int x, int y, int width, int height) : this(Interop.Rectangle.new_Rectangle__SWIG_1(x, y, width, height), true)
+ {
+ callback = cb;
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ }
+
+ internal Rectangle(RectangleChangedCallback cb) : this()
+ {
+ }
+
+ internal Rectangle(RectangleChangedCallback cb, Rectangle other) : this(cb, other.x, other.y, other.width, other.height)
+ {
+ }
+
+ internal delegate void RectangleChangedCallback(int x, int y, int width, int height);
+ private RectangleChangedCallback callback = null;
/// <summary>
- /// Dispose.
+ /// The x position of the rectangle.
/// </summary>
/// <since_tizen> 3 </since_tizen>
- ~Rectangle()
+ public int X
{
- if(!isDisposeQueued)
+ set
+ {
+ x = (value);
+
+ callback?.Invoke(X, Y, Width, Height);
+ }
+ get
{
- isDisposeQueued = true;
- DisposeQueue.Instance.Add(this);
+ return x;
}
}
/// <summary>
- /// Dispose.
+ /// The Y position of the rectangle.
/// </summary>
/// <since_tizen> 3 </since_tizen>
- public void Dispose()
+ public int Y
{
- //Throw excpetion if Dispose() is called in separate thread.
- if (!Window.IsInstalled())
+ set
{
- throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
- }
+ y = (value);
- if (isDisposeQueued)
- {
- Dispose(DisposeTypes.Implicit);
+ callback?.Invoke(X, Y, Width, Height);
}
- else
+ get
{
- Dispose(DisposeTypes.Explicit);
- System.GC.SuppressFinalize(this);
+ return y;
}
}
/// <summary>
- /// Dispose.
+ /// The width of the rectangle.
/// </summary>
/// <since_tizen> 3 </since_tizen>
- protected virtual void Dispose(DisposeTypes type)
+ public int Width
{
- if (disposed)
+ set
{
- return;
- }
+ width = (value);
- if(type == DisposeTypes.Explicit)
- {
- //Called by User
- //Release your own managed resources here.
- //You should release all of your own disposable objects here.
+ callback?.Invoke(X, Y, Width, Height);
}
-
- //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)
+ get
{
- if (swigCMemOwn)
- {
- swigCMemOwn = false;
- NDalicPINVOKE.delete_Rectangle(swigCPtr);
- }
- swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+ return width;
}
- disposed = true;
}
/// <summary>
- /// THe Equality operator.
+ /// The height of the rectangle.
/// </summary>
- /// <param name="a">The first operand.</param>
- /// <param name="b">The second operand.</param>
- /// <returns>True if the boxes are exactly the same.</returns>
/// <since_tizen> 3 </since_tizen>
- public static bool operator ==(Rectangle a, Rectangle b)
+ public int Height
{
- // If both are null, or both are same instance, return true.
- if (System.Object.ReferenceEquals(a, b))
+ set
{
- return true;
- }
+ height = (value);
- // If one is null, but not both, return false.
- if (((object)a == null) || ((object)b == null))
+ callback?.Invoke(X, Y, Width, Height);
+ }
+ get
{
- return false;
+ return height;
}
-
- // Return true if the fields match:
- return a.X == b.X && a.Y == b.Y && a.Width == b.Width && a.Height == b.Height;
}
- /// <summary>
- /// Equality operator.
- /// </summary>
- /// <param name="o">The object to compare with the current object.</param>
- /// <returns>True if boxes are exactly same.</returns>
- /// <since_tizen> 4 </since_tizen>
- public override bool Equals(object o)
+ private int x
{
- if(o == null)
+ set
{
- return false;
+ Interop.Rectangle.Rectangle_x_set(swigCPtr, value);
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
- if(!(o is Rectangle))
+ get
{
- return false;
+ int ret = Interop.Rectangle.Rectangle_x_get(swigCPtr);
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ return ret;
}
- Rectangle r = (Rectangle)o;
+ }
- // Return true if the fields match:
- return X == r.X && Y == r.Y && Width == r.Width && Height == r.Height;
+ private int left
+ {
+ set
+ {
+ Interop.Rectangle.Rectangle_left_set(swigCPtr, value);
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ }
+ get
+ {
+ int ret = Interop.Rectangle.Rectangle_left_get(swigCPtr);
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ return ret;
+ }
}
- /// <summary>
- /// Serves as the default hash function.
- /// </summary>
- /// <returns>A hash code for the current object.</returns>
- /// <since_tizen> 4 </since_tizen>
- public override int GetHashCode()
+ private int y
{
- return base.GetHashCode();
+ set
+ {
+ Interop.Rectangle.Rectangle_y_set(swigCPtr, value);
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ }
+ get
+ {
+ int ret = Interop.Rectangle.Rectangle_y_get(swigCPtr);
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ return ret;
+ }
}
- /// <summary>
- /// Inequality operator.
- /// </summary>
- /// <param name="a">The first rectangle.</param>
- /// <param name="b">The second rectangle.</param>
- /// <returns>True if the rectangles are not identical.</returns>
- /// <since_tizen> 3 </since_tizen>
- public static bool operator !=(Rectangle a, Rectangle b)
+ private int right
{
- return !(a == b);
+ set
+ {
+ Interop.Rectangle.Rectangle_right_set(swigCPtr, value);
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ }
+ get
+ {
+ int ret = Interop.Rectangle.Rectangle_right_get(swigCPtr);
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ return ret;
+ }
}
- /// <summary>
- /// The x position of the rectangle.
- /// </summary>
- /// <since_tizen> 3 </since_tizen>
- public int X
+ private int width
{
set
{
- x = ( value );
+ Interop.Rectangle.Rectangle_width_set(swigCPtr, value);
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
get
{
- return x;
+ int ret = Interop.Rectangle.Rectangle_width_get(swigCPtr);
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ return ret;
}
+ }
+
+ private int bottom
+ {
+ set
+ {
+ Interop.Rectangle.Rectangle_bottom_set(swigCPtr, value);
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
+ get
+ {
+ int ret = Interop.Rectangle.Rectangle_bottom_get(swigCPtr);
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ return ret;
+ }
+ }
- /// <summary>
- /// The Y position of the rectangle.
- /// </summary>
- /// <since_tizen> 3 </since_tizen>
- public int Y
+ private int height
{
set
{
- y = ( value );
+ Interop.Rectangle.Rectangle_height_set(swigCPtr, value);
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
get
{
- return y;
+ int ret = Interop.Rectangle.Rectangle_height_get(swigCPtr);
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ return ret;
}
}
- /// <summary>
- /// The width of the rectangle.
- /// </summary>
- /// <since_tizen> 3 </since_tizen>
- public int Width
+ private int top
{
set
{
- width = ( value );
+ Interop.Rectangle.Rectangle_top_set(swigCPtr, value);
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
get
{
- return width;
+ int ret = Interop.Rectangle.Rectangle_top_get(swigCPtr);
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ return ret;
}
}
/// <summary>
- /// The height of the rectangle.
+ /// THe Equality operator.
/// </summary>
+ /// <param name="a">The first operand.</param>
+ /// <param name="b">The second operand.</param>
+ /// <returns>True if the boxes are exactly the same.</returns>
/// <since_tizen> 3 </since_tizen>
- public int Height
+ public static bool operator ==(Rectangle a, Rectangle b)
{
- set
+ // If both are null, or both are same instance, return true.
+ if (System.Object.ReferenceEquals(a, b))
{
- height = ( value );
+ return true;
}
- get
+
+ // If one is null, but not both, return false.
+ if (((object)a == null) || ((object)b == null))
{
- return height;
+ 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;
}
/// <summary>
- /// The constructor.
+ /// Inequality operator.
/// </summary>
+ /// <param name="a">The first rectangle.</param>
+ /// <param name="b">The second rectangle.</param>
+ /// <returns>True if the rectangles are not identical.</returns>
/// <since_tizen> 3 </since_tizen>
- public Rectangle() : this(NDalicPINVOKE.new_Rectangle__SWIG_0(), true)
+ public static bool operator !=(Rectangle a, Rectangle b)
{
- if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ return !(a == b);
}
/// <summary>
- /// The constructor.
+ /// Equality operator.
/// </summary>
- /// <param name="x">The x coordinate (or left).</param>
- /// <param name="y">The y coordinate (or right).</param>
- /// <param name="width">The width (or bottom).</param>
- /// <param name="height">The height (or top).</param>
- /// <since_tizen> 3 </since_tizen>
- public Rectangle(int x, int y, int width, int height) : this(NDalicPINVOKE.new_Rectangle__SWIG_1(x, y, width, height), true)
+ /// <param name="o">The object to compare with the current object.</param>
+ /// <returns>True if boxes are exactly same.</returns>
+ /// <since_tizen> 4 </since_tizen>
+ public override bool Equals(object o)
{
- if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ 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;
+ }
+
+ /// <summary>
+ /// Serves as the default hash function.
+ /// </summary>
+ /// <returns>A hash code for the current object.</returns>
+ /// <since_tizen> 4 </since_tizen>
+ public override int GetHashCode()
+ {
+ return base.GetHashCode();
}
/// <summary>
/// <since_tizen> 3 </since_tizen>
public void Set(int newX, int newY, int newWidth, int newHeight)
{
- NDalicPINVOKE.Rectangle_Set(swigCPtr, newX, newY, newWidth, newHeight);
+ Interop.Rectangle.Rectangle_Set(swigCPtr, newX, newY, newWidth, newHeight);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
/// <since_tizen> 3 </since_tizen>
public bool IsEmpty()
{
- bool ret = NDalicPINVOKE.Rectangle_IsEmpty(swigCPtr);
+ bool ret = Interop.Rectangle.Rectangle_IsEmpty(swigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
/// <since_tizen> 3 </since_tizen>
public int Left()
{
- int ret = NDalicPINVOKE.Rectangle_Left(swigCPtr);
+ int ret = Interop.Rectangle.Rectangle_Left(swigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
/// <since_tizen> 3 </since_tizen>
public int Right()
{
- int ret = NDalicPINVOKE.Rectangle_Right(swigCPtr);
+ int ret = Interop.Rectangle.Rectangle_Right(swigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
/// <since_tizen> 3 </since_tizen>
public int Top()
{
- int ret = NDalicPINVOKE.Rectangle_Top(swigCPtr);
+ int ret = Interop.Rectangle.Rectangle_Top(swigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
/// <since_tizen> 3 </since_tizen>
public int Bottom()
{
- int ret = NDalicPINVOKE.Rectangle_Bottom(swigCPtr);
+ int ret = Interop.Rectangle.Rectangle_Bottom(swigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
/// <since_tizen> 3 </since_tizen>
public int Area()
{
- int ret = NDalicPINVOKE.Rectangle_Area(swigCPtr);
+ int ret = Interop.Rectangle.Rectangle_Area(swigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
/// <since_tizen> 3 </since_tizen>
public bool Intersects(Rectangle other)
{
- bool ret = NDalicPINVOKE.Rectangle_Intersects(swigCPtr, Rectangle.getCPtr(other));
+ bool ret = Interop.Rectangle.Rectangle_Intersects(swigCPtr, Rectangle.getCPtr(other));
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
/// <since_tizen> 3 </since_tizen>
public bool Contains(Rectangle other)
{
- bool ret = NDalicPINVOKE.Rectangle_Contains(swigCPtr, Rectangle.getCPtr(other));
+ bool ret = Interop.Rectangle.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
+ internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Rectangle obj)
{
- 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;
- }
+ return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
}
- private int top
+ /// This will not be public opened.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
{
- 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;
- }
+ Interop.Rectangle.delete_Rectangle(swigCPtr);
}
+ /// <summary>
+ /// Determines whether the reference is null or the Rectangle has all 0 properties.
+ /// </summary>
+ internal static bool IsNullOrZero(Rectangle rectangle) => (rectangle == null || (rectangle.top == 0 && rectangle.right == 0 && rectangle.bottom == 0 && rectangle.left == 0));
}
-
}
\ No newline at end of file