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