2 * Copyright(c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 using System.ComponentModel;
18 using Tizen.NUI.Binding;
23 /// The Rectangle class.
25 /// <since_tizen> 3 </since_tizen>
26 [Binding.TypeConverter(typeof(RectangleTypeConverter))]
27 public class Rectangle : Disposable
32 /// <since_tizen> 3 </since_tizen>
33 public Rectangle() : this(Interop.Rectangle.new_Rectangle__SWIG_0(), true)
35 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
41 /// <param name="x">The x coordinate (or left).</param>
42 /// <param name="y">The y coordinate (or right).</param>
43 /// <param name="width">The width (or bottom).</param>
44 /// <param name="height">The height (or top).</param>
45 /// <since_tizen> 3 </since_tizen>
46 public Rectangle(int x, int y, int width, int height) : this(Interop.Rectangle.new_Rectangle__SWIG_1(x, y, width, height), true)
48 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
51 internal Rectangle(Rectangle other) : this(other.x, other.y, other.width, other.height)
55 internal Rectangle(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
59 internal Rectangle(RectangleChangedCallback cb, int x, int y, int width, int height) : this(Interop.Rectangle.new_Rectangle__SWIG_1(x, y, width, height), true)
62 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
65 internal Rectangle(RectangleChangedCallback cb) : this()
69 internal Rectangle(RectangleChangedCallback cb, Rectangle other) : this(cb, other.x, other.y, other.width, other.height)
74 /// The type cast operator, int to Rectangle.
76 /// <param name="value">A value of int type.</param>
77 /// <returns>return a Extents instance</returns>
78 [EditorBrowsable(EditorBrowsableState.Never)]
79 public static implicit operator Rectangle(int value)
81 return new Rectangle(value, value, value, value);
84 internal delegate void RectangleChangedCallback(int x, int y, int width, int height);
85 private RectangleChangedCallback callback = null;
88 /// The x position of the rectangle.
90 /// <since_tizen> 3 </since_tizen>
97 callback?.Invoke(X, Y, Width, Height);
106 /// The Y position of the rectangle.
108 /// <since_tizen> 3 </since_tizen>
115 callback?.Invoke(X, Y, Width, Height);
124 /// The width of the rectangle.
126 /// <since_tizen> 3 </since_tizen>
133 callback?.Invoke(X, Y, Width, Height);
142 /// The height of the rectangle.
144 /// <since_tizen> 3 </since_tizen>
151 callback?.Invoke(X, Y, Width, Height);
163 Interop.Rectangle.Rectangle_x_set(swigCPtr, value);
164 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
168 int ret = Interop.Rectangle.Rectangle_x_get(swigCPtr);
169 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
178 Interop.Rectangle.Rectangle_left_set(swigCPtr, value);
179 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
183 int ret = Interop.Rectangle.Rectangle_left_get(swigCPtr);
184 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
193 Interop.Rectangle.Rectangle_y_set(swigCPtr, value);
194 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
198 int ret = Interop.Rectangle.Rectangle_y_get(swigCPtr);
199 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
208 Interop.Rectangle.Rectangle_right_set(swigCPtr, value);
209 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
213 int ret = Interop.Rectangle.Rectangle_right_get(swigCPtr);
214 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
223 Interop.Rectangle.Rectangle_width_set(swigCPtr, value);
224 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
228 int ret = Interop.Rectangle.Rectangle_width_get(swigCPtr);
229 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
238 Interop.Rectangle.Rectangle_bottom_set(swigCPtr, value);
239 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
243 int ret = Interop.Rectangle.Rectangle_bottom_get(swigCPtr);
244 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
253 Interop.Rectangle.Rectangle_height_set(swigCPtr, value);
254 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
258 int ret = Interop.Rectangle.Rectangle_height_get(swigCPtr);
259 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
268 Interop.Rectangle.Rectangle_top_set(swigCPtr, value);
269 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
273 int ret = Interop.Rectangle.Rectangle_top_get(swigCPtr);
274 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
280 /// THe Equality operator.
282 /// <param name="a">The first operand.</param>
283 /// <param name="b">The second operand.</param>
284 /// <returns>True if the boxes are exactly the same.</returns>
285 /// <since_tizen> 3 </since_tizen>
286 public static bool operator ==(Rectangle a, Rectangle b)
288 // If both are null, or both are same instance, return true.
289 if (System.Object.ReferenceEquals(a, b))
294 // If one is null, but not both, return false.
295 if (((object)a == null) || ((object)b == null))
300 // Return true if the fields match:
301 return a.X == b.X && a.Y == b.Y && a.Width == b.Width && a.Height == b.Height;
305 /// Inequality operator.
307 /// <param name="a">The first rectangle.</param>
308 /// <param name="b">The second rectangle.</param>
309 /// <returns>True if the rectangles are not identical.</returns>
310 /// <since_tizen> 3 </since_tizen>
311 public static bool operator !=(Rectangle a, Rectangle b)
317 /// Equality operator.
319 /// <param name="o">The object to compare with the current object.</param>
320 /// <returns>True if boxes are exactly same.</returns>
321 /// <since_tizen> 4 </since_tizen>
322 public override bool Equals(object o)
328 if(!(o is Rectangle))
332 Rectangle r = (Rectangle)o;
334 // Return true if the fields match:
335 return X == r.X && Y == r.Y && Width == r.Width && Height == r.Height;
339 /// Serves as the default hash function.
341 /// <returns>A hash code for the current object.</returns>
342 /// <since_tizen> 4 </since_tizen>
343 public override int GetHashCode()
345 return base.GetHashCode();
349 /// Assignment from individual values.
351 /// <param name="newX">The x coordinate.</param>
352 /// <param name="newY">The y coordinate.</param>
353 /// <param name="newWidth">The width.</param>
354 /// <param name="newHeight">The height.</param>
355 /// <since_tizen> 3 </since_tizen>
356 public void Set(int newX, int newY, int newWidth, int newHeight)
358 Interop.Rectangle.Rectangle_Set(swigCPtr, newX, newY, newWidth, newHeight);
359 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
363 /// Determines whether or not this rectangle is empty.
365 /// <returns>True if width or height are zero.</returns>
366 /// <since_tizen> 3 </since_tizen>
367 public bool IsEmpty()
369 bool ret = Interop.Rectangle.Rectangle_IsEmpty(swigCPtr);
370 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
375 /// Gets the left of the rectangle.
377 /// <returns>The left edge of the rectangle.</returns>
378 /// <since_tizen> 3 </since_tizen>
381 int ret = Interop.Rectangle.Rectangle_Left(swigCPtr);
382 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
387 /// Gets the right of the rectangle.
389 /// <returns>The right edge of the rectangle.</returns>
390 /// <since_tizen> 3 </since_tizen>
393 int ret = Interop.Rectangle.Rectangle_Right(swigCPtr);
394 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
399 /// Gets the top of the rectangle.
401 /// <returns>The top of the rectangle.</returns>
402 /// <since_tizen> 3 </since_tizen>
405 int ret = Interop.Rectangle.Rectangle_Top(swigCPtr);
406 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
411 /// Gets the bottom of the rectangle.
413 /// <returns>The bottom of the rectangle.</returns>
414 /// <since_tizen> 3 </since_tizen>
417 int ret = Interop.Rectangle.Rectangle_Bottom(swigCPtr);
418 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
423 /// Gets the area of the rectangle.
425 /// <returns>The area of the rectangle.</returns>
426 /// <since_tizen> 3 </since_tizen>
429 int ret = Interop.Rectangle.Rectangle_Area(swigCPtr);
430 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
435 /// Determines whether or not this rectangle and the specified rectangle intersect.
437 /// <param name="other">The other rectangle to test against this rectangle.</param>
438 /// <returns>True if the rectangles intersect.</returns>
439 /// <since_tizen> 3 </since_tizen>
440 public bool Intersects(Rectangle other)
442 bool ret = Interop.Rectangle.Rectangle_Intersects(swigCPtr, Rectangle.getCPtr(other));
443 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
448 /// Determines whether or not this rectangle contains the specified rectangle.
450 /// <param name="other">The other rectangle to test against this rectangle.</param>
451 /// <returns>True if the specified rectangle is contained.</returns>
452 /// <since_tizen> 3 </since_tizen>
453 public bool Contains(Rectangle other)
455 bool ret = Interop.Rectangle.Rectangle_Contains(swigCPtr, Rectangle.getCPtr(other));
456 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
460 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Rectangle obj)
462 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
465 /// This will not be public opened.
466 [EditorBrowsable(EditorBrowsableState.Never)]
467 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
469 Interop.Rectangle.delete_Rectangle(swigCPtr);
473 /// Determines whether the reference is null or the Rectangle has all 0 properties.
475 internal static bool IsNullOrZero(Rectangle rectangle) => (rectangle == null || (rectangle.top == 0 && rectangle.right == 0 && rectangle.bottom == 0 && rectangle.left == 0));