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