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();
60 internal delegate void RectangleChangedCallback(int x, int y, int width, int height);
61 private RectangleChangedCallback callback = null;
64 /// The x position of the rectangle.
66 /// <since_tizen> 3 </since_tizen>
73 callback?.Invoke(X, Y, Width, Height);
82 /// The Y position of the rectangle.
84 /// <since_tizen> 3 </since_tizen>
91 callback?.Invoke(X, Y, Width, Height);
100 /// The width of the rectangle.
102 /// <since_tizen> 3 </since_tizen>
109 callback?.Invoke(X, Y, Width, Height);
118 /// The height of the rectangle.
120 /// <since_tizen> 3 </since_tizen>
127 callback?.Invoke(X, Y, Width, Height);
139 Interop.Rectangle.Rectangle_x_set(swigCPtr, value);
140 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
144 int ret = Interop.Rectangle.Rectangle_x_get(swigCPtr);
145 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
154 Interop.Rectangle.Rectangle_left_set(swigCPtr, value);
155 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
159 int ret = Interop.Rectangle.Rectangle_left_get(swigCPtr);
160 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
169 Interop.Rectangle.Rectangle_y_set(swigCPtr, value);
170 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
174 int ret = Interop.Rectangle.Rectangle_y_get(swigCPtr);
175 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
184 Interop.Rectangle.Rectangle_right_set(swigCPtr, value);
185 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
189 int ret = Interop.Rectangle.Rectangle_right_get(swigCPtr);
190 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
199 Interop.Rectangle.Rectangle_width_set(swigCPtr, value);
200 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
204 int ret = Interop.Rectangle.Rectangle_width_get(swigCPtr);
205 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
214 Interop.Rectangle.Rectangle_bottom_set(swigCPtr, value);
215 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
219 int ret = Interop.Rectangle.Rectangle_bottom_get(swigCPtr);
220 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
229 Interop.Rectangle.Rectangle_height_set(swigCPtr, value);
230 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
234 int ret = Interop.Rectangle.Rectangle_height_get(swigCPtr);
235 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
244 Interop.Rectangle.Rectangle_top_set(swigCPtr, value);
245 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
249 int ret = Interop.Rectangle.Rectangle_top_get(swigCPtr);
250 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
256 /// THe Equality operator.
258 /// <param name="a">The first operand.</param>
259 /// <param name="b">The second operand.</param>
260 /// <returns>True if the boxes are exactly the same.</returns>
261 /// <since_tizen> 3 </since_tizen>
262 public static bool operator ==(Rectangle a, Rectangle b)
264 // If both are null, or both are same instance, return true.
265 if (System.Object.ReferenceEquals(a, b))
270 // If one is null, but not both, return false.
271 if (((object)a == null) || ((object)b == null))
276 // Return true if the fields match:
277 return a.X == b.X && a.Y == b.Y && a.Width == b.Width && a.Height == b.Height;
281 /// Inequality operator.
283 /// <param name="a">The first rectangle.</param>
284 /// <param name="b">The second rectangle.</param>
285 /// <returns>True if the rectangles are not identical.</returns>
286 /// <since_tizen> 3 </since_tizen>
287 public static bool operator !=(Rectangle a, Rectangle b)
293 /// Equality operator.
295 /// <param name="o">The object to compare with the current object.</param>
296 /// <returns>True if boxes are exactly same.</returns>
297 /// <since_tizen> 4 </since_tizen>
298 public override bool Equals(object o)
304 if(!(o is Rectangle))
308 Rectangle r = (Rectangle)o;
310 // Return true if the fields match:
311 return X == r.X && Y == r.Y && Width == r.Width && Height == r.Height;
315 /// Serves as the default hash function.
317 /// <returns>A hash code for the current object.</returns>
318 /// <since_tizen> 4 </since_tizen>
319 public override int GetHashCode()
321 return base.GetHashCode();
325 /// Assignment from individual values.
327 /// <param name="newX">The x coordinate.</param>
328 /// <param name="newY">The y coordinate.</param>
329 /// <param name="newWidth">The width.</param>
330 /// <param name="newHeight">The height.</param>
331 /// <since_tizen> 3 </since_tizen>
332 public void Set(int newX, int newY, int newWidth, int newHeight)
334 Interop.Rectangle.Rectangle_Set(swigCPtr, newX, newY, newWidth, newHeight);
335 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
339 /// Determines whether or not this rectangle is empty.
341 /// <returns>True if width or height are zero.</returns>
342 /// <since_tizen> 3 </since_tizen>
343 public bool IsEmpty()
345 bool ret = Interop.Rectangle.Rectangle_IsEmpty(swigCPtr);
346 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
351 /// Gets the left of the rectangle.
353 /// <returns>The left edge of the rectangle.</returns>
354 /// <since_tizen> 3 </since_tizen>
357 int ret = Interop.Rectangle.Rectangle_Left(swigCPtr);
358 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
363 /// Gets the right of the rectangle.
365 /// <returns>The right edge of the rectangle.</returns>
366 /// <since_tizen> 3 </since_tizen>
369 int ret = Interop.Rectangle.Rectangle_Right(swigCPtr);
370 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
375 /// Gets the top of the rectangle.
377 /// <returns>The top of the rectangle.</returns>
378 /// <since_tizen> 3 </since_tizen>
381 int ret = Interop.Rectangle.Rectangle_Top(swigCPtr);
382 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
387 /// Gets the bottom of the rectangle.
389 /// <returns>The bottom of the rectangle.</returns>
390 /// <since_tizen> 3 </since_tizen>
393 int ret = Interop.Rectangle.Rectangle_Bottom(swigCPtr);
394 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
399 /// Gets the area of the rectangle.
401 /// <returns>The area of the rectangle.</returns>
402 /// <since_tizen> 3 </since_tizen>
405 int ret = Interop.Rectangle.Rectangle_Area(swigCPtr);
406 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
411 /// Determines whether or not this rectangle and the specified rectangle intersect.
413 /// <param name="other">The other rectangle to test against this rectangle.</param>
414 /// <returns>True if the rectangles intersect.</returns>
415 /// <since_tizen> 3 </since_tizen>
416 public bool Intersects(Rectangle other)
418 bool ret = Interop.Rectangle.Rectangle_Intersects(swigCPtr, Rectangle.getCPtr(other));
419 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
424 /// Determines whether or not this rectangle contains the specified rectangle.
426 /// <param name="other">The other rectangle to test against this rectangle.</param>
427 /// <returns>True if the specified rectangle is contained.</returns>
428 /// <since_tizen> 3 </since_tizen>
429 public bool Contains(Rectangle other)
431 bool ret = Interop.Rectangle.Rectangle_Contains(swigCPtr, Rectangle.getCPtr(other));
432 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
436 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Rectangle obj)
438 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
441 /// This will not be public opened.
442 [EditorBrowsable(EditorBrowsableState.Never)]
443 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
445 Interop.Rectangle.delete_Rectangle(swigCPtr);