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