1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
21 /// The Rectangle class.
23 public class Rectangle : global::System.IDisposable
25 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
26 protected bool swigCMemOwn;
28 internal Rectangle(global::System.IntPtr cPtr, bool cMemoryOwn)
30 swigCMemOwn = cMemoryOwn;
31 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
34 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Rectangle obj)
36 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
39 //A Flag to check who called Dispose(). (By User or DisposeQueue)
40 private bool isDisposeQueued = false;
41 //A Flat to check if it is already disposed.
42 protected bool disposed = false;
48 isDisposeQueued = true;
49 DisposeQueue.Instance.Add(this);
55 //Throw excpetion if Dispose() is called in separate thread.
56 if (!Window.IsInstalled())
58 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
63 Dispose(DisposeTypes.Implicit);
67 Dispose(DisposeTypes.Explicit);
68 System.GC.SuppressFinalize(this);
72 protected virtual void Dispose(DisposeTypes type)
79 if(type == DisposeTypes.Explicit)
82 //Release your own managed resources here.
83 //You should release all of your own disposable objects here.
86 //Release your own unmanaged resources here.
87 //You should not access any managed member here except static instance.
88 //because the execution order of Finalizes is non-deterministic.
90 if (swigCPtr.Handle != global::System.IntPtr.Zero)
95 NDalicPINVOKE.delete_Rectangle(swigCPtr);
97 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
103 /// THe Equality operator.
105 /// <param name="a">The first operand.</param>
106 /// <param name="b">The second operand.</param>
107 /// <returns>True if the boxes are exactly the same.</returns>
108 /// <since_tizen> 3 </since_tizen>
109 public static bool operator ==(Rectangle a, Rectangle b)
111 // If both are null, or both are same instance, return true.
112 if (System.Object.ReferenceEquals(a, b))
117 // If one is null, but not both, return false.
118 if (((object)a == null) || ((object)b == null))
123 // Return true if the fields match:
124 return a.X == b.X && a.Y == b.Y && a.Width == b.Width && a.Height == b.Height;
128 /// Equality operator.
130 /// <param name="o">The object to compare with the current object.</param>
131 /// <returns>True if boxes are exactly same.</returns>
132 /// <since_tizen> 4 </since_tizen>
133 public override bool Equals(object o)
139 if(!(o is Rectangle))
143 Rectangle r = (Rectangle)o;
145 // Return true if the fields match:
146 return X == r.X && Y == r.Y && Width == r.Width && Height == r.Height;
150 /// Serves as the default hash function.
152 /// <returns>A hash code for the current object.</returns>
153 /// <since_tizen> 4 </since_tizen>
154 public override int GetHashCode()
156 return base.GetHashCode();
160 /// Inequality operator.
162 /// <param name="a">The first rectangle.</param>
163 /// <param name="b">The second rectangle.</param>
164 /// <returns>True if the rectangles are not identical.</returns>
165 /// <since_tizen> 3 </since_tizen>
166 public static bool operator !=(Rectangle a, Rectangle b)
172 /// The x position of the rectangle.
174 /// <since_tizen> 3 </since_tizen>
188 /// The Y position of the rectangle.
190 /// <since_tizen> 3 </since_tizen>
204 /// The width of the rectangle.
206 /// <since_tizen> 3 </since_tizen>
220 /// The height of the rectangle.
222 /// <since_tizen> 3 </since_tizen>
238 /// <since_tizen> 3 </since_tizen>
239 public Rectangle() : this(NDalicPINVOKE.new_Rectangle__SWIG_0(), true)
241 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
247 /// <param name="x">The x coordinate (or left).</param>
248 /// <param name="y">The y coordinate (or right).</param>
249 /// <param name="width">The width (or bottom).</param>
250 /// <param name="height">The height (or top).</param>
251 /// <since_tizen> 3 </since_tizen>
252 public Rectangle(int x, int y, int width, int height) : this(NDalicPINVOKE.new_Rectangle__SWIG_1(x, y, width, height), true)
254 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
258 /// Assignment from individual values.
260 /// <param name="newX">The x coordinate.</param>
261 /// <param name="newY">The y coordinate.</param>
262 /// <param name="newWidth">The width.</param>
263 /// <param name="newHeight">The height./param>
264 /// <since_tizen> 3 </since_tizen>
265 public void Set(int newX, int newY, int newWidth, int newHeight)
267 NDalicPINVOKE.Rectangle_Set(swigCPtr, newX, newY, newWidth, newHeight);
268 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
272 /// Determines whether or not this rectangle is empty.
274 /// <returns>True if width or height are zero.</returns>
275 /// <since_tizen> 3 </since_tizen>
276 public bool IsEmpty()
278 bool ret = NDalicPINVOKE.Rectangle_IsEmpty(swigCPtr);
279 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
284 /// Gets the left of the rectangle.
286 /// <returns>The left edge of the rectangle.</returns>
287 /// <since_tizen> 3 </since_tizen>
290 int ret = NDalicPINVOKE.Rectangle_Left(swigCPtr);
291 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
296 /// Gets the right of the rectangle.
298 /// <returns>The right edge of the rectangle.</returns>
299 /// <since_tizen> 3 </since_tizen>
302 int ret = NDalicPINVOKE.Rectangle_Right(swigCPtr);
303 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
308 /// Gets the top of the rectangle.
310 /// <returns>The top of the rectangle.</returns>
311 /// <since_tizen> 3 </since_tizen>
314 int ret = NDalicPINVOKE.Rectangle_Top(swigCPtr);
315 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
320 /// Gets the bottom of the rectangle.
322 /// <returns>The bottom of the rectangle.</returns>
323 /// <since_tizen> 3 </since_tizen>
326 int ret = NDalicPINVOKE.Rectangle_Bottom(swigCPtr);
327 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
332 /// Gets the area of the rectangle.
334 /// <returns>The area of the rectangle.</returns>
335 /// <since_tizen> 3 </since_tizen>
338 int ret = NDalicPINVOKE.Rectangle_Area(swigCPtr);
339 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
344 /// Determines whether or not this rectangle and the specified rectangle intersect.
346 /// <param name="other">The other rectangle to test against this rectangle.</param>
347 /// <returns>True if the rectangles intersect.</returns>
348 /// <since_tizen> 3 </since_tizen>
349 public bool Intersects(Rectangle other)
351 bool ret = NDalicPINVOKE.Rectangle_Intersects(swigCPtr, Rectangle.getCPtr(other));
352 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
357 /// Determines whether or not this rectangle contains the specified rectangle.
359 /// <param name="other">The other rectangle to test against this rectangle.</param>
360 /// <returns>True if the specified rectangle is contained.</returns>
361 /// <since_tizen> 3 </since_tizen>
362 public bool Contains(Rectangle other)
364 bool ret = NDalicPINVOKE.Rectangle_Contains(swigCPtr, Rectangle.getCPtr(other));
365 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
373 NDalicPINVOKE.Rectangle_x_set(swigCPtr, value);
374 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
378 int ret = NDalicPINVOKE.Rectangle_x_get(swigCPtr);
379 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
388 NDalicPINVOKE.Rectangle_left_set(swigCPtr, value);
389 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
393 int ret = NDalicPINVOKE.Rectangle_left_get(swigCPtr);
394 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
403 NDalicPINVOKE.Rectangle_y_set(swigCPtr, value);
404 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
408 int ret = NDalicPINVOKE.Rectangle_y_get(swigCPtr);
409 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
418 NDalicPINVOKE.Rectangle_right_set(swigCPtr, value);
419 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
423 int ret = NDalicPINVOKE.Rectangle_right_get(swigCPtr);
424 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
433 NDalicPINVOKE.Rectangle_width_set(swigCPtr, value);
434 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
438 int ret = NDalicPINVOKE.Rectangle_width_get(swigCPtr);
439 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
448 NDalicPINVOKE.Rectangle_bottom_set(swigCPtr, value);
449 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
453 int ret = NDalicPINVOKE.Rectangle_bottom_get(swigCPtr);
454 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
463 NDalicPINVOKE.Rectangle_height_set(swigCPtr, value);
464 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
468 int ret = NDalicPINVOKE.Rectangle_height_get(swigCPtr);
469 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
478 NDalicPINVOKE.Rectangle_top_set(swigCPtr, value);
479 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
483 int ret = NDalicPINVOKE.Rectangle_top_get(swigCPtr);
484 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();