[NUI] Fix build warning[CA1064]
[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 System.ComponentModel;
19 using Tizen.NUI.Binding;
20
21 namespace Tizen.NUI
22 {
23     /// <summary>
24     /// The Rectangle class.
25     /// </summary>
26     /// <since_tizen> 3 </since_tizen>
27     [Binding.TypeConverter(typeof(RectangleTypeConverter))]
28     public class Rectangle : Disposable, ICloneable
29     {
30         /// <summary>
31         /// The constructor.
32         /// </summary>
33         /// <since_tizen> 3 </since_tizen>
34         public Rectangle() : this(Interop.Rectangle.NewRectangle(), true)
35         {
36             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
37         }
38
39         /// <summary>
40         /// The constructor.
41         /// </summary>
42         /// <param name="x">The x coordinate (or left).</param>
43         /// <param name="y">The y coordinate (or right).</param>
44         /// <param name="width">The width (or bottom).</param>
45         /// <param name="height">The height (or top).</param>
46         /// <since_tizen> 3 </since_tizen>
47         public Rectangle(int x, int y, int width, int height) : this(Interop.Rectangle.NewRectangle(x, y, width, height), true)
48         {
49             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
50         }
51
52         internal Rectangle(Rectangle other) : this(other.x, other.y, other.width, other.height)
53         {
54         }
55
56         internal Rectangle(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
57         {
58         }
59
60         internal Rectangle(RectangleChangedCallback cb, int x, int y, int width, int height) : this(Interop.Rectangle.NewRectangle(x, y, width, height), true)
61         {
62             callback = cb;
63             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
64         }
65
66         internal Rectangle(RectangleChangedCallback cb) : this()
67         {
68             callback = cb;
69         }
70
71         internal Rectangle(RectangleChangedCallback cb, Rectangle other) : this(cb, other.x, other.y, other.width, other.height)
72         {
73         }
74
75         /// <summary>
76         /// The type cast operator, int to Rectangle.
77         /// </summary>
78         /// <param name="value">A value of int type.</param>
79         /// <returns>return a Extents instance</returns>
80         [EditorBrowsable(EditorBrowsableState.Never)]
81         public static implicit operator Rectangle(int value)
82         {
83             return new Rectangle(value, value, value, value);
84         }
85
86         internal delegate void RectangleChangedCallback(int x, int y, int width, int height);
87         private RectangleChangedCallback callback = null;
88
89         /// <summary>
90         /// The x position of the rectangle.
91         /// </summary>
92         /// <remarks>
93         /// The setter is deprecated in API8 and will be removed in API10. Please use new Rectangle(...) constructor.
94         /// </remarks>
95         /// <code>
96         /// // DO NOT use like the followings!
97         /// Rectangle rectangle = new Rectangle();
98         /// rectangle.X = 1; 
99         /// // Please USE like this
100         /// int x = 1, y = 2, width = 3, height = 4;
101         /// Rectangle rectangle = new Rectangle(x, y, width, height);
102         /// </code>
103         /// <since_tizen> 3 </since_tizen>
104         public int X
105         {
106             set
107             {
108                 Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Rectangle(...) constructor");
109
110                 x = (value);
111
112                 callback?.Invoke(X, Y, Width, Height);
113             }
114             get
115             {
116                 return x;
117             }
118         }
119
120         /// <summary>
121         /// The Y position of the rectangle.
122         /// </summary>
123         /// <remarks>
124         /// The setter is deprecated in API8 and will be removed in API10. Please use new Rectangle(...) constructor.
125         /// </remarks>
126         /// <code>
127         /// // DO NOT use like the followings!
128         /// Rectangle rectangle = new Rectangle();
129         /// rectangle.Y = 2; 
130         /// // Please USE like this
131         /// int x = 1, y = 2, width = 3, height = 4;
132         /// Rectangle rectangle = new Rectangle(x, y, width, height);
133         /// </code>
134         /// <since_tizen> 3 </since_tizen>
135         public int Y
136         {
137             set
138             {
139                 Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Rectangle(...) constructor");
140
141                 y = (value);
142
143                 callback?.Invoke(X, Y, Width, Height);
144             }
145             get
146             {
147                 return y;
148             }
149         }
150
151         /// <summary>
152         /// The width of the rectangle.
153         /// </summary>
154         /// <remarks>
155         /// The setter is deprecated in API8 and will be removed in API10. Please use new Rectangle(...) constructor.
156         /// </remarks>
157         /// <code>
158         /// // DO NOT use like the followings!
159         /// Rectangle rectangle = new Rectangle();
160         /// rectangle.Width = 3; 
161         /// // Please USE like this
162         /// int x = 1, y = 2, width = 3, height = 4;
163         /// Rectangle rectangle = new Rectangle(x, y, width, height);
164         /// </code>
165         /// <since_tizen> 3 </since_tizen>
166         public int Width
167         {
168             set
169             {
170                 Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Rectangle(...) constructor");
171
172                 width = (value);
173
174                 callback?.Invoke(X, Y, Width, Height);
175             }
176             get
177             {
178                 return width;
179             }
180         }
181
182         /// <summary>
183         /// The height of the rectangle.
184         /// </summary>
185         /// <remarks>
186         /// The setter is deprecated in API8 and will be removed in API10. Please use new Rectangle(...) constructor.
187         /// </remarks>
188         /// <code>
189         /// // DO NOT use like the followings!
190         /// Rectangle rectangle = new Rectangle();
191         /// rectangle.Height = 4; 
192         /// // Please USE like this
193         /// int x = 1, y = 2, width = 3, height = 4;
194         /// Rectangle rectangle = new Rectangle(x, y, width, height);
195         /// </code>
196         /// <since_tizen> 3 </since_tizen>
197         public int Height
198         {
199             set
200             {
201                 Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Rectangle(...) constructor");
202
203                 height = (value);
204
205                 callback?.Invoke(X, Y, Width, Height);
206             }
207             get
208             {
209                 return height;
210             }
211         }
212
213         private int x
214         {
215             set
216             {
217                 Interop.Rectangle.XSet(swigCPtr, value);
218                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
219             }
220             get
221             {
222                 int ret = Interop.Rectangle.XGet(swigCPtr);
223                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
224                 return ret;
225             }
226         }
227
228         private int left
229         {
230             set
231             {
232                 Interop.Rectangle.LeftSet(swigCPtr, value);
233                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
234             }
235             get
236             {
237                 int ret = Interop.Rectangle.LeftGet(swigCPtr);
238                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
239                 return ret;
240             }
241         }
242
243         private int y
244         {
245             set
246             {
247                 Interop.Rectangle.YSet(swigCPtr, value);
248                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
249             }
250             get
251             {
252                 int ret = Interop.Rectangle.YGet(swigCPtr);
253                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
254                 return ret;
255             }
256         }
257
258         private int right
259         {
260             set
261             {
262                 Interop.Rectangle.RightSet(swigCPtr, value);
263                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
264             }
265             get
266             {
267                 int ret = Interop.Rectangle.RightGet(swigCPtr);
268                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
269                 return ret;
270             }
271         }
272
273         private int width
274         {
275             set
276             {
277                 Interop.Rectangle.WidthSet(swigCPtr, value);
278                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
279             }
280             get
281             {
282                 int ret = Interop.Rectangle.WidthGet(swigCPtr);
283                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
284                 return ret;
285             }
286         }
287
288         private int bottom
289         {
290             set
291             {
292                 Interop.Rectangle.BottomSet(swigCPtr, value);
293                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
294             }
295             get
296             {
297                 int ret = Interop.Rectangle.BottomGet(swigCPtr);
298                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
299                 return ret;
300             }
301         }
302
303         private int height
304         {
305             set
306             {
307                 Interop.Rectangle.HeightSet(swigCPtr, value);
308                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
309             }
310             get
311             {
312                 int ret = Interop.Rectangle.HeightGet(swigCPtr);
313                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
314                 return ret;
315             }
316         }
317
318         private int top
319         {
320             set
321             {
322                 Interop.Rectangle.TopSet(swigCPtr, value);
323                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
324             }
325             get
326             {
327                 int ret = Interop.Rectangle.TopGet(swigCPtr);
328                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
329                 return ret;
330             }
331         }
332
333         /// <summary>
334         /// THe Equality operator.
335         /// </summary>
336         /// <param name="a">The first operand.</param>
337         /// <param name="b">The second operand.</param>
338         /// <returns>True if the boxes are exactly the same.</returns>
339         /// <since_tizen> 3 </since_tizen>
340         public static bool operator ==(Rectangle a, Rectangle b)
341         {
342             // If both are null, or both are same instance, return true.
343             if (System.Object.ReferenceEquals(a, b))
344             {
345                 return true;
346             }
347
348             // If one is null, but not both, return false.
349             if (((object)a == null) || ((object)b == null))
350             {
351                 return false;
352             }
353
354             // Return true if the fields match:
355             return a.X == b.X && a.Y == b.Y && a.Width == b.Width && a.Height == b.Height;
356         }
357
358         /// <summary>
359         /// Inequality operator.
360         /// </summary>
361         /// <param name="a">The first rectangle.</param>
362         /// <param name="b">The second rectangle.</param>
363         /// <returns>True if the rectangles are not identical.</returns>
364         /// <since_tizen> 3 </since_tizen>
365         public static bool operator !=(Rectangle a, Rectangle b)
366         {
367             return !(a == b);
368         }
369
370         /// <summary>
371         /// Equality operator.
372         /// </summary>
373         /// <param name="o">The object to compare with the current object.</param>
374         /// <returns>True if boxes are exactly same.</returns>
375         /// <since_tizen> 4 </since_tizen>
376         public override bool Equals(object o)
377         {
378             if (o == null)
379             {
380                 return false;
381             }
382             if (!(o is Rectangle))
383             {
384                 return false;
385             }
386             Rectangle r = (Rectangle)o;
387
388             // Return true if the fields match:
389             return X == r.X && Y == r.Y && Width == r.Width && Height == r.Height;
390         }
391
392         /// <summary>
393         /// Serves as the default hash function.
394         /// </summary>
395         /// <returns>A hash code for the current object.</returns>
396         /// <since_tizen> 4 </since_tizen>
397         public override int GetHashCode()
398         {
399             return base.GetHashCode();
400         }
401
402         /// <summary>
403         /// Assignment from individual values.
404         /// </summary>
405         /// <param name="newX">The x coordinate.</param>
406         /// <param name="newY">The y coordinate.</param>
407         /// <param name="newWidth">The width.</param>
408         /// <param name="newHeight">The height.</param>
409         /// <since_tizen> 3 </since_tizen>
410         public void Set(int newX, int newY, int newWidth, int newHeight)
411         {
412             Interop.Rectangle.Set(swigCPtr, newX, newY, newWidth, newHeight);
413             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
414         }
415
416         /// <summary>
417         /// Determines whether or not this rectangle is empty.
418         /// </summary>
419         /// <returns>True if width or height are zero.</returns>
420         /// <since_tizen> 3 </since_tizen>
421         public bool IsEmpty()
422         {
423             bool ret = Interop.Rectangle.IsEmpty(swigCPtr);
424             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
425             return ret;
426         }
427
428         /// <summary>
429         /// Gets the left of the rectangle.
430         /// </summary>
431         /// <returns>The left edge of the rectangle.</returns>
432         /// <since_tizen> 3 </since_tizen>
433         public int Left()
434         {
435             int ret = Interop.Rectangle.Left(swigCPtr);
436             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
437             return ret;
438         }
439
440         /// <summary>
441         /// Gets the right of the rectangle.
442         /// </summary>
443         /// <returns>The right edge of the rectangle.</returns>
444         /// <since_tizen> 3 </since_tizen>
445         public int Right()
446         {
447             int ret = Interop.Rectangle.Right(swigCPtr);
448             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
449             return ret;
450         }
451
452         /// <summary>
453         /// Gets the top of the rectangle.
454         /// </summary>
455         /// <returns>The top of the rectangle.</returns>
456         /// <since_tizen> 3 </since_tizen>
457         public int Top()
458         {
459             int ret = Interop.Rectangle.Top(swigCPtr);
460             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
461             return ret;
462         }
463
464         /// <summary>
465         /// Gets the bottom of the rectangle.
466         /// </summary>
467         /// <returns>The bottom of the rectangle.</returns>
468         /// <since_tizen> 3 </since_tizen>
469         public int Bottom()
470         {
471             int ret = Interop.Rectangle.Bottom(swigCPtr);
472             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
473             return ret;
474         }
475
476         /// <summary>
477         /// Gets the area of the rectangle.
478         /// </summary>
479         /// <returns>The area of the rectangle.</returns>
480         /// <since_tizen> 3 </since_tizen>
481         public int Area()
482         {
483             int ret = Interop.Rectangle.Area(swigCPtr);
484             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
485             return ret;
486         }
487
488         /// <summary>
489         /// Determines whether or not this rectangle and the specified rectangle intersect.
490         /// </summary>
491         /// <param name="other">The other rectangle to test against this rectangle.</param>
492         /// <returns>True if the rectangles intersect.</returns>
493         /// <since_tizen> 3 </since_tizen>
494         public bool Intersects(Rectangle other)
495         {
496             bool ret = Interop.Rectangle.Intersects(swigCPtr, Rectangle.getCPtr(other));
497             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
498             return ret;
499         }
500
501         /// <summary>
502         /// Determines whether or not this rectangle contains the specified rectangle.
503         /// </summary>
504         /// <param name="other">The other rectangle to test against this rectangle.</param>
505         /// <returns>True if the specified rectangle is contained.</returns>
506         /// <since_tizen> 3 </since_tizen>
507         public bool Contains(Rectangle other)
508         {
509             bool ret = Interop.Rectangle.Contains(swigCPtr, Rectangle.getCPtr(other));
510             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
511             return ret;
512         }
513
514         /// <inheritdoc/>
515         [EditorBrowsable(EditorBrowsableState.Never)]
516         public object Clone() => new Rectangle(this);
517
518         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Rectangle obj)
519         {
520             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
521         }
522
523         /// This will not be public opened.
524         [EditorBrowsable(EditorBrowsableState.Never)]
525         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
526         {
527             Interop.Rectangle.DeleteRectangle(swigCPtr);
528         }
529
530         /// <summary>
531         /// Determines whether the reference is null or the Rectangle has all 0 properties.
532         /// </summary>
533         internal static bool IsNullOrZero(Rectangle rectangle) => (rectangle == null || (rectangle.top == 0 && rectangle.right == 0 && rectangle.bottom == 0 && rectangle.left == 0));
534     }
535 }