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>
92 [Obsolete("Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Rectangle(...) constructor")]
97 Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Rectangle(...) constructor");
101 callback?.Invoke(X, Y, Width, Height);
110 /// The Y position of the rectangle.
112 /// <since_tizen> 3 </since_tizen>
113 [Obsolete("Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Rectangle(...) constructor")]
118 Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Rectangle(...) constructor");
122 callback?.Invoke(X, Y, Width, Height);
131 /// The width of the rectangle.
133 /// <since_tizen> 3 </since_tizen>
134 [Obsolete("Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Rectangle(...) constructor")]
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 height of the rectangle.
154 /// <since_tizen> 3 </since_tizen>
155 [Obsolete("Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Rectangle(...) constructor")]
160 Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Rectangle(...) constructor");
164 callback?.Invoke(X, Y, Width, Height);
176 Interop.Rectangle.Rectangle_x_set(swigCPtr, value);
177 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
181 int ret = Interop.Rectangle.Rectangle_x_get(swigCPtr);
182 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
191 Interop.Rectangle.Rectangle_left_set(swigCPtr, value);
192 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
196 int ret = Interop.Rectangle.Rectangle_left_get(swigCPtr);
197 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
206 Interop.Rectangle.Rectangle_y_set(swigCPtr, value);
207 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
211 int ret = Interop.Rectangle.Rectangle_y_get(swigCPtr);
212 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
221 Interop.Rectangle.Rectangle_right_set(swigCPtr, value);
222 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
226 int ret = Interop.Rectangle.Rectangle_right_get(swigCPtr);
227 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
236 Interop.Rectangle.Rectangle_width_set(swigCPtr, value);
237 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
241 int ret = Interop.Rectangle.Rectangle_width_get(swigCPtr);
242 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
251 Interop.Rectangle.Rectangle_bottom_set(swigCPtr, value);
252 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
256 int ret = Interop.Rectangle.Rectangle_bottom_get(swigCPtr);
257 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
266 Interop.Rectangle.Rectangle_height_set(swigCPtr, value);
267 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
271 int ret = Interop.Rectangle.Rectangle_height_get(swigCPtr);
272 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
281 Interop.Rectangle.Rectangle_top_set(swigCPtr, value);
282 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
286 int ret = Interop.Rectangle.Rectangle_top_get(swigCPtr);
287 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
293 /// THe Equality operator.
295 /// <param name="a">The first operand.</param>
296 /// <param name="b">The second operand.</param>
297 /// <returns>True if the boxes are exactly the same.</returns>
298 /// <since_tizen> 3 </since_tizen>
299 public static bool operator ==(Rectangle a, Rectangle b)
301 // If both are null, or both are same instance, return true.
302 if (System.Object.ReferenceEquals(a, b))
307 // If one is null, but not both, return false.
308 if (((object)a == null) || ((object)b == null))
313 // Return true if the fields match:
314 return a.X == b.X && a.Y == b.Y && a.Width == b.Width && a.Height == b.Height;
318 /// Inequality operator.
320 /// <param name="a">The first rectangle.</param>
321 /// <param name="b">The second rectangle.</param>
322 /// <returns>True if the rectangles are not identical.</returns>
323 /// <since_tizen> 3 </since_tizen>
324 public static bool operator !=(Rectangle a, Rectangle b)
330 /// Equality operator.
332 /// <param name="o">The object to compare with the current object.</param>
333 /// <returns>True if boxes are exactly same.</returns>
334 /// <since_tizen> 4 </since_tizen>
335 public override bool Equals(object o)
341 if (!(o is Rectangle))
345 Rectangle r = (Rectangle)o;
347 // Return true if the fields match:
348 return X == r.X && Y == r.Y && Width == r.Width && Height == r.Height;
352 /// Serves as the default hash function.
354 /// <returns>A hash code for the current object.</returns>
355 /// <since_tizen> 4 </since_tizen>
356 public override int GetHashCode()
358 return base.GetHashCode();
362 /// Assignment from individual values.
364 /// <param name="newX">The x coordinate.</param>
365 /// <param name="newY">The y coordinate.</param>
366 /// <param name="newWidth">The width.</param>
367 /// <param name="newHeight">The height.</param>
368 /// <since_tizen> 3 </since_tizen>
369 public void Set(int newX, int newY, int newWidth, int newHeight)
371 Interop.Rectangle.Rectangle_Set(swigCPtr, newX, newY, newWidth, newHeight);
372 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
376 /// Determines whether or not this rectangle is empty.
378 /// <returns>True if width or height are zero.</returns>
379 /// <since_tizen> 3 </since_tizen>
380 public bool IsEmpty()
382 bool ret = Interop.Rectangle.Rectangle_IsEmpty(swigCPtr);
383 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
388 /// Gets the left of the rectangle.
390 /// <returns>The left edge of the rectangle.</returns>
391 /// <since_tizen> 3 </since_tizen>
394 int ret = Interop.Rectangle.Rectangle_Left(swigCPtr);
395 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
400 /// Gets the right of the rectangle.
402 /// <returns>The right edge of the rectangle.</returns>
403 /// <since_tizen> 3 </since_tizen>
406 int ret = Interop.Rectangle.Rectangle_Right(swigCPtr);
407 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
412 /// Gets the top of the rectangle.
414 /// <returns>The top of the rectangle.</returns>
415 /// <since_tizen> 3 </since_tizen>
418 int ret = Interop.Rectangle.Rectangle_Top(swigCPtr);
419 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
424 /// Gets the bottom of the rectangle.
426 /// <returns>The bottom of the rectangle.</returns>
427 /// <since_tizen> 3 </since_tizen>
430 int ret = Interop.Rectangle.Rectangle_Bottom(swigCPtr);
431 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
436 /// Gets the area of the rectangle.
438 /// <returns>The area of the rectangle.</returns>
439 /// <since_tizen> 3 </since_tizen>
442 int ret = Interop.Rectangle.Rectangle_Area(swigCPtr);
443 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
448 /// Determines whether or not this rectangle and the specified rectangle intersect.
450 /// <param name="other">The other rectangle to test against this rectangle.</param>
451 /// <returns>True if the rectangles intersect.</returns>
452 /// <since_tizen> 3 </since_tizen>
453 public bool Intersects(Rectangle other)
455 bool ret = Interop.Rectangle.Rectangle_Intersects(swigCPtr, Rectangle.getCPtr(other));
456 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
461 /// Determines whether or not this rectangle contains the specified rectangle.
463 /// <param name="other">The other rectangle to test against this rectangle.</param>
464 /// <returns>True if the specified rectangle is contained.</returns>
465 /// <since_tizen> 3 </since_tizen>
466 public bool Contains(Rectangle other)
468 bool ret = Interop.Rectangle.Rectangle_Contains(swigCPtr, Rectangle.getCPtr(other));
469 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
474 [EditorBrowsable(EditorBrowsableState.Never)]
475 public object Clone() => new Rectangle(this);
477 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Rectangle obj)
479 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
482 /// This will not be public opened.
483 [EditorBrowsable(EditorBrowsableState.Never)]
484 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
486 Interop.Rectangle.delete_Rectangle(swigCPtr);
490 /// Determines whether the reference is null or the Rectangle has all 0 properties.
492 internal static bool IsNullOrZero(Rectangle rectangle) => (rectangle == null || (rectangle.top == 0 && rectangle.right == 0 && rectangle.bottom == 0 && rectangle.left == 0));