Release 4.0.0-preview1-00235
[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         /// The Inequality operator.
128         /// </summary>
129         /// <param name="a">The first rectangle.</param>
130         /// <param name="b">The second rectangle.</param>
131         /// <returns>True if the rectangles are not identical.</returns>
132         public static bool operator !=(Rectangle a, Rectangle b)
133         {
134             return !(a == b);
135         }
136
137         /// <summary>
138         /// The x position of the rectangle.
139         /// </summary>
140         public int X
141         {
142             set
143             {
144                 x = ( value );
145             }
146             get
147             {
148                 return x;
149             }
150             }
151
152         /// <summary>
153         /// The Y position of the rectangle.
154         /// </summary>
155         public int Y
156         {
157             set
158             {
159                 y = ( value );
160             }
161             get
162             {
163                 return y;
164             }
165         }
166
167         /// <summary>
168         /// The width of the rectangle.
169         /// </summary>
170         public int Width
171         {
172             set
173             {
174                 width = ( value );
175             }
176             get
177             {
178                 return width;
179             }
180         }
181
182         /// <summary>
183         /// The height of the rectangle.
184         /// </summary>
185         public int Height
186         {
187             set
188             {
189                 height = ( value );
190             }
191             get
192             {
193                 return height;
194             }
195         }
196
197         /// <summary>
198         /// The constructor.
199         /// </summary>
200         public Rectangle() : this(NDalicPINVOKE.new_Rectangle__SWIG_0(), true)
201         {
202             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
203         }
204
205         /// <summary>
206         /// The constructor.
207         /// </summary>
208         /// <param name="x">The x coordinate (or left).</param>
209         /// <param name="y">The y coordinate (or right).</param>
210         /// <param name="width">The width (or bottom).</param>
211         /// <param name="height">The height (or top).</param>
212         public Rectangle(int x, int y, int width, int height) : this(NDalicPINVOKE.new_Rectangle__SWIG_1(x, y, width, height), true)
213         {
214             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
215         }
216
217         /// <summary>
218         /// Assignment from individual values.
219         /// </summary>
220         /// <param name="newX">The x coordinate.</param>
221         /// <param name="newY">The y coordinate.</param>
222         /// <param name="newWidth">The width.</param>
223         /// <param name="newHeight">The height./param>
224         public void Set(int newX, int newY, int newWidth, int newHeight)
225         {
226             NDalicPINVOKE.Rectangle_Set(swigCPtr, newX, newY, newWidth, newHeight);
227             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
228         }
229
230         /// <summary>
231         /// Determines whether or not this rectangle is empty.
232         /// </summary>
233         /// <returns>True if width or height are zero.</returns>
234         public bool IsEmpty()
235         {
236             bool ret = NDalicPINVOKE.Rectangle_IsEmpty(swigCPtr);
237             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
238             return ret;
239         }
240
241         /// <summary>
242         /// Gets the left of the rectangle.
243         /// </summary>
244         /// <returns>The left edge of the rectangle.</returns>
245         public int Left()
246         {
247             int ret = NDalicPINVOKE.Rectangle_Left(swigCPtr);
248             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
249             return ret;
250         }
251
252         /// <summary>
253         /// Gets the right of the rectangle.
254         /// </summary>
255         /// <returns>The right edge of the rectangle.</returns>
256         public int Right()
257         {
258             int ret = NDalicPINVOKE.Rectangle_Right(swigCPtr);
259             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
260             return ret;
261         }
262
263         /// <summary>
264         /// Gets the top of the rectangle.
265         /// </summary>
266         /// <returns>The top of the rectangle.</returns>
267         public int Top()
268         {
269             int ret = NDalicPINVOKE.Rectangle_Top(swigCPtr);
270             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
271             return ret;
272         }
273
274         /// <summary>
275         /// Gets the bottom of the rectangle.
276         /// </summary>
277         /// <returns>The bottom of the rectangle.</returns>
278         public int Bottom()
279         {
280             int ret = NDalicPINVOKE.Rectangle_Bottom(swigCPtr);
281             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
282             return ret;
283         }
284
285         /// <summary>
286         /// Gets the area of the rectangle.
287         /// </summary>
288         /// <returns>The area of the rectangle.</returns>
289         public int Area()
290         {
291             int ret = NDalicPINVOKE.Rectangle_Area(swigCPtr);
292             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
293             return ret;
294         }
295
296         /// <summary>
297         /// Determines whether or not this rectangle and the specified rectangle intersect.
298         /// </summary>
299         /// <param name="other">The other rectangle to test against this rectangle.</param>
300         /// <returns>True if the rectangles intersect.</returns>
301         public bool Intersects(Rectangle other)
302         {
303             bool ret = NDalicPINVOKE.Rectangle_Intersects(swigCPtr, Rectangle.getCPtr(other));
304             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
305             return ret;
306         }
307
308         /// <summary>
309         /// Determines whether or not this rectangle contains the specified rectangle.
310         /// </summary>
311         /// <param name="other">The other rectangle to test against this rectangle.</param>
312         /// <returns>True if the specified rectangle is contained.</returns>
313         public bool Contains(Rectangle other)
314         {
315             bool ret = NDalicPINVOKE.Rectangle_Contains(swigCPtr, Rectangle.getCPtr(other));
316             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
317             return ret;
318         }
319
320         private int x
321         {
322             set
323             {
324                 NDalicPINVOKE.Rectangle_x_set(swigCPtr, value);
325                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
326             }
327             get
328             {
329                 int ret = NDalicPINVOKE.Rectangle_x_get(swigCPtr);
330                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
331                 return ret;
332             }
333         }
334
335         private int left
336         {
337             set
338             {
339                 NDalicPINVOKE.Rectangle_left_set(swigCPtr, value);
340                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
341             }
342             get
343             {
344                 int ret = NDalicPINVOKE.Rectangle_left_get(swigCPtr);
345                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
346                 return ret;
347             }
348         }
349
350         private int y
351         {
352             set
353             {
354                 NDalicPINVOKE.Rectangle_y_set(swigCPtr, value);
355                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
356             }
357             get
358             {
359                 int ret = NDalicPINVOKE.Rectangle_y_get(swigCPtr);
360                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
361                 return ret;
362             }
363         }
364
365         private int right
366         {
367             set
368             {
369                 NDalicPINVOKE.Rectangle_right_set(swigCPtr, value);
370                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
371             }
372             get
373             {
374                 int ret = NDalicPINVOKE.Rectangle_right_get(swigCPtr);
375                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
376                 return ret;
377             }
378         }
379
380         private int width
381         {
382             set
383             {
384                 NDalicPINVOKE.Rectangle_width_set(swigCPtr, value);
385                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
386             }
387             get
388             {
389                 int ret = NDalicPINVOKE.Rectangle_width_get(swigCPtr);
390                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
391                 return ret;
392             }
393         }
394
395         private int bottom
396         {
397             set
398             {
399                 NDalicPINVOKE.Rectangle_bottom_set(swigCPtr, value);
400                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
401             }
402             get
403             {
404                 int ret = NDalicPINVOKE.Rectangle_bottom_get(swigCPtr);
405                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
406                 return ret;
407             }
408         }
409
410         private int height
411         {
412             set
413             {
414                 NDalicPINVOKE.Rectangle_height_set(swigCPtr, value);
415                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
416             }
417             get
418             {
419                 int ret = NDalicPINVOKE.Rectangle_height_get(swigCPtr);
420                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
421                 return ret;
422             }
423         }
424
425         private int top
426         {
427             set
428             {
429                 NDalicPINVOKE.Rectangle_top_set(swigCPtr, value);
430                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
431             }
432             get
433             {
434                 int ret = NDalicPINVOKE.Rectangle_top_get(swigCPtr);
435                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
436                 return ret;
437             }
438         }
439
440     }
441
442 }