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