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;
24 /// The Rectangle class.
26 /// <since_tizen> 3 </since_tizen>
27 [TypeConverter(typeof(RectangleTypeConverter))]
28 public class Rectangle : global::System.IDisposable
30 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
34 /// <since_tizen> 3 </since_tizen>
35 protected bool swigCMemOwn;
37 internal Rectangle(global::System.IntPtr cPtr, bool cMemoryOwn)
39 swigCMemOwn = cMemoryOwn;
40 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
43 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Rectangle obj)
45 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
48 //A Flag to check who called Dispose(). (By User or DisposeQueue)
49 private bool isDisposeQueued = false;
51 /// A Flat to check if it is already disposed.
53 /// <since_tizen> 3 </since_tizen>
54 protected bool disposed = false;
59 /// <since_tizen> 3 </since_tizen>
64 isDisposeQueued = true;
65 DisposeQueue.Instance.Add(this);
72 /// <since_tizen> 3 </since_tizen>
75 //Throw excpetion if Dispose() is called in separate thread.
76 if (!Window.IsInstalled())
78 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
83 Dispose(DisposeTypes.Implicit);
87 Dispose(DisposeTypes.Explicit);
88 System.GC.SuppressFinalize(this);
95 /// <since_tizen> 3 </since_tizen>
96 protected virtual void Dispose(DisposeTypes type)
103 if(type == DisposeTypes.Explicit)
106 //Release your own managed resources here.
107 //You should release all of your own disposable objects here.
110 //Release your own unmanaged resources here.
111 //You should not access any managed member here except static instance.
112 //because the execution order of Finalizes is non-deterministic.
114 if (swigCPtr.Handle != global::System.IntPtr.Zero)
119 NDalicPINVOKE.delete_Rectangle(swigCPtr);
121 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
127 /// THe Equality operator.
129 /// <param name="a">The first operand.</param>
130 /// <param name="b">The second operand.</param>
131 /// <returns>True if the boxes are exactly the same.</returns>
132 /// <since_tizen> 3 </since_tizen>
133 public static bool operator ==(Rectangle a, Rectangle b)
135 // If both are null, or both are same instance, return true.
136 if (System.Object.ReferenceEquals(a, b))
141 // If one is null, but not both, return false.
142 if (((object)a == null) || ((object)b == null))
147 // Return true if the fields match:
148 return a.X == b.X && a.Y == b.Y && a.Width == b.Width && a.Height == b.Height;
152 /// Equality operator.
154 /// <param name="o">The object to compare with the current object.</param>
155 /// <returns>True if boxes are exactly same.</returns>
156 /// <since_tizen> 4 </since_tizen>
157 public override bool Equals(object o)
163 if(!(o is Rectangle))
167 Rectangle r = (Rectangle)o;
169 // Return true if the fields match:
170 return X == r.X && Y == r.Y && Width == r.Width && Height == r.Height;
174 /// Serves as the default hash function.
176 /// <returns>A hash code for the current object.</returns>
177 /// <since_tizen> 4 </since_tizen>
178 public override int GetHashCode()
180 return base.GetHashCode();
184 /// Inequality operator.
186 /// <param name="a">The first rectangle.</param>
187 /// <param name="b">The second rectangle.</param>
188 /// <returns>True if the rectangles are not identical.</returns>
189 /// <since_tizen> 3 </since_tizen>
190 public static bool operator !=(Rectangle a, Rectangle b)
196 /// The x position of the rectangle.
198 /// <since_tizen> 3 </since_tizen>
212 /// The Y position of the rectangle.
214 /// <since_tizen> 3 </since_tizen>
228 /// The width of the rectangle.
230 /// <since_tizen> 3 </since_tizen>
244 /// The height of the rectangle.
246 /// <since_tizen> 3 </since_tizen>
262 /// <since_tizen> 3 </since_tizen>
263 public Rectangle() : this(NDalicPINVOKE.new_Rectangle__SWIG_0(), true)
265 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
271 /// <param name="x">The x coordinate (or left).</param>
272 /// <param name="y">The y coordinate (or right).</param>
273 /// <param name="width">The width (or bottom).</param>
274 /// <param name="height">The height (or top).</param>
275 /// <since_tizen> 3 </since_tizen>
276 public Rectangle(int x, int y, int width, int height) : this(NDalicPINVOKE.new_Rectangle__SWIG_1(x, y, width, height), true)
278 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
282 /// Assignment from individual values.
284 /// <param name="newX">The x coordinate.</param>
285 /// <param name="newY">The y coordinate.</param>
286 /// <param name="newWidth">The width.</param>
287 /// <param name="newHeight">The height.</param>
288 /// <since_tizen> 3 </since_tizen>
289 public void Set(int newX, int newY, int newWidth, int newHeight)
291 NDalicPINVOKE.Rectangle_Set(swigCPtr, newX, newY, newWidth, newHeight);
292 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
296 /// Determines whether or not this rectangle is empty.
298 /// <returns>True if width or height are zero.</returns>
299 /// <since_tizen> 3 </since_tizen>
300 public bool IsEmpty()
302 bool ret = NDalicPINVOKE.Rectangle_IsEmpty(swigCPtr);
303 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
308 /// Gets the left of the rectangle.
310 /// <returns>The left edge of the rectangle.</returns>
311 /// <since_tizen> 3 </since_tizen>
314 int ret = NDalicPINVOKE.Rectangle_Left(swigCPtr);
315 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
320 /// Gets the right of the rectangle.
322 /// <returns>The right edge of the rectangle.</returns>
323 /// <since_tizen> 3 </since_tizen>
326 int ret = NDalicPINVOKE.Rectangle_Right(swigCPtr);
327 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
332 /// Gets the top of the rectangle.
334 /// <returns>The top of the rectangle.</returns>
335 /// <since_tizen> 3 </since_tizen>
338 int ret = NDalicPINVOKE.Rectangle_Top(swigCPtr);
339 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
344 /// Gets the bottom of the rectangle.
346 /// <returns>The bottom of the rectangle.</returns>
347 /// <since_tizen> 3 </since_tizen>
350 int ret = NDalicPINVOKE.Rectangle_Bottom(swigCPtr);
351 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
356 /// Gets the area of the rectangle.
358 /// <returns>The area of the rectangle.</returns>
359 /// <since_tizen> 3 </since_tizen>
362 int ret = NDalicPINVOKE.Rectangle_Area(swigCPtr);
363 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
368 /// Determines whether or not this rectangle and the specified rectangle intersect.
370 /// <param name="other">The other rectangle to test against this rectangle.</param>
371 /// <returns>True if the rectangles intersect.</returns>
372 /// <since_tizen> 3 </since_tizen>
373 public bool Intersects(Rectangle other)
375 bool ret = NDalicPINVOKE.Rectangle_Intersects(swigCPtr, Rectangle.getCPtr(other));
376 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
381 /// Determines whether or not this rectangle contains the specified rectangle.
383 /// <param name="other">The other rectangle to test against this rectangle.</param>
384 /// <returns>True if the specified rectangle is contained.</returns>
385 /// <since_tizen> 3 </since_tizen>
386 public bool Contains(Rectangle other)
388 bool ret = NDalicPINVOKE.Rectangle_Contains(swigCPtr, Rectangle.getCPtr(other));
389 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
397 NDalicPINVOKE.Rectangle_x_set(swigCPtr, value);
398 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
402 int ret = NDalicPINVOKE.Rectangle_x_get(swigCPtr);
403 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
412 NDalicPINVOKE.Rectangle_left_set(swigCPtr, value);
413 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
417 int ret = NDalicPINVOKE.Rectangle_left_get(swigCPtr);
418 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
427 NDalicPINVOKE.Rectangle_y_set(swigCPtr, value);
428 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
432 int ret = NDalicPINVOKE.Rectangle_y_get(swigCPtr);
433 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
442 NDalicPINVOKE.Rectangle_right_set(swigCPtr, value);
443 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
447 int ret = NDalicPINVOKE.Rectangle_right_get(swigCPtr);
448 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
457 NDalicPINVOKE.Rectangle_width_set(swigCPtr, value);
458 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
462 int ret = NDalicPINVOKE.Rectangle_width_get(swigCPtr);
463 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
472 NDalicPINVOKE.Rectangle_bottom_set(swigCPtr, value);
473 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
477 int ret = NDalicPINVOKE.Rectangle_bottom_get(swigCPtr);
478 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
487 NDalicPINVOKE.Rectangle_height_set(swigCPtr, value);
488 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
492 int ret = NDalicPINVOKE.Rectangle_height_get(swigCPtr);
493 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
502 NDalicPINVOKE.Rectangle_top_set(swigCPtr, value);
503 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
507 int ret = NDalicPINVOKE.Rectangle_top_get(swigCPtr);
508 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();