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, Rectangle other) : this(cb, other.x, other.y, other.width, other.height)
65 internal delegate void RectangleChangedCallback(int x, int y, int width, int height);
66 private RectangleChangedCallback callback = null;
69 /// The x position of the rectangle.
71 /// <since_tizen> 3 </since_tizen>
78 callback?.Invoke(X, Y, Width, Height);
87 /// The Y position of the rectangle.
89 /// <since_tizen> 3 </since_tizen>
96 callback?.Invoke(X, Y, Width, Height);
105 /// The width of the rectangle.
107 /// <since_tizen> 3 </since_tizen>
114 callback?.Invoke(X, Y, Width, Height);
123 /// The height of the rectangle.
125 /// <since_tizen> 3 </since_tizen>
132 callback?.Invoke(X, Y, Width, Height);
144 Interop.Rectangle.Rectangle_x_set(swigCPtr, value);
145 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
149 int ret = Interop.Rectangle.Rectangle_x_get(swigCPtr);
150 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
159 Interop.Rectangle.Rectangle_left_set(swigCPtr, value);
160 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
164 int ret = Interop.Rectangle.Rectangle_left_get(swigCPtr);
165 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
174 Interop.Rectangle.Rectangle_y_set(swigCPtr, value);
175 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
179 int ret = Interop.Rectangle.Rectangle_y_get(swigCPtr);
180 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
189 Interop.Rectangle.Rectangle_right_set(swigCPtr, value);
190 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
194 int ret = Interop.Rectangle.Rectangle_right_get(swigCPtr);
195 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
204 Interop.Rectangle.Rectangle_width_set(swigCPtr, value);
205 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
209 int ret = Interop.Rectangle.Rectangle_width_get(swigCPtr);
210 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
219 Interop.Rectangle.Rectangle_bottom_set(swigCPtr, value);
220 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
224 int ret = Interop.Rectangle.Rectangle_bottom_get(swigCPtr);
225 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
234 Interop.Rectangle.Rectangle_height_set(swigCPtr, value);
235 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
239 int ret = Interop.Rectangle.Rectangle_height_get(swigCPtr);
240 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
249 Interop.Rectangle.Rectangle_top_set(swigCPtr, value);
250 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
254 int ret = Interop.Rectangle.Rectangle_top_get(swigCPtr);
255 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
261 /// THe Equality operator.
263 /// <param name="a">The first operand.</param>
264 /// <param name="b">The second operand.</param>
265 /// <returns>True if the boxes are exactly the same.</returns>
266 /// <since_tizen> 3 </since_tizen>
267 public static bool operator ==(Rectangle a, Rectangle b)
269 // If both are null, or both are same instance, return true.
270 if (System.Object.ReferenceEquals(a, b))
275 // If one is null, but not both, return false.
276 if (((object)a == null) || ((object)b == null))
281 // Return true if the fields match:
282 return a.X == b.X && a.Y == b.Y && a.Width == b.Width && a.Height == b.Height;
286 /// Inequality operator.
288 /// <param name="a">The first rectangle.</param>
289 /// <param name="b">The second rectangle.</param>
290 /// <returns>True if the rectangles are not identical.</returns>
291 /// <since_tizen> 3 </since_tizen>
292 public static bool operator !=(Rectangle a, Rectangle b)
298 /// Equality operator.
300 /// <param name="o">The object to compare with the current object.</param>
301 /// <returns>True if boxes are exactly same.</returns>
302 /// <since_tizen> 4 </since_tizen>
303 public override bool Equals(object o)
309 if(!(o is Rectangle))
313 Rectangle r = (Rectangle)o;
315 // Return true if the fields match:
316 return X == r.X && Y == r.Y && Width == r.Width && Height == r.Height;
320 /// Serves as the default hash function.
322 /// <returns>A hash code for the current object.</returns>
323 /// <since_tizen> 4 </since_tizen>
324 public override int GetHashCode()
326 return base.GetHashCode();
330 /// Assignment from individual values.
332 /// <param name="newX">The x coordinate.</param>
333 /// <param name="newY">The y coordinate.</param>
334 /// <param name="newWidth">The width.</param>
335 /// <param name="newHeight">The height.</param>
336 /// <since_tizen> 3 </since_tizen>
337 public void Set(int newX, int newY, int newWidth, int newHeight)
339 Interop.Rectangle.Rectangle_Set(swigCPtr, newX, newY, newWidth, newHeight);
340 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
344 /// Determines whether or not this rectangle is empty.
346 /// <returns>True if width or height are zero.</returns>
347 /// <since_tizen> 3 </since_tizen>
348 public bool IsEmpty()
350 bool ret = Interop.Rectangle.Rectangle_IsEmpty(swigCPtr);
351 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
356 /// Gets the left of the rectangle.
358 /// <returns>The left edge of the rectangle.</returns>
359 /// <since_tizen> 3 </since_tizen>
362 int ret = Interop.Rectangle.Rectangle_Left(swigCPtr);
363 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
368 /// Gets the right of the rectangle.
370 /// <returns>The right edge of the rectangle.</returns>
371 /// <since_tizen> 3 </since_tizen>
374 int ret = Interop.Rectangle.Rectangle_Right(swigCPtr);
375 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
380 /// Gets the top of the rectangle.
382 /// <returns>The top of the rectangle.</returns>
383 /// <since_tizen> 3 </since_tizen>
386 int ret = Interop.Rectangle.Rectangle_Top(swigCPtr);
387 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
392 /// Gets the bottom of the rectangle.
394 /// <returns>The bottom of the rectangle.</returns>
395 /// <since_tizen> 3 </since_tizen>
398 int ret = Interop.Rectangle.Rectangle_Bottom(swigCPtr);
399 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
404 /// Gets the area of the rectangle.
406 /// <returns>The area of the rectangle.</returns>
407 /// <since_tizen> 3 </since_tizen>
410 int ret = Interop.Rectangle.Rectangle_Area(swigCPtr);
411 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
416 /// Determines whether or not this rectangle and the specified rectangle intersect.
418 /// <param name="other">The other rectangle to test against this rectangle.</param>
419 /// <returns>True if the rectangles intersect.</returns>
420 /// <since_tizen> 3 </since_tizen>
421 public bool Intersects(Rectangle other)
423 bool ret = Interop.Rectangle.Rectangle_Intersects(swigCPtr, Rectangle.getCPtr(other));
424 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
429 /// Determines whether or not this rectangle contains the specified rectangle.
431 /// <param name="other">The other rectangle to test against this rectangle.</param>
432 /// <returns>True if the specified rectangle is contained.</returns>
433 /// <since_tizen> 3 </since_tizen>
434 public bool Contains(Rectangle other)
436 bool ret = Interop.Rectangle.Rectangle_Contains(swigCPtr, Rectangle.getCPtr(other));
437 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
441 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Rectangle obj)
443 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
446 /// This will not be public opened.
447 [EditorBrowsable(EditorBrowsableState.Never)]
448 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
450 Interop.Rectangle.delete_Rectangle(swigCPtr);