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