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 public class Rectangle : global::System.IDisposable
26 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
30 /// <since_tizen> 3 </since_tizen>
31 protected bool swigCMemOwn;
33 internal Rectangle(global::System.IntPtr cPtr, bool cMemoryOwn)
35 swigCMemOwn = cMemoryOwn;
36 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
39 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Rectangle obj)
41 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
44 //A Flag to check who called Dispose(). (By User or DisposeQueue)
45 private bool isDisposeQueued = false;
47 /// A Flat to check if it is already disposed.
49 /// <since_tizen> 3 </since_tizen>
50 protected bool disposed = false;
55 /// <since_tizen> 3 </since_tizen>
60 isDisposeQueued = true;
61 DisposeQueue.Instance.Add(this);
68 /// <since_tizen> 3 </since_tizen>
71 //Throw excpetion if Dispose() is called in separate thread.
72 if (!Window.IsInstalled())
74 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
79 Dispose(DisposeTypes.Implicit);
83 Dispose(DisposeTypes.Explicit);
84 System.GC.SuppressFinalize(this);
91 /// <since_tizen> 3 </since_tizen>
92 protected virtual void Dispose(DisposeTypes type)
99 if(type == DisposeTypes.Explicit)
102 //Release your own managed resources here.
103 //You should release all of your own disposable objects here.
106 //Release your own unmanaged resources here.
107 //You should not access any managed member here except static instance.
108 //because the execution order of Finalizes is non-deterministic.
110 if (swigCPtr.Handle != global::System.IntPtr.Zero)
115 NDalicPINVOKE.delete_Rectangle(swigCPtr);
117 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
123 /// THe Equality operator.
125 /// <param name="a">The first operand.</param>
126 /// <param name="b">The second operand.</param>
127 /// <returns>True if the boxes are exactly the same.</returns>
128 /// <since_tizen> 3 </since_tizen>
129 public static bool operator ==(Rectangle a, Rectangle b)
131 // If both are null, or both are same instance, return true.
132 if (System.Object.ReferenceEquals(a, b))
137 // If one is null, but not both, return false.
138 if (((object)a == null) || ((object)b == null))
143 // Return true if the fields match:
144 return a.X == b.X && a.Y == b.Y && a.Width == b.Width && a.Height == b.Height;
148 /// Equality operator.
150 /// <param name="o">The object to compare with the current object.</param>
151 /// <returns>True if boxes are exactly same.</returns>
152 /// <since_tizen> 4 </since_tizen>
153 public override bool Equals(object o)
159 if(!(o is Rectangle))
163 Rectangle r = (Rectangle)o;
165 // Return true if the fields match:
166 return X == r.X && Y == r.Y && Width == r.Width && Height == r.Height;
170 /// Serves as the default hash function.
172 /// <returns>A hash code for the current object.</returns>
173 /// <since_tizen> 4 </since_tizen>
174 public override int GetHashCode()
176 return base.GetHashCode();
180 /// Inequality operator.
182 /// <param name="a">The first rectangle.</param>
183 /// <param name="b">The second rectangle.</param>
184 /// <returns>True if the rectangles are not identical.</returns>
185 /// <since_tizen> 3 </since_tizen>
186 public static bool operator !=(Rectangle a, Rectangle b)
192 /// The x position of the rectangle.
194 /// <since_tizen> 3 </since_tizen>
208 /// The Y position of the rectangle.
210 /// <since_tizen> 3 </since_tizen>
224 /// The width of the rectangle.
226 /// <since_tizen> 3 </since_tizen>
240 /// The height of the rectangle.
242 /// <since_tizen> 3 </since_tizen>
258 /// <since_tizen> 3 </since_tizen>
259 public Rectangle() : this(NDalicPINVOKE.new_Rectangle__SWIG_0(), true)
261 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
267 /// <param name="x">The x coordinate (or left).</param>
268 /// <param name="y">The y coordinate (or right).</param>
269 /// <param name="width">The width (or bottom).</param>
270 /// <param name="height">The height (or top).</param>
271 /// <since_tizen> 3 </since_tizen>
272 public Rectangle(int x, int y, int width, int height) : this(NDalicPINVOKE.new_Rectangle__SWIG_1(x, y, width, height), true)
274 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
278 /// Assignment from individual values.
280 /// <param name="newX">The x coordinate.</param>
281 /// <param name="newY">The y coordinate.</param>
282 /// <param name="newWidth">The width.</param>
283 /// <param name="newHeight">The height.</param>
284 /// <since_tizen> 3 </since_tizen>
285 public void Set(int newX, int newY, int newWidth, int newHeight)
287 NDalicPINVOKE.Rectangle_Set(swigCPtr, newX, newY, newWidth, newHeight);
288 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
292 /// Determines whether or not this rectangle is empty.
294 /// <returns>True if width or height are zero.</returns>
295 /// <since_tizen> 3 </since_tizen>
296 public bool IsEmpty()
298 bool ret = NDalicPINVOKE.Rectangle_IsEmpty(swigCPtr);
299 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
304 /// Gets the left of the rectangle.
306 /// <returns>The left edge of the rectangle.</returns>
307 /// <since_tizen> 3 </since_tizen>
310 int ret = NDalicPINVOKE.Rectangle_Left(swigCPtr);
311 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
316 /// Gets the right of the rectangle.
318 /// <returns>The right edge of the rectangle.</returns>
319 /// <since_tizen> 3 </since_tizen>
322 int ret = NDalicPINVOKE.Rectangle_Right(swigCPtr);
323 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
328 /// Gets the top of the rectangle.
330 /// <returns>The top of the rectangle.</returns>
331 /// <since_tizen> 3 </since_tizen>
334 int ret = NDalicPINVOKE.Rectangle_Top(swigCPtr);
335 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
340 /// Gets the bottom of the rectangle.
342 /// <returns>The bottom of the rectangle.</returns>
343 /// <since_tizen> 3 </since_tizen>
346 int ret = NDalicPINVOKE.Rectangle_Bottom(swigCPtr);
347 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
352 /// Gets the area of the rectangle.
354 /// <returns>The area of the rectangle.</returns>
355 /// <since_tizen> 3 </since_tizen>
358 int ret = NDalicPINVOKE.Rectangle_Area(swigCPtr);
359 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
364 /// Determines whether or not this rectangle and the specified rectangle intersect.
366 /// <param name="other">The other rectangle to test against this rectangle.</param>
367 /// <returns>True if the rectangles intersect.</returns>
368 /// <since_tizen> 3 </since_tizen>
369 public bool Intersects(Rectangle other)
371 bool ret = NDalicPINVOKE.Rectangle_Intersects(swigCPtr, Rectangle.getCPtr(other));
372 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
377 /// Determines whether or not this rectangle contains the specified rectangle.
379 /// <param name="other">The other rectangle to test against this rectangle.</param>
380 /// <returns>True if the specified rectangle is contained.</returns>
381 /// <since_tizen> 3 </since_tizen>
382 public bool Contains(Rectangle other)
384 bool ret = NDalicPINVOKE.Rectangle_Contains(swigCPtr, Rectangle.getCPtr(other));
385 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
393 NDalicPINVOKE.Rectangle_x_set(swigCPtr, value);
394 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
398 int ret = NDalicPINVOKE.Rectangle_x_get(swigCPtr);
399 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
408 NDalicPINVOKE.Rectangle_left_set(swigCPtr, value);
409 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
413 int ret = NDalicPINVOKE.Rectangle_left_get(swigCPtr);
414 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
423 NDalicPINVOKE.Rectangle_y_set(swigCPtr, value);
424 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
428 int ret = NDalicPINVOKE.Rectangle_y_get(swigCPtr);
429 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
438 NDalicPINVOKE.Rectangle_right_set(swigCPtr, value);
439 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
443 int ret = NDalicPINVOKE.Rectangle_right_get(swigCPtr);
444 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
453 NDalicPINVOKE.Rectangle_width_set(swigCPtr, value);
454 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
458 int ret = NDalicPINVOKE.Rectangle_width_get(swigCPtr);
459 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
468 NDalicPINVOKE.Rectangle_bottom_set(swigCPtr, value);
469 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
473 int ret = NDalicPINVOKE.Rectangle_bottom_get(swigCPtr);
474 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
483 NDalicPINVOKE.Rectangle_height_set(swigCPtr, value);
484 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
488 int ret = NDalicPINVOKE.Rectangle_height_get(swigCPtr);
489 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
498 NDalicPINVOKE.Rectangle_top_set(swigCPtr, value);
499 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
503 int ret = NDalicPINVOKE.Rectangle_top_get(swigCPtr);
504 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();