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.NewRectangle(), 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.NewRectangle(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.NewRectangle(x, y, width, height), true)
63 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
66 internal Rectangle(RectangleChangedCallback cb) : this()
71 internal Rectangle(RectangleChangedCallback cb, Rectangle other) : this(cb, other.x, other.y, other.width, other.height)
76 /// The type cast operator, int to Rectangle.
78 /// <param name="value">A value of int type.</param>
79 /// <returns>return a Extents instance</returns>
80 [EditorBrowsable(EditorBrowsableState.Never)]
81 public static implicit operator Rectangle(int value)
83 return new Rectangle(value, value, value, value);
86 internal delegate void RectangleChangedCallback(int x, int y, int width, int height);
87 private RectangleChangedCallback callback = null;
90 /// The x position of the rectangle.
93 /// The setter is deprecated in API8 and will be removed in API10. Please use new Rectangle(...) constructor.
96 /// // DO NOT use like the followings!
97 /// Rectangle rectangle = new Rectangle();
99 /// // Please USE like this
100 /// int x = 1, y = 2, width = 3, height = 4;
101 /// Rectangle rectangle = new Rectangle(x, y, width, height);
103 /// <since_tizen> 3 </since_tizen>
108 Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Rectangle(...) constructor");
112 callback?.Invoke(X, Y, Width, Height);
121 /// The Y position of the rectangle.
124 /// The setter is deprecated in API8 and will be removed in API10. Please use new Rectangle(...) constructor.
127 /// // DO NOT use like the followings!
128 /// Rectangle rectangle = new Rectangle();
130 /// // Please USE like this
131 /// int x = 1, y = 2, width = 3, height = 4;
132 /// Rectangle rectangle = new Rectangle(x, y, width, height);
134 /// <since_tizen> 3 </since_tizen>
139 Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Rectangle(...) constructor");
143 callback?.Invoke(X, Y, Width, Height);
152 /// The width of the rectangle.
155 /// The setter is deprecated in API8 and will be removed in API10. Please use new Rectangle(...) constructor.
158 /// // DO NOT use like the followings!
159 /// Rectangle rectangle = new Rectangle();
160 /// rectangle.Width = 3;
161 /// // Please USE like this
162 /// int x = 1, y = 2, width = 3, height = 4;
163 /// Rectangle rectangle = new Rectangle(x, y, width, height);
165 /// <since_tizen> 3 </since_tizen>
170 Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Rectangle(...) constructor");
174 callback?.Invoke(X, Y, Width, Height);
183 /// The height of the rectangle.
186 /// The setter is deprecated in API8 and will be removed in API10. Please use new Rectangle(...) constructor.
189 /// // DO NOT use like the followings!
190 /// Rectangle rectangle = new Rectangle();
191 /// rectangle.Height = 4;
192 /// // Please USE like this
193 /// int x = 1, y = 2, width = 3, height = 4;
194 /// Rectangle rectangle = new Rectangle(x, y, width, height);
196 /// <since_tizen> 3 </since_tizen>
201 Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Rectangle(...) constructor");
205 callback?.Invoke(X, Y, Width, Height);
217 Interop.Rectangle.XSet(swigCPtr, value);
218 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
222 int ret = Interop.Rectangle.XGet(swigCPtr);
223 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
232 Interop.Rectangle.LeftSet(swigCPtr, value);
233 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
237 int ret = Interop.Rectangle.LeftGet(swigCPtr);
238 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
247 Interop.Rectangle.YSet(swigCPtr, value);
248 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
252 int ret = Interop.Rectangle.YGet(swigCPtr);
253 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
262 Interop.Rectangle.RightSet(swigCPtr, value);
263 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
267 int ret = Interop.Rectangle.RightGet(swigCPtr);
268 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
277 Interop.Rectangle.WidthSet(swigCPtr, value);
278 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
282 int ret = Interop.Rectangle.WidthGet(swigCPtr);
283 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
292 Interop.Rectangle.BottomSet(swigCPtr, value);
293 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
297 int ret = Interop.Rectangle.BottomGet(swigCPtr);
298 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
307 Interop.Rectangle.HeightSet(swigCPtr, value);
308 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
312 int ret = Interop.Rectangle.HeightGet(swigCPtr);
313 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
322 Interop.Rectangle.TopSet(swigCPtr, value);
323 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
327 int ret = Interop.Rectangle.TopGet(swigCPtr);
328 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
334 /// THe Equality operator.
336 /// <param name="a">The first operand.</param>
337 /// <param name="b">The second operand.</param>
338 /// <returns>True if the boxes are exactly the same.</returns>
339 /// <since_tizen> 3 </since_tizen>
340 public static bool operator ==(Rectangle a, Rectangle b)
342 // If both are null, or both are same instance, return true.
343 if (System.Object.ReferenceEquals(a, b))
348 // If one is null, but not both, return false.
349 if (((object)a == null) || ((object)b == null))
354 // Return true if the fields match:
355 return a.X == b.X && a.Y == b.Y && a.Width == b.Width && a.Height == b.Height;
359 /// Inequality operator.
361 /// <param name="a">The first rectangle.</param>
362 /// <param name="b">The second rectangle.</param>
363 /// <returns>True if the rectangles are not identical.</returns>
364 /// <since_tizen> 3 </since_tizen>
365 public static bool operator !=(Rectangle a, Rectangle b)
371 /// Equality operator.
373 /// <param name="o">The object to compare with the current object.</param>
374 /// <returns>True if boxes are exactly same.</returns>
375 /// <since_tizen> 4 </since_tizen>
376 public override bool Equals(object o)
382 if (!(o is Rectangle))
386 Rectangle r = (Rectangle)o;
388 // Return true if the fields match:
389 return X == r.X && Y == r.Y && Width == r.Width && Height == r.Height;
393 /// Serves as the default hash function.
395 /// <returns>A hash code for the current object.</returns>
396 /// <since_tizen> 4 </since_tizen>
397 public override int GetHashCode()
399 return base.GetHashCode();
403 /// Assignment from individual values.
405 /// <param name="newX">The x coordinate.</param>
406 /// <param name="newY">The y coordinate.</param>
407 /// <param name="newWidth">The width.</param>
408 /// <param name="newHeight">The height.</param>
409 /// <since_tizen> 3 </since_tizen>
410 public void Set(int newX, int newY, int newWidth, int newHeight)
412 Interop.Rectangle.Set(swigCPtr, newX, newY, newWidth, newHeight);
413 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
417 /// Determines whether or not this rectangle is empty.
419 /// <returns>True if width or height are zero.</returns>
420 /// <since_tizen> 3 </since_tizen>
421 public bool IsEmpty()
423 bool ret = Interop.Rectangle.IsEmpty(swigCPtr);
424 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
429 /// Gets the left of the rectangle.
431 /// <returns>The left edge of the rectangle.</returns>
432 /// <since_tizen> 3 </since_tizen>
435 int ret = Interop.Rectangle.Left(swigCPtr);
436 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
441 /// Gets the right of the rectangle.
443 /// <returns>The right edge of the rectangle.</returns>
444 /// <since_tizen> 3 </since_tizen>
447 int ret = Interop.Rectangle.Right(swigCPtr);
448 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
453 /// Gets the top of the rectangle.
455 /// <returns>The top of the rectangle.</returns>
456 /// <since_tizen> 3 </since_tizen>
459 int ret = Interop.Rectangle.Top(swigCPtr);
460 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
465 /// Gets the bottom of the rectangle.
467 /// <returns>The bottom of the rectangle.</returns>
468 /// <since_tizen> 3 </since_tizen>
471 int ret = Interop.Rectangle.Bottom(swigCPtr);
472 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
477 /// Gets the area of the rectangle.
479 /// <returns>The area of the rectangle.</returns>
480 /// <since_tizen> 3 </since_tizen>
483 int ret = Interop.Rectangle.Area(swigCPtr);
484 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
489 /// Determines whether or not this rectangle and the specified rectangle intersect.
491 /// <param name="other">The other rectangle to test against this rectangle.</param>
492 /// <returns>True if the rectangles intersect.</returns>
493 /// <since_tizen> 3 </since_tizen>
494 public bool Intersects(Rectangle other)
496 bool ret = Interop.Rectangle.Intersects(swigCPtr, Rectangle.getCPtr(other));
497 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
502 /// Determines whether or not this rectangle contains the specified rectangle.
504 /// <param name="other">The other rectangle to test against this rectangle.</param>
505 /// <returns>True if the specified rectangle is contained.</returns>
506 /// <since_tizen> 3 </since_tizen>
507 public bool Contains(Rectangle other)
509 bool ret = Interop.Rectangle.Contains(swigCPtr, Rectangle.getCPtr(other));
510 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
515 [EditorBrowsable(EditorBrowsableState.Never)]
516 public object Clone() => new Rectangle(this);
518 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Rectangle obj)
520 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
523 /// This will not be public opened.
524 [EditorBrowsable(EditorBrowsableState.Never)]
525 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
527 Interop.Rectangle.DeleteRectangle(swigCPtr);
531 /// Determines whether the reference is null or the Rectangle has all 0 properties.
533 internal static bool IsNullOrZero(Rectangle rectangle) => (rectangle == null || (rectangle.top == 0 && rectangle.right == 0 && rectangle.bottom == 0 && rectangle.left == 0));