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