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
27 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
31 /// <since_tizen> 3 </since_tizen>
32 protected bool swigCMemOwn;
34 internal Rectangle(global::System.IntPtr cPtr, bool cMemoryOwn)
36 swigCMemOwn = cMemoryOwn;
37 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
40 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Rectangle obj)
42 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
45 //A Flag to check who called Dispose(). (By User or DisposeQueue)
46 private bool isDisposeQueued = false;
48 /// A Flat to check if it is already disposed.
50 /// <since_tizen> 3 </since_tizen>
51 protected bool disposed = false;
56 /// <since_tizen> 3 </since_tizen>
61 isDisposeQueued = true;
62 DisposeQueue.Instance.Add(this);
69 /// <since_tizen> 3 </since_tizen>
72 //Throw excpetion if Dispose() is called in separate thread.
73 if (!Window.IsInstalled())
75 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
80 Dispose(DisposeTypes.Implicit);
84 Dispose(DisposeTypes.Explicit);
85 System.GC.SuppressFinalize(this);
92 /// <since_tizen> 3 </since_tizen>
93 protected virtual void Dispose(DisposeTypes type)
100 if(type == DisposeTypes.Explicit)
103 //Release your own managed resources here.
104 //You should release all of your own disposable objects here.
107 //Release your own unmanaged resources here.
108 //You should not access any managed member here except static instance.
109 //because the execution order of Finalizes is non-deterministic.
111 if (swigCPtr.Handle != global::System.IntPtr.Zero)
116 NDalicPINVOKE.delete_Rectangle(swigCPtr);
118 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
124 /// THe Equality operator.
126 /// <param name="a">The first operand.</param>
127 /// <param name="b">The second operand.</param>
128 /// <returns>True if the boxes are exactly the same.</returns>
129 /// <since_tizen> 3 </since_tizen>
130 public static bool operator ==(Rectangle a, Rectangle b)
132 // If both are null, or both are same instance, return true.
133 if (System.Object.ReferenceEquals(a, b))
138 // If one is null, but not both, return false.
139 if (((object)a == null) || ((object)b == null))
144 // Return true if the fields match:
145 return a.X == b.X && a.Y == b.Y && a.Width == b.Width && a.Height == b.Height;
149 /// Equality operator.
151 /// <param name="o">The object to compare with the current object.</param>
152 /// <returns>True if boxes are exactly same.</returns>
153 /// <since_tizen> 4 </since_tizen>
154 public override bool Equals(object o)
160 if(!(o is Rectangle))
164 Rectangle r = (Rectangle)o;
166 // Return true if the fields match:
167 return X == r.X && Y == r.Y && Width == r.Width && Height == r.Height;
171 /// Serves as the default hash function.
173 /// <returns>A hash code for the current object.</returns>
174 /// <since_tizen> 4 </since_tizen>
175 public override int GetHashCode()
177 return base.GetHashCode();
181 /// Inequality operator.
183 /// <param name="a">The first rectangle.</param>
184 /// <param name="b">The second rectangle.</param>
185 /// <returns>True if the rectangles are not identical.</returns>
186 /// <since_tizen> 3 </since_tizen>
187 public static bool operator !=(Rectangle a, Rectangle b)
193 /// The x position of the rectangle.
195 /// <since_tizen> 3 </since_tizen>
209 /// The Y position of the rectangle.
211 /// <since_tizen> 3 </since_tizen>
225 /// The width of the rectangle.
227 /// <since_tizen> 3 </since_tizen>
241 /// The height of the rectangle.
243 /// <since_tizen> 3 </since_tizen>
259 /// <since_tizen> 3 </since_tizen>
260 public Rectangle() : this(NDalicPINVOKE.new_Rectangle__SWIG_0(), true)
262 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
268 /// <param name="x">The x coordinate (or left).</param>
269 /// <param name="y">The y coordinate (or right).</param>
270 /// <param name="width">The width (or bottom).</param>
271 /// <param name="height">The height (or top).</param>
272 /// <since_tizen> 3 </since_tizen>
273 public Rectangle(int x, int y, int width, int height) : this(NDalicPINVOKE.new_Rectangle__SWIG_1(x, y, width, height), true)
275 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
279 /// Assignment from individual values.
281 /// <param name="newX">The x coordinate.</param>
282 /// <param name="newY">The y coordinate.</param>
283 /// <param name="newWidth">The width.</param>
284 /// <param name="newHeight">The height.</param>
285 /// <since_tizen> 3 </since_tizen>
286 public void Set(int newX, int newY, int newWidth, int newHeight)
288 NDalicPINVOKE.Rectangle_Set(swigCPtr, newX, newY, newWidth, newHeight);
289 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
293 /// Determines whether or not this rectangle is empty.
295 /// <returns>True if width or height are zero.</returns>
296 /// <since_tizen> 3 </since_tizen>
297 public bool IsEmpty()
299 bool ret = NDalicPINVOKE.Rectangle_IsEmpty(swigCPtr);
300 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
305 /// Gets the left of the rectangle.
307 /// <returns>The left edge of the rectangle.</returns>
308 /// <since_tizen> 3 </since_tizen>
311 int ret = NDalicPINVOKE.Rectangle_Left(swigCPtr);
312 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
317 /// Gets the right of the rectangle.
319 /// <returns>The right edge of the rectangle.</returns>
320 /// <since_tizen> 3 </since_tizen>
323 int ret = NDalicPINVOKE.Rectangle_Right(swigCPtr);
324 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
329 /// Gets the top of the rectangle.
331 /// <returns>The top of the rectangle.</returns>
332 /// <since_tizen> 3 </since_tizen>
335 int ret = NDalicPINVOKE.Rectangle_Top(swigCPtr);
336 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
341 /// Gets the bottom of the rectangle.
343 /// <returns>The bottom of the rectangle.</returns>
344 /// <since_tizen> 3 </since_tizen>
347 int ret = NDalicPINVOKE.Rectangle_Bottom(swigCPtr);
348 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
353 /// Gets the area of the rectangle.
355 /// <returns>The area of the rectangle.</returns>
356 /// <since_tizen> 3 </since_tizen>
359 int ret = NDalicPINVOKE.Rectangle_Area(swigCPtr);
360 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
365 /// Determines whether or not this rectangle and the specified rectangle intersect.
367 /// <param name="other">The other rectangle to test against this rectangle.</param>
368 /// <returns>True if the rectangles intersect.</returns>
369 /// <since_tizen> 3 </since_tizen>
370 public bool Intersects(Rectangle other)
372 bool ret = NDalicPINVOKE.Rectangle_Intersects(swigCPtr, Rectangle.getCPtr(other));
373 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
378 /// Determines whether or not this rectangle contains the specified rectangle.
380 /// <param name="other">The other rectangle to test against this rectangle.</param>
381 /// <returns>True if the specified rectangle is contained.</returns>
382 /// <since_tizen> 3 </since_tizen>
383 public bool Contains(Rectangle other)
385 bool ret = NDalicPINVOKE.Rectangle_Contains(swigCPtr, Rectangle.getCPtr(other));
386 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
394 NDalicPINVOKE.Rectangle_x_set(swigCPtr, value);
395 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
399 int ret = NDalicPINVOKE.Rectangle_x_get(swigCPtr);
400 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
409 NDalicPINVOKE.Rectangle_left_set(swigCPtr, value);
410 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
414 int ret = NDalicPINVOKE.Rectangle_left_get(swigCPtr);
415 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
424 NDalicPINVOKE.Rectangle_y_set(swigCPtr, value);
425 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
429 int ret = NDalicPINVOKE.Rectangle_y_get(swigCPtr);
430 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
439 NDalicPINVOKE.Rectangle_right_set(swigCPtr, value);
440 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
444 int ret = NDalicPINVOKE.Rectangle_right_get(swigCPtr);
445 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
454 NDalicPINVOKE.Rectangle_width_set(swigCPtr, value);
455 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
459 int ret = NDalicPINVOKE.Rectangle_width_get(swigCPtr);
460 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
469 NDalicPINVOKE.Rectangle_bottom_set(swigCPtr, value);
470 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
474 int ret = NDalicPINVOKE.Rectangle_bottom_get(swigCPtr);
475 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
484 NDalicPINVOKE.Rectangle_height_set(swigCPtr, value);
485 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
489 int ret = NDalicPINVOKE.Rectangle_height_get(swigCPtr);
490 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
499 NDalicPINVOKE.Rectangle_top_set(swigCPtr, value);
500 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
504 int ret = NDalicPINVOKE.Rectangle_top_get(swigCPtr);
505 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();