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 public static bool operator ==(Rectangle a, Rectangle b)
110 // If both are null, or both are same instance, return true.
111 if (System.Object.ReferenceEquals(a, b))
116 // If one is null, but not both, return false.
117 if (((object)a == null) || ((object)b == null))
122 // Return true if the fields match:
123 return a.X == b.X && a.Y == b.Y && a.Width == b.Width && a.Height == b.Height;
127 /// Equality operator.
129 /// <param name="o">The object to compare with the current object.</param>
130 /// <returns>True if boxes are exactly same.</returns>
131 public override bool Equals(object o)
137 if(!(o is Rectangle))
141 Rectangle r = (Rectangle)o;
143 // Return true if the fields match:
144 return X == r.X && Y == r.Y && Width == r.Width && Height == r.Height;
148 /// Serves as the default hash function.
150 /// <returns>A hash code for the current object.</returns>
151 public override int GetHashCode()
153 return base.GetHashCode();
157 /// Inequality operator.
159 /// <param name="a">The first rectangle.</param>
160 /// <param name="b">The second rectangle.</param>
161 /// <returns>True if the rectangles are not identical.</returns>
162 public static bool operator !=(Rectangle a, Rectangle b)
168 /// The x position of the rectangle.
183 /// The Y position of the rectangle.
198 /// The width of the rectangle.
213 /// The height of the rectangle.
230 public Rectangle() : this(NDalicPINVOKE.new_Rectangle__SWIG_0(), true)
232 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
238 /// <param name="x">The x coordinate (or left).</param>
239 /// <param name="y">The y coordinate (or right).</param>
240 /// <param name="width">The width (or bottom).</param>
241 /// <param name="height">The height (or top).</param>
242 public Rectangle(int x, int y, int width, int height) : this(NDalicPINVOKE.new_Rectangle__SWIG_1(x, y, width, height), true)
244 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
248 /// Assignment from individual values.
250 /// <param name="newX">The x coordinate.</param>
251 /// <param name="newY">The y coordinate.</param>
252 /// <param name="newWidth">The width.</param>
253 /// <param name="newHeight">The height./param>
254 public void Set(int newX, int newY, int newWidth, int newHeight)
256 NDalicPINVOKE.Rectangle_Set(swigCPtr, newX, newY, newWidth, newHeight);
257 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
261 /// Determines whether or not this rectangle is empty.
263 /// <returns>True if width or height are zero.</returns>
264 public bool IsEmpty()
266 bool ret = NDalicPINVOKE.Rectangle_IsEmpty(swigCPtr);
267 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
272 /// Gets the left of the rectangle.
274 /// <returns>The left edge of the rectangle.</returns>
277 int ret = NDalicPINVOKE.Rectangle_Left(swigCPtr);
278 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
283 /// Gets the right of the rectangle.
285 /// <returns>The right edge of the rectangle.</returns>
288 int ret = NDalicPINVOKE.Rectangle_Right(swigCPtr);
289 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
294 /// Gets the top of the rectangle.
296 /// <returns>The top of the rectangle.</returns>
299 int ret = NDalicPINVOKE.Rectangle_Top(swigCPtr);
300 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
305 /// Gets the bottom of the rectangle.
307 /// <returns>The bottom of the rectangle.</returns>
310 int ret = NDalicPINVOKE.Rectangle_Bottom(swigCPtr);
311 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
316 /// Gets the area of the rectangle.
318 /// <returns>The area of the rectangle.</returns>
321 int ret = NDalicPINVOKE.Rectangle_Area(swigCPtr);
322 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
327 /// Determines whether or not this rectangle and the specified rectangle intersect.
329 /// <param name="other">The other rectangle to test against this rectangle.</param>
330 /// <returns>True if the rectangles intersect.</returns>
331 public bool Intersects(Rectangle other)
333 bool ret = NDalicPINVOKE.Rectangle_Intersects(swigCPtr, Rectangle.getCPtr(other));
334 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
339 /// Determines whether or not this rectangle contains the specified rectangle.
341 /// <param name="other">The other rectangle to test against this rectangle.</param>
342 /// <returns>True if the specified rectangle is contained.</returns>
343 public bool Contains(Rectangle other)
345 bool ret = NDalicPINVOKE.Rectangle_Contains(swigCPtr, Rectangle.getCPtr(other));
346 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
354 NDalicPINVOKE.Rectangle_x_set(swigCPtr, value);
355 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
359 int ret = NDalicPINVOKE.Rectangle_x_get(swigCPtr);
360 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
369 NDalicPINVOKE.Rectangle_left_set(swigCPtr, value);
370 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
374 int ret = NDalicPINVOKE.Rectangle_left_get(swigCPtr);
375 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
384 NDalicPINVOKE.Rectangle_y_set(swigCPtr, value);
385 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
389 int ret = NDalicPINVOKE.Rectangle_y_get(swigCPtr);
390 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
399 NDalicPINVOKE.Rectangle_right_set(swigCPtr, value);
400 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
404 int ret = NDalicPINVOKE.Rectangle_right_get(swigCPtr);
405 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
414 NDalicPINVOKE.Rectangle_width_set(swigCPtr, value);
415 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
419 int ret = NDalicPINVOKE.Rectangle_width_get(swigCPtr);
420 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
429 NDalicPINVOKE.Rectangle_bottom_set(swigCPtr, value);
430 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
434 int ret = NDalicPINVOKE.Rectangle_bottom_get(swigCPtr);
435 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
444 NDalicPINVOKE.Rectangle_height_set(swigCPtr, value);
445 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
449 int ret = NDalicPINVOKE.Rectangle_height_get(swigCPtr);
450 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
459 NDalicPINVOKE.Rectangle_top_set(swigCPtr, value);
460 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
464 int ret = NDalicPINVOKE.Rectangle_top_get(swigCPtr);
465 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();