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