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.
22 /// The Rectangle class.
24 /// <since_tizen> 3 </since_tizen>
25 public class Rectangle : global::System.IDisposable
30 /// <since_tizen> 3 </since_tizen>
31 protected bool swigCMemOwn;
34 /// A Flat to check if it is already disposed.
36 /// <since_tizen> 3 </since_tizen>
37 protected bool disposed = false;
39 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
41 //A Flag to check who called Dispose(). (By User or DisposeQueue)
42 private bool isDisposeQueued = false;
47 /// <since_tizen> 3 </since_tizen>
48 public Rectangle() : this(Interop.Rectangle.new_Rectangle__SWIG_0(), true)
50 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
56 /// <param name="x">The x coordinate (or left).</param>
57 /// <param name="y">The y coordinate (or right).</param>
58 /// <param name="width">The width (or bottom).</param>
59 /// <param name="height">The height (or top).</param>
60 /// <since_tizen> 3 </since_tizen>
61 public Rectangle(int x, int y, int width, int height) : this(Interop.Rectangle.new_Rectangle__SWIG_1(x, y, width, height), true)
63 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
66 internal Rectangle(global::System.IntPtr cPtr, bool cMemoryOwn)
68 swigCMemOwn = cMemoryOwn;
69 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
75 /// <since_tizen> 3 </since_tizen>
80 isDisposeQueued = true;
81 DisposeQueue.Instance.Add(this);
86 /// The x position of the rectangle.
88 /// <since_tizen> 3 </since_tizen>
102 /// The Y position of the rectangle.
104 /// <since_tizen> 3 </since_tizen>
118 /// The width of the rectangle.
120 /// <since_tizen> 3 </since_tizen>
134 /// The height of the rectangle.
136 /// <since_tizen> 3 </since_tizen>
153 Interop.Rectangle.Rectangle_x_set(swigCPtr, value);
154 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
158 int ret = Interop.Rectangle.Rectangle_x_get(swigCPtr);
159 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
168 Interop.Rectangle.Rectangle_left_set(swigCPtr, value);
169 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
173 int ret = Interop.Rectangle.Rectangle_left_get(swigCPtr);
174 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
183 Interop.Rectangle.Rectangle_y_set(swigCPtr, value);
184 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
188 int ret = Interop.Rectangle.Rectangle_y_get(swigCPtr);
189 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
198 Interop.Rectangle.Rectangle_right_set(swigCPtr, value);
199 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
203 int ret = Interop.Rectangle.Rectangle_right_get(swigCPtr);
204 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
213 Interop.Rectangle.Rectangle_width_set(swigCPtr, value);
214 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
218 int ret = Interop.Rectangle.Rectangle_width_get(swigCPtr);
219 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
228 Interop.Rectangle.Rectangle_bottom_set(swigCPtr, value);
229 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
233 int ret = Interop.Rectangle.Rectangle_bottom_get(swigCPtr);
234 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
243 Interop.Rectangle.Rectangle_height_set(swigCPtr, value);
244 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
248 int ret = Interop.Rectangle.Rectangle_height_get(swigCPtr);
249 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
258 Interop.Rectangle.Rectangle_top_set(swigCPtr, value);
259 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
263 int ret = Interop.Rectangle.Rectangle_top_get(swigCPtr);
264 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
270 /// THe Equality operator.
272 /// <param name="a">The first operand.</param>
273 /// <param name="b">The second operand.</param>
274 /// <returns>True if the boxes are exactly the same.</returns>
275 /// <since_tizen> 3 </since_tizen>
276 public static bool operator ==(Rectangle a, Rectangle b)
278 // If both are null, or both are same instance, return true.
279 if (System.Object.ReferenceEquals(a, b))
284 // If one is null, but not both, return false.
285 if (((object)a == null) || ((object)b == null))
290 // Return true if the fields match:
291 return a.X == b.X && a.Y == b.Y && a.Width == b.Width && a.Height == b.Height;
295 /// Inequality operator.
297 /// <param name="a">The first rectangle.</param>
298 /// <param name="b">The second rectangle.</param>
299 /// <returns>True if the rectangles are not identical.</returns>
300 /// <since_tizen> 3 </since_tizen>
301 public static bool operator !=(Rectangle a, Rectangle b)
309 /// <since_tizen> 3 </since_tizen>
310 public void Dispose()
312 //Throw excpetion if Dispose() is called in separate thread.
313 if (!Window.IsInstalled())
315 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
320 Dispose(DisposeTypes.Implicit);
324 Dispose(DisposeTypes.Explicit);
325 System.GC.SuppressFinalize(this);
330 /// Equality operator.
332 /// <param name="o">The object to compare with the current object.</param>
333 /// <returns>True if boxes are exactly same.</returns>
334 /// <since_tizen> 4 </since_tizen>
335 public override bool Equals(object o)
341 if(!(o is Rectangle))
345 Rectangle r = (Rectangle)o;
347 // Return true if the fields match:
348 return X == r.X && Y == r.Y && Width == r.Width && Height == r.Height;
352 /// Serves as the default hash function.
354 /// <returns>A hash code for the current object.</returns>
355 /// <since_tizen> 4 </since_tizen>
356 public override int GetHashCode()
358 return base.GetHashCode();
362 /// Assignment from individual values.
364 /// <param name="newX">The x coordinate.</param>
365 /// <param name="newY">The y coordinate.</param>
366 /// <param name="newWidth">The width.</param>
367 /// <param name="newHeight">The height.</param>
368 /// <since_tizen> 3 </since_tizen>
369 public void Set(int newX, int newY, int newWidth, int newHeight)
371 Interop.Rectangle.Rectangle_Set(swigCPtr, newX, newY, newWidth, newHeight);
372 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
376 /// Determines whether or not this rectangle is empty.
378 /// <returns>True if width or height are zero.</returns>
379 /// <since_tizen> 3 </since_tizen>
380 public bool IsEmpty()
382 bool ret = Interop.Rectangle.Rectangle_IsEmpty(swigCPtr);
383 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
388 /// Gets the left of the rectangle.
390 /// <returns>The left edge of the rectangle.</returns>
391 /// <since_tizen> 3 </since_tizen>
394 int ret = Interop.Rectangle.Rectangle_Left(swigCPtr);
395 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
400 /// Gets the right of the rectangle.
402 /// <returns>The right edge of the rectangle.</returns>
403 /// <since_tizen> 3 </since_tizen>
406 int ret = Interop.Rectangle.Rectangle_Right(swigCPtr);
407 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
412 /// Gets the top of the rectangle.
414 /// <returns>The top of the rectangle.</returns>
415 /// <since_tizen> 3 </since_tizen>
418 int ret = Interop.Rectangle.Rectangle_Top(swigCPtr);
419 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
424 /// Gets the bottom of the rectangle.
426 /// <returns>The bottom of the rectangle.</returns>
427 /// <since_tizen> 3 </since_tizen>
430 int ret = Interop.Rectangle.Rectangle_Bottom(swigCPtr);
431 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
436 /// Gets the area of the rectangle.
438 /// <returns>The area of the rectangle.</returns>
439 /// <since_tizen> 3 </since_tizen>
442 int ret = Interop.Rectangle.Rectangle_Area(swigCPtr);
443 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
448 /// Determines whether or not this rectangle and the specified rectangle intersect.
450 /// <param name="other">The other rectangle to test against this rectangle.</param>
451 /// <returns>True if the rectangles intersect.</returns>
452 /// <since_tizen> 3 </since_tizen>
453 public bool Intersects(Rectangle other)
455 bool ret = Interop.Rectangle.Rectangle_Intersects(swigCPtr, Rectangle.getCPtr(other));
456 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
461 /// Determines whether or not this rectangle contains the specified rectangle.
463 /// <param name="other">The other rectangle to test against this rectangle.</param>
464 /// <returns>True if the specified rectangle is contained.</returns>
465 /// <since_tizen> 3 </since_tizen>
466 public bool Contains(Rectangle other)
468 bool ret = Interop.Rectangle.Rectangle_Contains(swigCPtr, Rectangle.getCPtr(other));
469 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
473 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Rectangle obj)
475 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
481 /// <since_tizen> 3 </since_tizen>
482 protected virtual void Dispose(DisposeTypes type)
489 if (type == DisposeTypes.Explicit)
492 //Release your own managed resources here.
493 //You should release all of your own disposable objects here.
496 //Release your own unmanaged resources here.
497 //You should not access any managed member here except static instance.
498 //because the execution order of Finalizes is non-deterministic.
500 if (swigCPtr.Handle != global::System.IntPtr.Zero)
505 Interop.Rectangle.delete_Rectangle(swigCPtr);
507 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);