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