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 Tizen.NUI.Binding;
23 /// The Rectangle class.
25 /// <since_tizen> 3 </since_tizen>
26 [TypeConverter(typeof(RectangleTypeConverter))]
27 public class Rectangle : Disposable
32 /// <since_tizen> 3 </since_tizen>
33 protected bool swigCMemOwn;
35 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
40 /// <since_tizen> 3 </since_tizen>
41 public Rectangle() : this(Interop.Rectangle.new_Rectangle__SWIG_0(), true)
43 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
49 /// <param name="x">The x coordinate (or left).</param>
50 /// <param name="y">The y coordinate (or right).</param>
51 /// <param name="width">The width (or bottom).</param>
52 /// <param name="height">The height (or top).</param>
53 /// <since_tizen> 3 </since_tizen>
54 public Rectangle(int x, int y, int width, int height) : this(Interop.Rectangle.new_Rectangle__SWIG_1(x, y, width, height), true)
56 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
59 internal Rectangle(global::System.IntPtr cPtr, bool cMemoryOwn)
61 swigCMemOwn = cMemoryOwn;
62 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
65 internal Rectangle(RectangleChangedCallback cb, int x, int y, int width, int height) : this(Interop.Rectangle.new_Rectangle__SWIG_1(x, y, width, height), true)
68 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
70 internal delegate void RectangleChangedCallback(int x, int y, int width, int height);
71 private RectangleChangedCallback callback = null;
74 /// The x position of the rectangle.
76 /// <since_tizen> 3 </since_tizen>
83 callback?.Invoke(X, Y, Width, Height);
92 /// The Y position of the rectangle.
94 /// <since_tizen> 3 </since_tizen>
101 callback?.Invoke(X, Y, Width, Height);
110 /// The width of the rectangle.
112 /// <since_tizen> 3 </since_tizen>
119 callback?.Invoke(X, Y, Width, Height);
128 /// The height of the rectangle.
130 /// <since_tizen> 3 </since_tizen>
137 callback?.Invoke(X, Y, Width, Height);
149 Interop.Rectangle.Rectangle_x_set(swigCPtr, value);
150 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
154 int ret = Interop.Rectangle.Rectangle_x_get(swigCPtr);
155 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
164 Interop.Rectangle.Rectangle_left_set(swigCPtr, value);
165 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
169 int ret = Interop.Rectangle.Rectangle_left_get(swigCPtr);
170 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
179 Interop.Rectangle.Rectangle_y_set(swigCPtr, value);
180 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
184 int ret = Interop.Rectangle.Rectangle_y_get(swigCPtr);
185 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
194 Interop.Rectangle.Rectangle_right_set(swigCPtr, value);
195 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
199 int ret = Interop.Rectangle.Rectangle_right_get(swigCPtr);
200 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
209 Interop.Rectangle.Rectangle_width_set(swigCPtr, value);
210 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
214 int ret = Interop.Rectangle.Rectangle_width_get(swigCPtr);
215 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
224 Interop.Rectangle.Rectangle_bottom_set(swigCPtr, value);
225 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
229 int ret = Interop.Rectangle.Rectangle_bottom_get(swigCPtr);
230 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
239 Interop.Rectangle.Rectangle_height_set(swigCPtr, value);
240 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
244 int ret = Interop.Rectangle.Rectangle_height_get(swigCPtr);
245 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
254 Interop.Rectangle.Rectangle_top_set(swigCPtr, value);
255 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
259 int ret = Interop.Rectangle.Rectangle_top_get(swigCPtr);
260 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
266 /// THe Equality operator.
268 /// <param name="a">The first operand.</param>
269 /// <param name="b">The second operand.</param>
270 /// <returns>True if the boxes are exactly the same.</returns>
271 /// <since_tizen> 3 </since_tizen>
272 public static bool operator ==(Rectangle a, Rectangle b)
274 // If both are null, or both are same instance, return true.
275 if (System.Object.ReferenceEquals(a, b))
280 // If one is null, but not both, return false.
281 if (((object)a == null) || ((object)b == null))
286 // Return true if the fields match:
287 return a.X == b.X && a.Y == b.Y && a.Width == b.Width && a.Height == b.Height;
291 /// Inequality operator.
293 /// <param name="a">The first rectangle.</param>
294 /// <param name="b">The second rectangle.</param>
295 /// <returns>True if the rectangles are not identical.</returns>
296 /// <since_tizen> 3 </since_tizen>
297 public static bool operator !=(Rectangle a, Rectangle b)
303 /// Equality operator.
305 /// <param name="o">The object to compare with the current object.</param>
306 /// <returns>True if boxes are exactly same.</returns>
307 /// <since_tizen> 4 </since_tizen>
308 public override bool Equals(object o)
314 if(!(o is Rectangle))
318 Rectangle r = (Rectangle)o;
320 // Return true if the fields match:
321 return X == r.X && Y == r.Y && Width == r.Width && Height == r.Height;
325 /// Serves as the default hash function.
327 /// <returns>A hash code for the current object.</returns>
328 /// <since_tizen> 4 </since_tizen>
329 public override int GetHashCode()
331 return base.GetHashCode();
335 /// Assignment from individual values.
337 /// <param name="newX">The x coordinate.</param>
338 /// <param name="newY">The y coordinate.</param>
339 /// <param name="newWidth">The width.</param>
340 /// <param name="newHeight">The height.</param>
341 /// <since_tizen> 3 </since_tizen>
342 public void Set(int newX, int newY, int newWidth, int newHeight)
344 Interop.Rectangle.Rectangle_Set(swigCPtr, newX, newY, newWidth, newHeight);
345 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
349 /// Determines whether or not this rectangle is empty.
351 /// <returns>True if width or height are zero.</returns>
352 /// <since_tizen> 3 </since_tizen>
353 public bool IsEmpty()
355 bool ret = Interop.Rectangle.Rectangle_IsEmpty(swigCPtr);
356 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
361 /// Gets the left of the rectangle.
363 /// <returns>The left edge of the rectangle.</returns>
364 /// <since_tizen> 3 </since_tizen>
367 int ret = Interop.Rectangle.Rectangle_Left(swigCPtr);
368 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
373 /// Gets the right of the rectangle.
375 /// <returns>The right edge of the rectangle.</returns>
376 /// <since_tizen> 3 </since_tizen>
379 int ret = Interop.Rectangle.Rectangle_Right(swigCPtr);
380 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
385 /// Gets the top of the rectangle.
387 /// <returns>The top of the rectangle.</returns>
388 /// <since_tizen> 3 </since_tizen>
391 int ret = Interop.Rectangle.Rectangle_Top(swigCPtr);
392 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
397 /// Gets the bottom of the rectangle.
399 /// <returns>The bottom of the rectangle.</returns>
400 /// <since_tizen> 3 </since_tizen>
403 int ret = Interop.Rectangle.Rectangle_Bottom(swigCPtr);
404 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
409 /// Gets the area of the rectangle.
411 /// <returns>The area of the rectangle.</returns>
412 /// <since_tizen> 3 </since_tizen>
415 int ret = Interop.Rectangle.Rectangle_Area(swigCPtr);
416 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
421 /// Determines whether or not this rectangle and the specified rectangle intersect.
423 /// <param name="other">The other rectangle to test against this rectangle.</param>
424 /// <returns>True if the rectangles intersect.</returns>
425 /// <since_tizen> 3 </since_tizen>
426 public bool Intersects(Rectangle other)
428 bool ret = Interop.Rectangle.Rectangle_Intersects(swigCPtr, Rectangle.getCPtr(other));
429 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
434 /// Determines whether or not this rectangle contains the specified rectangle.
436 /// <param name="other">The other rectangle to test against this rectangle.</param>
437 /// <returns>True if the specified rectangle is contained.</returns>
438 /// <since_tizen> 3 </since_tizen>
439 public bool Contains(Rectangle other)
441 bool ret = Interop.Rectangle.Rectangle_Contains(swigCPtr, Rectangle.getCPtr(other));
442 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
446 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Rectangle obj)
448 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
454 /// <since_tizen> 3 </since_tizen>
455 protected override void Dispose(DisposeTypes type)
462 //Release your own unmanaged resources here.
463 //You should not access any managed member here except static instance.
464 //because the execution order of Finalizes is non-deterministic.
466 if (swigCPtr.Handle != global::System.IntPtr.Zero)
471 Interop.Rectangle.delete_Rectangle(swigCPtr);
473 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);