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)
69 internal delegate void RectangleChangedCallback(int x, int y, int width, int height);
70 private RectangleChangedCallback callback = null;
73 /// The x position of the rectangle.
75 /// <since_tizen> 3 </since_tizen>
82 callback?.Invoke(X, Y, Width, Height);
91 /// The Y position of the rectangle.
93 /// <since_tizen> 3 </since_tizen>
100 callback?.Invoke(X, Y, Width, Height);
109 /// The width of the rectangle.
111 /// <since_tizen> 3 </since_tizen>
118 callback?.Invoke(X, Y, Width, Height);
127 /// The height of the rectangle.
129 /// <since_tizen> 3 </since_tizen>
136 callback?.Invoke(X, Y, Width, Height);
148 Interop.Rectangle.Rectangle_x_set(swigCPtr, value);
149 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
153 int ret = Interop.Rectangle.Rectangle_x_get(swigCPtr);
154 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
163 Interop.Rectangle.Rectangle_left_set(swigCPtr, value);
164 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
168 int ret = Interop.Rectangle.Rectangle_left_get(swigCPtr);
169 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
178 Interop.Rectangle.Rectangle_y_set(swigCPtr, value);
179 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
183 int ret = Interop.Rectangle.Rectangle_y_get(swigCPtr);
184 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
193 Interop.Rectangle.Rectangle_right_set(swigCPtr, value);
194 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
198 int ret = Interop.Rectangle.Rectangle_right_get(swigCPtr);
199 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
208 Interop.Rectangle.Rectangle_width_set(swigCPtr, value);
209 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
213 int ret = Interop.Rectangle.Rectangle_width_get(swigCPtr);
214 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
223 Interop.Rectangle.Rectangle_bottom_set(swigCPtr, value);
224 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
228 int ret = Interop.Rectangle.Rectangle_bottom_get(swigCPtr);
229 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
238 Interop.Rectangle.Rectangle_height_set(swigCPtr, value);
239 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
243 int ret = Interop.Rectangle.Rectangle_height_get(swigCPtr);
244 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
253 Interop.Rectangle.Rectangle_top_set(swigCPtr, value);
254 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
258 int ret = Interop.Rectangle.Rectangle_top_get(swigCPtr);
259 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
265 /// THe Equality operator.
267 /// <param name="a">The first operand.</param>
268 /// <param name="b">The second operand.</param>
269 /// <returns>True if the boxes are exactly the same.</returns>
270 /// <since_tizen> 3 </since_tizen>
271 public static bool operator ==(Rectangle a, Rectangle b)
273 // If both are null, or both are same instance, return true.
274 if (System.Object.ReferenceEquals(a, b))
279 // If one is null, but not both, return false.
280 if (((object)a == null) || ((object)b == null))
285 // Return true if the fields match:
286 return a.X == b.X && a.Y == b.Y && a.Width == b.Width && a.Height == b.Height;
290 /// Inequality operator.
292 /// <param name="a">The first rectangle.</param>
293 /// <param name="b">The second rectangle.</param>
294 /// <returns>True if the rectangles are not identical.</returns>
295 /// <since_tizen> 3 </since_tizen>
296 public static bool operator !=(Rectangle a, Rectangle b)
302 /// Equality operator.
304 /// <param name="o">The object to compare with the current object.</param>
305 /// <returns>True if boxes are exactly same.</returns>
306 /// <since_tizen> 4 </since_tizen>
307 public override bool Equals(object o)
313 if(!(o is Rectangle))
317 Rectangle r = (Rectangle)o;
319 // Return true if the fields match:
320 return X == r.X && Y == r.Y && Width == r.Width && Height == r.Height;
324 /// Serves as the default hash function.
326 /// <returns>A hash code for the current object.</returns>
327 /// <since_tizen> 4 </since_tizen>
328 public override int GetHashCode()
330 return base.GetHashCode();
334 /// Assignment from individual values.
336 /// <param name="newX">The x coordinate.</param>
337 /// <param name="newY">The y coordinate.</param>
338 /// <param name="newWidth">The width.</param>
339 /// <param name="newHeight">The height.</param>
340 /// <since_tizen> 3 </since_tizen>
341 public void Set(int newX, int newY, int newWidth, int newHeight)
343 Interop.Rectangle.Rectangle_Set(swigCPtr, newX, newY, newWidth, newHeight);
344 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
348 /// Determines whether or not this rectangle is empty.
350 /// <returns>True if width or height are zero.</returns>
351 /// <since_tizen> 3 </since_tizen>
352 public bool IsEmpty()
354 bool ret = Interop.Rectangle.Rectangle_IsEmpty(swigCPtr);
355 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
360 /// Gets the left of the rectangle.
362 /// <returns>The left edge of the rectangle.</returns>
363 /// <since_tizen> 3 </since_tizen>
366 int ret = Interop.Rectangle.Rectangle_Left(swigCPtr);
367 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
372 /// Gets the right of the rectangle.
374 /// <returns>The right edge of the rectangle.</returns>
375 /// <since_tizen> 3 </since_tizen>
378 int ret = Interop.Rectangle.Rectangle_Right(swigCPtr);
379 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
384 /// Gets the top of the rectangle.
386 /// <returns>The top of the rectangle.</returns>
387 /// <since_tizen> 3 </since_tizen>
390 int ret = Interop.Rectangle.Rectangle_Top(swigCPtr);
391 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
396 /// Gets the bottom of the rectangle.
398 /// <returns>The bottom of the rectangle.</returns>
399 /// <since_tizen> 3 </since_tizen>
402 int ret = Interop.Rectangle.Rectangle_Bottom(swigCPtr);
403 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
408 /// Gets the area of the rectangle.
410 /// <returns>The area of the rectangle.</returns>
411 /// <since_tizen> 3 </since_tizen>
414 int ret = Interop.Rectangle.Rectangle_Area(swigCPtr);
415 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
420 /// Determines whether or not this rectangle and the specified rectangle intersect.
422 /// <param name="other">The other rectangle to test against this rectangle.</param>
423 /// <returns>True if the rectangles intersect.</returns>
424 /// <since_tizen> 3 </since_tizen>
425 public bool Intersects(Rectangle other)
427 bool ret = Interop.Rectangle.Rectangle_Intersects(swigCPtr, Rectangle.getCPtr(other));
428 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
433 /// Determines whether or not this rectangle contains the specified rectangle.
435 /// <param name="other">The other rectangle to test against this rectangle.</param>
436 /// <returns>True if the specified rectangle is contained.</returns>
437 /// <since_tizen> 3 </since_tizen>
438 public bool Contains(Rectangle other)
440 bool ret = Interop.Rectangle.Rectangle_Contains(swigCPtr, Rectangle.getCPtr(other));
441 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
445 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Rectangle obj)
447 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
450 /// This will not be public opened.
451 [EditorBrowsable(EditorBrowsableState.Never)]
452 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
454 Interop.Rectangle.delete_Rectangle(swigCPtr);
458 /// Determines whether the reference is null or the Rectangle has all 0 properties.
460 internal static bool IsNullOrZero(Rectangle rectangle) => (rectangle == null || (rectangle.top == 0 && rectangle.right == 0 && rectangle.bottom == 0 && rectangle.left == 0));