2 * Copyright(c) 2017 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 : global::System.IDisposable
32 /// <since_tizen> 3 </since_tizen>
33 protected bool swigCMemOwn;
36 /// A Flat to check if it is already disposed.
38 /// <since_tizen> 3 </since_tizen>
39 protected bool disposed = false;
41 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
43 //A Flag to check who called Dispose(). (By User or DisposeQueue)
44 private bool isDisposeQueued = false;
49 /// <since_tizen> 3 </since_tizen>
50 public Rectangle() : this(NDalicPINVOKE.new_Rectangle__SWIG_0(), true)
52 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
58 /// <param name="x">The x coordinate (or left).</param>
59 /// <param name="y">The y coordinate (or right).</param>
60 /// <param name="width">The width (or bottom).</param>
61 /// <param name="height">The height (or top).</param>
62 /// <since_tizen> 3 </since_tizen>
63 public Rectangle(int x, int y, int width, int height) : this(NDalicPINVOKE.new_Rectangle__SWIG_1(x, y, width, height), true)
65 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
68 internal Rectangle(global::System.IntPtr cPtr, bool cMemoryOwn)
70 swigCMemOwn = cMemoryOwn;
71 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
77 /// <since_tizen> 3 </since_tizen>
82 isDisposeQueued = true;
83 DisposeQueue.Instance.Add(this);
88 /// The x position of the rectangle.
90 /// <since_tizen> 3 </since_tizen>
104 /// The Y position of the rectangle.
106 /// <since_tizen> 3 </since_tizen>
120 /// The width of the rectangle.
122 /// <since_tizen> 3 </since_tizen>
136 /// The height of the rectangle.
138 /// <since_tizen> 3 </since_tizen>
155 NDalicPINVOKE.Rectangle_x_set(swigCPtr, value);
156 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
160 int ret = NDalicPINVOKE.Rectangle_x_get(swigCPtr);
161 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
170 NDalicPINVOKE.Rectangle_left_set(swigCPtr, value);
171 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
175 int ret = NDalicPINVOKE.Rectangle_left_get(swigCPtr);
176 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
185 NDalicPINVOKE.Rectangle_y_set(swigCPtr, value);
186 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
190 int ret = NDalicPINVOKE.Rectangle_y_get(swigCPtr);
191 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
200 NDalicPINVOKE.Rectangle_right_set(swigCPtr, value);
201 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
205 int ret = NDalicPINVOKE.Rectangle_right_get(swigCPtr);
206 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
215 NDalicPINVOKE.Rectangle_width_set(swigCPtr, value);
216 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
220 int ret = NDalicPINVOKE.Rectangle_width_get(swigCPtr);
221 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
230 NDalicPINVOKE.Rectangle_bottom_set(swigCPtr, value);
231 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
235 int ret = NDalicPINVOKE.Rectangle_bottom_get(swigCPtr);
236 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
245 NDalicPINVOKE.Rectangle_height_set(swigCPtr, value);
246 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
250 int ret = NDalicPINVOKE.Rectangle_height_get(swigCPtr);
251 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
260 NDalicPINVOKE.Rectangle_top_set(swigCPtr, value);
261 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
265 int ret = NDalicPINVOKE.Rectangle_top_get(swigCPtr);
266 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
272 /// THe Equality operator.
274 /// <param name="a">The first operand.</param>
275 /// <param name="b">The second operand.</param>
276 /// <returns>True if the boxes are exactly the same.</returns>
277 /// <since_tizen> 3 </since_tizen>
278 public static bool operator ==(Rectangle a, Rectangle b)
280 // If both are null, or both are same instance, return true.
281 if (System.Object.ReferenceEquals(a, b))
286 // If one is null, but not both, return false.
287 if (((object)a == null) || ((object)b == null))
292 // Return true if the fields match:
293 return a.X == b.X && a.Y == b.Y && a.Width == b.Width && a.Height == b.Height;
297 /// Inequality operator.
299 /// <param name="a">The first rectangle.</param>
300 /// <param name="b">The second rectangle.</param>
301 /// <returns>True if the rectangles are not identical.</returns>
302 /// <since_tizen> 3 </since_tizen>
303 public static bool operator !=(Rectangle a, Rectangle b)
311 /// <since_tizen> 3 </since_tizen>
312 public void Dispose()
314 //Throw excpetion if Dispose() is called in separate thread.
315 if (!Window.IsInstalled())
317 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
322 Dispose(DisposeTypes.Implicit);
326 Dispose(DisposeTypes.Explicit);
327 System.GC.SuppressFinalize(this);
332 /// Equality operator.
334 /// <param name="o">The object to compare with the current object.</param>
335 /// <returns>True if boxes are exactly same.</returns>
336 /// <since_tizen> 4 </since_tizen>
337 public override bool Equals(object o)
343 if(!(o is Rectangle))
347 Rectangle r = (Rectangle)o;
349 // Return true if the fields match:
350 return X == r.X && Y == r.Y && Width == r.Width && Height == r.Height;
354 /// Serves as the default hash function.
356 /// <returns>A hash code for the current object.</returns>
357 /// <since_tizen> 4 </since_tizen>
358 public override int GetHashCode()
360 return base.GetHashCode();
364 /// Assignment from individual values.
366 /// <param name="newX">The x coordinate.</param>
367 /// <param name="newY">The y coordinate.</param>
368 /// <param name="newWidth">The width.</param>
369 /// <param name="newHeight">The height.</param>
370 /// <since_tizen> 3 </since_tizen>
371 public void Set(int newX, int newY, int newWidth, int newHeight)
373 NDalicPINVOKE.Rectangle_Set(swigCPtr, newX, newY, newWidth, newHeight);
374 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
378 /// Determines whether or not this rectangle is empty.
380 /// <returns>True if width or height are zero.</returns>
381 /// <since_tizen> 3 </since_tizen>
382 public bool IsEmpty()
384 bool ret = NDalicPINVOKE.Rectangle_IsEmpty(swigCPtr);
385 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
390 /// Gets the left of the rectangle.
392 /// <returns>The left edge of the rectangle.</returns>
393 /// <since_tizen> 3 </since_tizen>
396 int ret = NDalicPINVOKE.Rectangle_Left(swigCPtr);
397 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
402 /// Gets the right of the rectangle.
404 /// <returns>The right edge of the rectangle.</returns>
405 /// <since_tizen> 3 </since_tizen>
408 int ret = NDalicPINVOKE.Rectangle_Right(swigCPtr);
409 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
414 /// Gets the top of the rectangle.
416 /// <returns>The top of the rectangle.</returns>
417 /// <since_tizen> 3 </since_tizen>
420 int ret = NDalicPINVOKE.Rectangle_Top(swigCPtr);
421 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
426 /// Gets the bottom of the rectangle.
428 /// <returns>The bottom of the rectangle.</returns>
429 /// <since_tizen> 3 </since_tizen>
432 int ret = NDalicPINVOKE.Rectangle_Bottom(swigCPtr);
433 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
438 /// Gets the area of the rectangle.
440 /// <returns>The area of the rectangle.</returns>
441 /// <since_tizen> 3 </since_tizen>
444 int ret = NDalicPINVOKE.Rectangle_Area(swigCPtr);
445 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
450 /// Determines whether or not this rectangle and the specified rectangle intersect.
452 /// <param name="other">The other rectangle to test against this rectangle.</param>
453 /// <returns>True if the rectangles intersect.</returns>
454 /// <since_tizen> 3 </since_tizen>
455 public bool Intersects(Rectangle other)
457 bool ret = NDalicPINVOKE.Rectangle_Intersects(swigCPtr, Rectangle.getCPtr(other));
458 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
463 /// Determines whether or not this rectangle contains the specified rectangle.
465 /// <param name="other">The other rectangle to test against this rectangle.</param>
466 /// <returns>True if the specified rectangle is contained.</returns>
467 /// <since_tizen> 3 </since_tizen>
468 public bool Contains(Rectangle other)
470 bool ret = NDalicPINVOKE.Rectangle_Contains(swigCPtr, Rectangle.getCPtr(other));
471 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
475 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Rectangle obj)
477 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
483 /// <since_tizen> 3 </since_tizen>
484 protected virtual void Dispose(DisposeTypes type)
491 if (type == DisposeTypes.Explicit)
494 //Release your own managed resources here.
495 //You should release all of your own disposable objects here.
498 //Release your own unmanaged resources here.
499 //You should not access any managed member here except static instance.
500 //because the execution order of Finalizes is non-deterministic.
502 if (swigCPtr.Handle != global::System.IntPtr.Zero)
507 NDalicPINVOKE.delete_Rectangle(swigCPtr);
509 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);