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