/* * 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. * 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 System.ComponentModel; using Tizen.NUI.Binding; namespace Tizen.NUI { /// /// The Rectangle class. /// /// 3 [Binding.TypeConverter(typeof(RectangleTypeConverter))] public class Rectangle : Disposable, ICloneable { /// /// The constructor. /// /// 3 public Rectangle() : this(Interop.Rectangle.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(Interop.Rectangle.new_Rectangle__SWIG_1(x, y, width, height), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } internal Rectangle(Rectangle other) : this(other.x, other.y, other.width, other.height) { } internal Rectangle(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn) { } 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() { callback = cb; } internal Rectangle(RectangleChangedCallback cb, Rectangle other) : this(cb, other.x, other.y, other.width, other.height) { } /// /// The type cast operator, int to Rectangle. /// /// A value of int type. /// return a Extents instance [EditorBrowsable(EditorBrowsableState.Never)] public static implicit operator Rectangle(int value) { return new Rectangle(value, value, value, value); } internal delegate void RectangleChangedCallback(int x, int y, int width, int height); private RectangleChangedCallback callback = null; /// /// The x position of the rectangle. /// /// /// The setter is deprecated in API8 and will be removed in API10. Please use new Rectangle(...) constructor. /// /// /// // DO NOT use like the followings! /// Rectangle rectangle = new Rectangle(); /// rectangle.X = 1; /// // Please USE like this /// int x = 1, y = 2, width = 3, height = 4; /// Rectangle rectangle = new Rectangle(x, y, width, height); /// /// 3 public int X { set { Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Rectangle(...) constructor"); x = (value); callback?.Invoke(X, Y, Width, Height); } get { return x; } } /// /// The Y position of the rectangle. /// /// /// The setter is deprecated in API8 and will be removed in API10. Please use new Rectangle(...) constructor. /// /// /// // DO NOT use like the followings! /// Rectangle rectangle = new Rectangle(); /// rectangle.Y = 2; /// // Please USE like this /// int x = 1, y = 2, width = 3, height = 4; /// Rectangle rectangle = new Rectangle(x, y, width, height); /// /// 3 public int Y { set { Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Rectangle(...) constructor"); y = (value); callback?.Invoke(X, Y, Width, Height); } get { return y; } } /// /// The width of the rectangle. /// /// /// The setter is deprecated in API8 and will be removed in API10. Please use new Rectangle(...) constructor. /// /// /// // DO NOT use like the followings! /// Rectangle rectangle = new Rectangle(); /// rectangle.Width = 3; /// // Please USE like this /// int x = 1, y = 2, width = 3, height = 4; /// Rectangle rectangle = new Rectangle(x, y, width, height); /// /// 3 public int Width { set { Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Rectangle(...) constructor"); width = (value); callback?.Invoke(X, Y, Width, Height); } get { return width; } } /// /// The height of the rectangle. /// /// /// The setter is deprecated in API8 and will be removed in API10. Please use new Rectangle(...) constructor. /// /// /// // DO NOT use like the followings! /// Rectangle rectangle = new Rectangle(); /// rectangle.Height = 4; /// // Please USE like this /// int x = 1, y = 2, width = 3, height = 4; /// Rectangle rectangle = new Rectangle(x, y, width, height); /// /// 3 public int Height { set { Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Rectangle(...) constructor"); height = (value); callback?.Invoke(X, Y, Width, Height); } get { return height; } } private int x { set { Interop.Rectangle.Rectangle_x_set(swigCPtr, value); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } get { int ret = Interop.Rectangle.Rectangle_x_get(swigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } } 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; } } private int y { 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; } } private int right { 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; } } private int width { set { Interop.Rectangle.Rectangle_width_set(swigCPtr, value); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } get { 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; } } private int height { set { Interop.Rectangle.Rectangle_height_set(swigCPtr, value); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } get { int ret = Interop.Rectangle.Rectangle_height_get(swigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } } private int top { set { Interop.Rectangle.Rectangle_top_set(swigCPtr, value); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } get { int ret = Interop.Rectangle.Rectangle_top_get(swigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } } /// /// 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; } /// /// 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); } /// /// 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(); } /// /// 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) { Interop.Rectangle.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 = Interop.Rectangle.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 = Interop.Rectangle.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 = Interop.Rectangle.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 = Interop.Rectangle.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 = Interop.Rectangle.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 = Interop.Rectangle.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 = Interop.Rectangle.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 = Interop.Rectangle.Rectangle_Contains(swigCPtr, Rectangle.getCPtr(other)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// [EditorBrowsable(EditorBrowsableState.Never)] public object Clone() => new Rectangle(this); 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; } /// This will not be public opened. [EditorBrowsable(EditorBrowsableState.Never)] protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr) { Interop.Rectangle.delete_Rectangle(swigCPtr); } /// /// Determines whether the reference is null or the Rectangle has all 0 properties. /// internal static bool IsNullOrZero(Rectangle rectangle) => (rectangle == null || (rectangle.top == 0 && rectangle.right == 0 && rectangle.bottom == 0 && rectangle.left == 0)); } }