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