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.
18 using System.ComponentModel;
19 using Tizen.NUI.Binding;
24 /// The Rectangle class.
26 /// <since_tizen> 3 </since_tizen>
27 [Binding.TypeConverter(typeof(RectangleTypeConverter))]
28 public class Rectangle : Disposable, ICloneable
33 /// <since_tizen> 3 </since_tizen>
34 public Rectangle() : this(Interop.Rectangle.new_Rectangle__SWIG_0(), true)
36 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
42 /// <param name="x">The x coordinate (or left).</param>
43 /// <param name="y">The y coordinate (or right).</param>
44 /// <param name="width">The width (or bottom).</param>
45 /// <param name="height">The height (or top).</param>
46 /// <since_tizen> 3 </since_tizen>
47 public Rectangle(int x, int y, int width, int height) : this(Interop.Rectangle.new_Rectangle__SWIG_1(x, y, width, height), true)
49 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
52 internal Rectangle(Rectangle other) : this(other.x, other.y, other.width, other.height)
56 internal Rectangle(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
60 internal Rectangle(RectangleChangedCallback cb, int x, int y, int width, int height) : this(Interop.Rectangle.new_Rectangle__SWIG_1(x, y, width, height), true)
63 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
66 internal Rectangle(RectangleChangedCallback cb) : this()
70 internal Rectangle(RectangleChangedCallback cb, Rectangle other) : this(cb, other.x, other.y, other.width, other.height)
75 /// The type cast operator, int to Rectangle.
77 /// <param name="value">A value of int type.</param>
78 /// <returns>return a Extents instance</returns>
79 [EditorBrowsable(EditorBrowsableState.Never)]
80 public static implicit operator Rectangle(int value)
82 return new Rectangle(value, value, value, value);
85 internal delegate void RectangleChangedCallback(int x, int y, int width, int height);
86 private RectangleChangedCallback callback = null;
89 /// The x position of the rectangle.
91 /// <since_tizen> 3 </since_tizen>
98 callback?.Invoke(X, Y, Width, Height);
107 /// The Y position of the rectangle.
109 /// <since_tizen> 3 </since_tizen>
116 callback?.Invoke(X, Y, Width, Height);
125 /// The width of the rectangle.
127 /// <since_tizen> 3 </since_tizen>
134 callback?.Invoke(X, Y, Width, Height);
143 /// The height of the rectangle.
145 /// <since_tizen> 3 </since_tizen>
152 callback?.Invoke(X, Y, Width, Height);
164 Interop.Rectangle.Rectangle_x_set(swigCPtr, value);
165 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
169 int ret = Interop.Rectangle.Rectangle_x_get(swigCPtr);
170 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
179 Interop.Rectangle.Rectangle_left_set(swigCPtr, value);
180 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
184 int ret = Interop.Rectangle.Rectangle_left_get(swigCPtr);
185 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
194 Interop.Rectangle.Rectangle_y_set(swigCPtr, value);
195 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
199 int ret = Interop.Rectangle.Rectangle_y_get(swigCPtr);
200 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
209 Interop.Rectangle.Rectangle_right_set(swigCPtr, value);
210 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
214 int ret = Interop.Rectangle.Rectangle_right_get(swigCPtr);
215 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
224 Interop.Rectangle.Rectangle_width_set(swigCPtr, value);
225 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
229 int ret = Interop.Rectangle.Rectangle_width_get(swigCPtr);
230 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
239 Interop.Rectangle.Rectangle_bottom_set(swigCPtr, value);
240 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
244 int ret = Interop.Rectangle.Rectangle_bottom_get(swigCPtr);
245 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
254 Interop.Rectangle.Rectangle_height_set(swigCPtr, value);
255 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
259 int ret = Interop.Rectangle.Rectangle_height_get(swigCPtr);
260 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
269 Interop.Rectangle.Rectangle_top_set(swigCPtr, value);
270 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
274 int ret = Interop.Rectangle.Rectangle_top_get(swigCPtr);
275 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
281 /// THe Equality operator.
283 /// <param name="a">The first operand.</param>
284 /// <param name="b">The second operand.</param>
285 /// <returns>True if the boxes are exactly the same.</returns>
286 /// <since_tizen> 3 </since_tizen>
287 public static bool operator ==(Rectangle a, Rectangle b)
289 // If both are null, or both are same instance, return true.
290 if (System.Object.ReferenceEquals(a, b))
295 // If one is null, but not both, return false.
296 if (((object)a == null) || ((object)b == null))
301 // Return true if the fields match:
302 return a.X == b.X && a.Y == b.Y && a.Width == b.Width && a.Height == b.Height;
306 /// Inequality operator.
308 /// <param name="a">The first rectangle.</param>
309 /// <param name="b">The second rectangle.</param>
310 /// <returns>True if the rectangles are not identical.</returns>
311 /// <since_tizen> 3 </since_tizen>
312 public static bool operator !=(Rectangle a, Rectangle b)
318 /// Equality operator.
320 /// <param name="o">The object to compare with the current object.</param>
321 /// <returns>True if boxes are exactly same.</returns>
322 /// <since_tizen> 4 </since_tizen>
323 public override bool Equals(object o)
329 if(!(o is Rectangle))
333 Rectangle r = (Rectangle)o;
335 // Return true if the fields match:
336 return X == r.X && Y == r.Y && Width == r.Width && Height == r.Height;
340 /// Serves as the default hash function.
342 /// <returns>A hash code for the current object.</returns>
343 /// <since_tizen> 4 </since_tizen>
344 public override int GetHashCode()
346 return base.GetHashCode();
350 /// Assignment from individual values.
352 /// <param name="newX">The x coordinate.</param>
353 /// <param name="newY">The y coordinate.</param>
354 /// <param name="newWidth">The width.</param>
355 /// <param name="newHeight">The height.</param>
356 /// <since_tizen> 3 </since_tizen>
357 public void Set(int newX, int newY, int newWidth, int newHeight)
359 Interop.Rectangle.Rectangle_Set(swigCPtr, newX, newY, newWidth, newHeight);
360 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
364 /// Determines whether or not this rectangle is empty.
366 /// <returns>True if width or height are zero.</returns>
367 /// <since_tizen> 3 </since_tizen>
368 public bool IsEmpty()
370 bool ret = Interop.Rectangle.Rectangle_IsEmpty(swigCPtr);
371 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
376 /// Gets the left of the rectangle.
378 /// <returns>The left edge of the rectangle.</returns>
379 /// <since_tizen> 3 </since_tizen>
382 int ret = Interop.Rectangle.Rectangle_Left(swigCPtr);
383 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
388 /// Gets the right of the rectangle.
390 /// <returns>The right edge of the rectangle.</returns>
391 /// <since_tizen> 3 </since_tizen>
394 int ret = Interop.Rectangle.Rectangle_Right(swigCPtr);
395 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
400 /// Gets the top of the rectangle.
402 /// <returns>The top of the rectangle.</returns>
403 /// <since_tizen> 3 </since_tizen>
406 int ret = Interop.Rectangle.Rectangle_Top(swigCPtr);
407 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
412 /// Gets the bottom of the rectangle.
414 /// <returns>The bottom of the rectangle.</returns>
415 /// <since_tizen> 3 </since_tizen>
418 int ret = Interop.Rectangle.Rectangle_Bottom(swigCPtr);
419 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
424 /// Gets the area of the rectangle.
426 /// <returns>The area of the rectangle.</returns>
427 /// <since_tizen> 3 </since_tizen>
430 int ret = Interop.Rectangle.Rectangle_Area(swigCPtr);
431 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
436 /// Determines whether or not this rectangle and the specified rectangle intersect.
438 /// <param name="other">The other rectangle to test against this rectangle.</param>
439 /// <returns>True if the rectangles intersect.</returns>
440 /// <since_tizen> 3 </since_tizen>
441 public bool Intersects(Rectangle other)
443 bool ret = Interop.Rectangle.Rectangle_Intersects(swigCPtr, Rectangle.getCPtr(other));
444 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
449 /// Determines whether or not this rectangle contains the specified rectangle.
451 /// <param name="other">The other rectangle to test against this rectangle.</param>
452 /// <returns>True if the specified rectangle is contained.</returns>
453 /// <since_tizen> 3 </since_tizen>
454 public bool Contains(Rectangle other)
456 bool ret = Interop.Rectangle.Rectangle_Contains(swigCPtr, Rectangle.getCPtr(other));
457 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
462 [EditorBrowsable(EditorBrowsableState.Never)]
463 public object Clone() => new Rectangle(this);
465 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Rectangle obj)
467 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
470 /// This will not be public opened.
471 [EditorBrowsable(EditorBrowsableState.Never)]
472 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
474 Interop.Rectangle.delete_Rectangle(swigCPtr);
478 /// Determines whether the reference is null or the Rectangle has all 0 properties.
480 internal static bool IsNullOrZero(Rectangle rectangle) => (rectangle == null || (rectangle.top == 0 && rectangle.right == 0 && rectangle.bottom == 0 && rectangle.left == 0));