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