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