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