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(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
55 internal Rectangle(RectangleChangedCallback cb, int x, int y, int width, int height) : this(Interop.Rectangle.new_Rectangle__SWIG_1(x, y, width, height), true)
58 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
61 internal Rectangle(RectangleChangedCallback cb) : this()
65 internal Rectangle(RectangleChangedCallback cb, Rectangle other) : this(cb, other.x, other.y, other.width, other.height)
70 /// The type cast operator, int to Rectangle.
72 /// <param name="value">A value of int type.</param>
73 /// <returns>return a Extents instance</returns>
74 [EditorBrowsable(EditorBrowsableState.Never)]
75 public static implicit operator Rectangle(int value)
77 return new Rectangle(value, value, value, value);
80 internal delegate void RectangleChangedCallback(int x, int y, int width, int height);
81 private RectangleChangedCallback callback = null;
84 /// The x position of the rectangle.
86 /// <since_tizen> 3 </since_tizen>
93 callback?.Invoke(X, Y, Width, Height);
102 /// The Y position of the rectangle.
104 /// <since_tizen> 3 </since_tizen>
111 callback?.Invoke(X, Y, Width, Height);
120 /// The width of the rectangle.
122 /// <since_tizen> 3 </since_tizen>
129 callback?.Invoke(X, Y, Width, Height);
138 /// The height of the rectangle.
140 /// <since_tizen> 3 </since_tizen>
147 callback?.Invoke(X, Y, Width, Height);
159 Interop.Rectangle.Rectangle_x_set(swigCPtr, value);
160 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
164 int ret = Interop.Rectangle.Rectangle_x_get(swigCPtr);
165 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
174 Interop.Rectangle.Rectangle_left_set(swigCPtr, value);
175 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
179 int ret = Interop.Rectangle.Rectangle_left_get(swigCPtr);
180 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
189 Interop.Rectangle.Rectangle_y_set(swigCPtr, value);
190 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
194 int ret = Interop.Rectangle.Rectangle_y_get(swigCPtr);
195 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
204 Interop.Rectangle.Rectangle_right_set(swigCPtr, value);
205 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
209 int ret = Interop.Rectangle.Rectangle_right_get(swigCPtr);
210 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
219 Interop.Rectangle.Rectangle_width_set(swigCPtr, value);
220 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
224 int ret = Interop.Rectangle.Rectangle_width_get(swigCPtr);
225 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
234 Interop.Rectangle.Rectangle_bottom_set(swigCPtr, value);
235 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
239 int ret = Interop.Rectangle.Rectangle_bottom_get(swigCPtr);
240 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
249 Interop.Rectangle.Rectangle_height_set(swigCPtr, value);
250 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
254 int ret = Interop.Rectangle.Rectangle_height_get(swigCPtr);
255 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
264 Interop.Rectangle.Rectangle_top_set(swigCPtr, value);
265 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
269 int ret = Interop.Rectangle.Rectangle_top_get(swigCPtr);
270 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
276 /// THe Equality operator.
278 /// <param name="a">The first operand.</param>
279 /// <param name="b">The second operand.</param>
280 /// <returns>True if the boxes are exactly the same.</returns>
281 /// <since_tizen> 3 </since_tizen>
282 public static bool operator ==(Rectangle a, Rectangle b)
284 // If both are null, or both are same instance, return true.
285 if (System.Object.ReferenceEquals(a, b))
290 // If one is null, but not both, return false.
291 if (((object)a == null) || ((object)b == null))
296 // Return true if the fields match:
297 return a.X == b.X && a.Y == b.Y && a.Width == b.Width && a.Height == b.Height;
301 /// Inequality operator.
303 /// <param name="a">The first rectangle.</param>
304 /// <param name="b">The second rectangle.</param>
305 /// <returns>True if the rectangles are not identical.</returns>
306 /// <since_tizen> 3 </since_tizen>
307 public static bool operator !=(Rectangle a, Rectangle b)
313 /// Equality operator.
315 /// <param name="o">The object to compare with the current object.</param>
316 /// <returns>True if boxes are exactly same.</returns>
317 /// <since_tizen> 4 </since_tizen>
318 public override bool Equals(object o)
324 if(!(o is Rectangle))
328 Rectangle r = (Rectangle)o;
330 // Return true if the fields match:
331 return X == r.X && Y == r.Y && Width == r.Width && Height == r.Height;
335 /// Serves as the default hash function.
337 /// <returns>A hash code for the current object.</returns>
338 /// <since_tizen> 4 </since_tizen>
339 public override int GetHashCode()
341 return base.GetHashCode();
345 /// Assignment from individual values.
347 /// <param name="newX">The x coordinate.</param>
348 /// <param name="newY">The y coordinate.</param>
349 /// <param name="newWidth">The width.</param>
350 /// <param name="newHeight">The height.</param>
351 /// <since_tizen> 3 </since_tizen>
352 public void Set(int newX, int newY, int newWidth, int newHeight)
354 Interop.Rectangle.Rectangle_Set(swigCPtr, newX, newY, newWidth, newHeight);
355 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
359 /// Determines whether or not this rectangle is empty.
361 /// <returns>True if width or height are zero.</returns>
362 /// <since_tizen> 3 </since_tizen>
363 public bool IsEmpty()
365 bool ret = Interop.Rectangle.Rectangle_IsEmpty(swigCPtr);
366 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
371 /// Gets the left of the rectangle.
373 /// <returns>The left edge of the rectangle.</returns>
374 /// <since_tizen> 3 </since_tizen>
377 int ret = Interop.Rectangle.Rectangle_Left(swigCPtr);
378 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
383 /// Gets the right of the rectangle.
385 /// <returns>The right edge of the rectangle.</returns>
386 /// <since_tizen> 3 </since_tizen>
389 int ret = Interop.Rectangle.Rectangle_Right(swigCPtr);
390 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
395 /// Gets the top of the rectangle.
397 /// <returns>The top of the rectangle.</returns>
398 /// <since_tizen> 3 </since_tizen>
401 int ret = Interop.Rectangle.Rectangle_Top(swigCPtr);
402 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
407 /// Gets the bottom of the rectangle.
409 /// <returns>The bottom of the rectangle.</returns>
410 /// <since_tizen> 3 </since_tizen>
413 int ret = Interop.Rectangle.Rectangle_Bottom(swigCPtr);
414 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
419 /// Gets the area of the rectangle.
421 /// <returns>The area of the rectangle.</returns>
422 /// <since_tizen> 3 </since_tizen>
425 int ret = Interop.Rectangle.Rectangle_Area(swigCPtr);
426 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
431 /// Determines whether or not this rectangle and the specified rectangle intersect.
433 /// <param name="other">The other rectangle to test against this rectangle.</param>
434 /// <returns>True if the rectangles intersect.</returns>
435 /// <since_tizen> 3 </since_tizen>
436 public bool Intersects(Rectangle other)
438 bool ret = Interop.Rectangle.Rectangle_Intersects(swigCPtr, Rectangle.getCPtr(other));
439 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
444 /// Determines whether or not this rectangle contains the specified rectangle.
446 /// <param name="other">The other rectangle to test against this rectangle.</param>
447 /// <returns>True if the specified rectangle is contained.</returns>
448 /// <since_tizen> 3 </since_tizen>
449 public bool Contains(Rectangle other)
451 bool ret = Interop.Rectangle.Rectangle_Contains(swigCPtr, Rectangle.getCPtr(other));
452 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
456 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Rectangle obj)
458 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
461 /// This will not be public opened.
462 [EditorBrowsable(EditorBrowsableState.Never)]
463 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
465 Interop.Rectangle.delete_Rectangle(swigCPtr);
469 /// Determines whether the reference is null or the Rectangle has all 0 properties.
471 internal static bool IsNullOrZero(Rectangle rectangle) => (rectangle == null || (rectangle.top == 0 && rectangle.right == 0 && rectangle.bottom == 0 && rectangle.left == 0));