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