[NUI] Split NUI Assemblies (#865)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Rectangle.cs
1 /*
2  * Copyright(c) 2017 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 using System;
18
19 namespace Tizen.NUI
20 {
21     /// <summary>
22     /// The Rectangle class.
23     /// </summary>
24     /// <since_tizen> 3 </since_tizen>
25     public class Rectangle : global::System.IDisposable
26     {
27         /// <summary>
28         /// swigCMemOwn
29         /// </summary>
30         /// <since_tizen> 3 </since_tizen>
31         protected bool swigCMemOwn;
32
33         /// <summary>
34         /// A Flat to check if it is already disposed.
35         /// </summary>
36         /// <since_tizen> 3 </since_tizen>
37         protected bool disposed = false;
38
39         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
40
41         //A Flag to check who called Dispose(). (By User or DisposeQueue)
42         private bool isDisposeQueued = false;
43
44         /// <summary>
45         /// The constructor.
46         /// </summary>
47         /// <since_tizen> 3 </since_tizen>
48         public Rectangle() : this(Interop.Rectangle.new_Rectangle__SWIG_0(), true)
49         {
50             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
51         }
52
53         /// <summary>
54         /// The constructor.
55         /// </summary>
56         /// <param name="x">The x coordinate (or left).</param>
57         /// <param name="y">The y coordinate (or right).</param>
58         /// <param name="width">The width (or bottom).</param>
59         /// <param name="height">The height (or top).</param>
60         /// <since_tizen> 3 </since_tizen>
61         public Rectangle(int x, int y, int width, int height) : this(Interop.Rectangle.new_Rectangle__SWIG_1(x, y, width, height), true)
62         {
63             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
64         }
65
66         internal Rectangle(global::System.IntPtr cPtr, bool cMemoryOwn)
67         {
68             swigCMemOwn = cMemoryOwn;
69             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
70         }
71
72         /// <summary>
73         /// Dispose.
74         /// </summary>
75         /// <since_tizen> 3 </since_tizen>
76         ~Rectangle()
77         {
78             if (!isDisposeQueued)
79             {
80                 isDisposeQueued = true;
81                 DisposeQueue.Instance.Add(this);
82             }
83         }
84
85         /// <summary>
86         /// The x position of the rectangle.
87         /// </summary>
88         /// <since_tizen> 3 </since_tizen>
89         public int X
90         {
91             set
92             {
93                 x = (value);
94             }
95             get
96             {
97                 return x;
98             }
99         }
100
101         /// <summary>
102         /// The Y position of the rectangle.
103         /// </summary>
104         /// <since_tizen> 3 </since_tizen>
105         public int Y
106         {
107             set
108             {
109                 y = (value);
110             }
111             get
112             {
113                 return y;
114             }
115         }
116
117         /// <summary>
118         /// The width of the rectangle.
119         /// </summary>
120         /// <since_tizen> 3 </since_tizen>
121         public int Width
122         {
123             set
124             {
125                 width = (value);
126             }
127             get
128             {
129                 return width;
130             }
131         }
132
133         /// <summary>
134         /// The height of the rectangle.
135         /// </summary>
136         /// <since_tizen> 3 </since_tizen>
137         public int Height
138         {
139             set
140             {
141                 height = (value);
142             }
143             get
144             {
145                 return height;
146             }
147         }
148
149         private int x
150         {
151             set
152             {
153                 Interop.Rectangle.Rectangle_x_set(swigCPtr, value);
154                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
155             }
156             get
157             {
158                 int ret = Interop.Rectangle.Rectangle_x_get(swigCPtr);
159                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
160                 return ret;
161             }
162         }
163
164         private int left
165         {
166             set
167             {
168                 Interop.Rectangle.Rectangle_left_set(swigCPtr, value);
169                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
170             }
171             get
172             {
173                 int ret = Interop.Rectangle.Rectangle_left_get(swigCPtr);
174                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
175                 return ret;
176             }
177         }
178
179         private int y
180         {
181             set
182             {
183                 Interop.Rectangle.Rectangle_y_set(swigCPtr, value);
184                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
185             }
186             get
187             {
188                 int ret = Interop.Rectangle.Rectangle_y_get(swigCPtr);
189                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
190                 return ret;
191             }
192         }
193
194         private int right
195         {
196             set
197             {
198                 Interop.Rectangle.Rectangle_right_set(swigCPtr, value);
199                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
200             }
201             get
202             {
203                 int ret = Interop.Rectangle.Rectangle_right_get(swigCPtr);
204                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
205                 return ret;
206             }
207         }
208
209         private int width
210         {
211             set
212             {
213                 Interop.Rectangle.Rectangle_width_set(swigCPtr, value);
214                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
215             }
216             get
217             {
218                 int ret = Interop.Rectangle.Rectangle_width_get(swigCPtr);
219                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
220                 return ret;
221             }
222         }
223
224         private int bottom
225         {
226             set
227             {
228                 Interop.Rectangle.Rectangle_bottom_set(swigCPtr, value);
229                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
230             }
231             get
232             {
233                 int ret = Interop.Rectangle.Rectangle_bottom_get(swigCPtr);
234                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
235                 return ret;
236             }
237         }
238
239         private int height
240         {
241             set
242             {
243                 Interop.Rectangle.Rectangle_height_set(swigCPtr, value);
244                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
245             }
246             get
247             {
248                 int ret = Interop.Rectangle.Rectangle_height_get(swigCPtr);
249                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
250                 return ret;
251             }
252         }
253
254         private int top
255         {
256             set
257             {
258                 Interop.Rectangle.Rectangle_top_set(swigCPtr, value);
259                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
260             }
261             get
262             {
263                 int ret = Interop.Rectangle.Rectangle_top_get(swigCPtr);
264                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
265                 return ret;
266             }
267         }
268
269         /// <summary>
270         /// THe Equality operator.
271         /// </summary>
272         /// <param name="a">The first operand.</param>
273         /// <param name="b">The second operand.</param>
274         /// <returns>True if the boxes are exactly the same.</returns>
275         /// <since_tizen> 3 </since_tizen>
276         public static bool operator ==(Rectangle a, Rectangle b)
277         {
278             // If both are null, or both are same instance, return true.
279             if (System.Object.ReferenceEquals(a, b))
280             {
281                 return true;
282             }
283
284             // If one is null, but not both, return false.
285             if (((object)a == null) || ((object)b == null))
286             {
287                 return false;
288             }
289
290             // Return true if the fields match:
291             return a.X == b.X && a.Y == b.Y && a.Width == b.Width && a.Height == b.Height;
292         }
293
294         /// <summary>
295         /// Inequality operator.
296         /// </summary>
297         /// <param name="a">The first rectangle.</param>
298         /// <param name="b">The second rectangle.</param>
299         /// <returns>True if the rectangles are not identical.</returns>
300         /// <since_tizen> 3 </since_tizen>
301         public static bool operator !=(Rectangle a, Rectangle b)
302         {
303             return !(a == b);
304         }
305
306         /// <summary>
307         /// Dispose.
308         /// </summary>
309         /// <since_tizen> 3 </since_tizen>
310         public void Dispose()
311         {
312             //Throw excpetion if Dispose() is called in separate thread.
313             if (!Window.IsInstalled())
314             {
315                 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
316             }
317
318             if (isDisposeQueued)
319             {
320                 Dispose(DisposeTypes.Implicit);
321             }
322             else
323             {
324                 Dispose(DisposeTypes.Explicit);
325                 System.GC.SuppressFinalize(this);
326             }
327         }
328
329         /// <summary>
330         /// Equality operator.
331         /// </summary>
332         /// <param name="o">The object to compare with the current object.</param>
333         /// <returns>True if boxes are exactly same.</returns>
334         /// <since_tizen> 4 </since_tizen>
335         public override bool Equals(object o)
336         {
337             if(o == null)
338             {
339                 return false;
340             }
341             if(!(o is Rectangle))
342             {
343                 return false;
344             }
345             Rectangle r = (Rectangle)o;
346
347             // Return true if the fields match:
348             return X == r.X && Y == r.Y && Width == r.Width && Height == r.Height;
349         }
350
351         /// <summary>
352         /// Serves as the default hash function.
353         /// </summary>
354         /// <returns>A hash code for the current object.</returns>
355         /// <since_tizen> 4 </since_tizen>
356         public override int GetHashCode()
357         {
358             return base.GetHashCode();
359         }
360
361         /// <summary>
362         /// Assignment from individual values.
363         /// </summary>
364         /// <param name="newX">The x coordinate.</param>
365         /// <param name="newY">The y coordinate.</param>
366         /// <param name="newWidth">The width.</param>
367         /// <param name="newHeight">The height.</param>
368         /// <since_tizen> 3 </since_tizen>
369         public void Set(int newX, int newY, int newWidth, int newHeight)
370         {
371             Interop.Rectangle.Rectangle_Set(swigCPtr, newX, newY, newWidth, newHeight);
372             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
373         }
374
375         /// <summary>
376         /// Determines whether or not this rectangle is empty.
377         /// </summary>
378         /// <returns>True if width or height are zero.</returns>
379         /// <since_tizen> 3 </since_tizen>
380         public bool IsEmpty()
381         {
382             bool ret = Interop.Rectangle.Rectangle_IsEmpty(swigCPtr);
383             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
384             return ret;
385         }
386
387         /// <summary>
388         /// Gets the left of the rectangle.
389         /// </summary>
390         /// <returns>The left edge of the rectangle.</returns>
391         /// <since_tizen> 3 </since_tizen>
392         public int Left()
393         {
394             int ret = Interop.Rectangle.Rectangle_Left(swigCPtr);
395             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
396             return ret;
397         }
398
399         /// <summary>
400         /// Gets the right of the rectangle.
401         /// </summary>
402         /// <returns>The right edge of the rectangle.</returns>
403         /// <since_tizen> 3 </since_tizen>
404         public int Right()
405         {
406             int ret = Interop.Rectangle.Rectangle_Right(swigCPtr);
407             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
408             return ret;
409         }
410
411         /// <summary>
412         /// Gets the top of the rectangle.
413         /// </summary>
414         /// <returns>The top of the rectangle.</returns>
415         /// <since_tizen> 3 </since_tizen>
416         public int Top()
417         {
418             int ret = Interop.Rectangle.Rectangle_Top(swigCPtr);
419             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
420             return ret;
421         }
422
423         /// <summary>
424         /// Gets the bottom of the rectangle.
425         /// </summary>
426         /// <returns>The bottom of the rectangle.</returns>
427         /// <since_tizen> 3 </since_tizen>
428         public int Bottom()
429         {
430             int ret = Interop.Rectangle.Rectangle_Bottom(swigCPtr);
431             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
432             return ret;
433         }
434
435         /// <summary>
436         /// Gets the area of the rectangle.
437         /// </summary>
438         /// <returns>The area of the rectangle.</returns>
439         /// <since_tizen> 3 </since_tizen>
440         public int Area()
441         {
442             int ret = Interop.Rectangle.Rectangle_Area(swigCPtr);
443             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
444             return ret;
445         }
446
447         /// <summary>
448         /// Determines whether or not this rectangle and the specified rectangle intersect.
449         /// </summary>
450         /// <param name="other">The other rectangle to test against this rectangle.</param>
451         /// <returns>True if the rectangles intersect.</returns>
452         /// <since_tizen> 3 </since_tizen>
453         public bool Intersects(Rectangle other)
454         {
455             bool ret = Interop.Rectangle.Rectangle_Intersects(swigCPtr, Rectangle.getCPtr(other));
456             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
457             return ret;
458         }
459
460         /// <summary>
461         /// Determines whether or not this rectangle contains the specified rectangle.
462         /// </summary>
463         /// <param name="other">The other rectangle to test against this rectangle.</param>
464         /// <returns>True if the specified rectangle is contained.</returns>
465         /// <since_tizen> 3 </since_tizen>
466         public bool Contains(Rectangle other)
467         {
468             bool ret = Interop.Rectangle.Rectangle_Contains(swigCPtr, Rectangle.getCPtr(other));
469             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
470             return ret;
471         }
472
473         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Rectangle obj)
474         {
475             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
476         }
477
478         /// <summary>
479         /// Dispose.
480         /// </summary>
481         /// <since_tizen> 3 </since_tizen>
482         protected virtual void Dispose(DisposeTypes type)
483         {
484             if (disposed)
485             {
486                 return;
487             }
488
489             if (type == DisposeTypes.Explicit)
490             {
491                 //Called by User
492                 //Release your own managed resources here.
493                 //You should release all of your own disposable objects here.
494             }
495
496             //Release your own unmanaged resources here.
497             //You should not access any managed member here except static instance.
498             //because the execution order of Finalizes is non-deterministic.
499
500             if (swigCPtr.Handle != global::System.IntPtr.Zero)
501             {
502                 if (swigCMemOwn)
503                 {
504                     swigCMemOwn = false;
505                     Interop.Rectangle.delete_Rectangle(swigCPtr);
506                 }
507                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
508             }
509             disposed = true;
510         }
511     }
512 }