Merge "[Tizen.Pims.Contacts]Fix XML Doc warnings"
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Size2D.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
18 namespace Tizen.NUI
19 {
20
21     /// <summary>
22     /// A two-dimensional size.
23     /// </summary>
24     public class Size2D : global::System.IDisposable
25     {
26         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
27         protected bool swigCMemOwn;
28
29         internal Size2D(global::System.IntPtr cPtr, bool cMemoryOwn)
30         {
31             swigCMemOwn = cMemoryOwn;
32             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
33         }
34
35         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Size2D obj)
36         {
37             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
38         }
39
40         //A Flag to check who called Dispose(). (By User or DisposeQueue)
41         private bool isDisposeQueued = false;
42         //A Flat to check if it is already disposed.
43         protected bool disposed = false;
44
45         ~Size2D()
46         {
47             if(!isDisposeQueued)
48             {
49                 isDisposeQueued = true;
50                 DisposeQueue.Instance.Add(this);
51             }
52         }
53
54         /// <summary>
55         /// Dispose.
56         /// </summary>
57         /// <since_tizen> 3 </since_tizen>
58         public void Dispose()
59         {
60             //Throw excpetion if Dispose() is called in separate thread.
61             if (!Window.IsInstalled())
62             {
63                 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
64             }
65
66             if (isDisposeQueued)
67             {
68                 Dispose(DisposeTypes.Implicit);
69             }
70             else
71             {
72                 Dispose(DisposeTypes.Explicit);
73                 System.GC.SuppressFinalize(this);
74             }
75         }
76
77         protected virtual void Dispose(DisposeTypes type)
78         {
79             if (disposed)
80             {
81                 return;
82             }
83
84             if(type == DisposeTypes.Explicit)
85             {
86                 //Called by User
87                 //Release your own managed resources here.
88                 //You should release all of your own disposable objects here.
89             }
90
91             //Release your own unmanaged resources here.
92             //You should not access any managed member here except static instance.
93             //because the execution order of Finalizes is non-deterministic.
94
95             if (swigCPtr.Handle != global::System.IntPtr.Zero)
96             {
97                 if (swigCMemOwn)
98                 {
99                     swigCMemOwn = false;
100                     NDalicPINVOKE.delete_Vector2(swigCPtr);
101                 }
102                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
103             }
104             disposed = true;
105         }
106
107         /// <summary>
108         /// The addition operator for A+B.
109         /// </summary>
110         /// <param name="arg1">Size A.</param>
111         /// <param name="arg2">Size to assign B.</param>
112         /// <returns>A size containing the result of the addition.</returns>
113         /// <since_tizen> 3 </since_tizen>
114         public static Size2D operator +(Size2D arg1, Size2D arg2)
115         {
116             return arg1.Add(arg2);
117         }
118
119         /// <summary>
120         /// The subtraction operator for A-B.
121         /// </summary>
122         /// <param name="arg1">Size A.</param>
123         /// <param name="arg2">Size to subtract B.</param>
124         /// <returns>A size containing the result of the subtraction.</returns>
125         /// <since_tizen> 3 </since_tizen>
126         public static Size2D operator -(Size2D arg1, Size2D arg2)
127         {
128             return arg1.Subtract(arg2);
129         }
130
131         /// <summary>
132         /// The unary negation operator.
133         /// </summary>
134         /// <param name="arg1">Size for unary negation.</param>
135         /// <returns>A size containing the negation.</returns>
136         /// <since_tizen> 3 </since_tizen>
137         public static Size2D operator -(Size2D arg1)
138         {
139             return arg1.Subtract();
140         }
141
142         /// <summary>
143         /// The multiplication operator.
144         /// </summary>
145         /// <param name="arg1">Size for multiplication.</param>
146         /// <param name="arg2">Size to multiply.</param>
147         /// <returns>A size containing the result of the multiplication.</returns>
148         /// <since_tizen> 3 </since_tizen>
149         public static Size2D operator *(Size2D arg1, Size2D arg2)
150         {
151             return arg1.Multiply(arg2);
152         }
153
154         /// <summary>
155         /// The multiplication operator.
156         /// </summary>
157         /// <param name="arg1">Size for multiplication</param>
158         /// <param name="arg2">The integer value to scale the size.</param>
159         /// <returns>A size containing the result of the scaling.</returns>
160
161         /// <since_tizen> 3 </since_tizen>
162         public static Size2D operator *(Size2D arg1, int arg2)
163         {
164             return arg1.Multiply(arg2);
165         }
166
167         /// <summary>
168         /// The division operator.
169         /// </summary>
170         /// <param name="arg1">Size for division.</param>
171         /// <param name="arg2">Size to divide.</param>
172         /// <returns>A size containing the result of the division.</returns>
173         /// <since_tizen> 3 </since_tizen>
174         public static Size2D operator /(Size2D arg1, Size2D arg2)
175         {
176             return arg1.Divide(arg2);
177         }
178
179         /// <summary>
180         /// The division operator.
181         /// </summary>
182         /// <param name="arg1">Size for division.</param>
183         /// <param name="arg2">The integer value to scale the size by.</param>
184         /// <returns>A size containing the result of the scaling.</returns>
185         /// <since_tizen> 3 </since_tizen>
186         public static Size2D operator /(Size2D arg1, int arg2)
187         {
188             return arg1.Divide(arg2);
189         }
190
191         /// <summary>
192         /// The array subscript operator.
193         /// </summary>
194         /// <param name="index">The subscript index.</param>
195         /// <returns>The float at the given index.</returns>
196         /// <since_tizen> 3 </since_tizen>
197         public float this[uint index]
198         {
199             get
200             {
201                 return ValueOfIndex(index);
202             }
203         }
204
205         /// <summary>
206         /// Gets the size from the pointer.
207         /// </summary>
208         /// <param name="cPtr">The pointer of the size.</param>
209         /// <returns>Size</returns>
210         internal static Size2D GetSize2DFromPtr(global::System.IntPtr cPtr)
211         {
212             Size2D ret = new Size2D(cPtr, false);
213             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
214             return ret;
215         }
216
217         /// <summary>
218         /// The constructor.
219         /// </summary>
220         /// <since_tizen> 3 </since_tizen>
221         public Size2D() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
222         {
223             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
224         }
225
226         /// <summary>
227         /// The constructor.
228         /// </summary>
229         /// <param name="x">The x (or width) component.</param>
230         /// <param name="y">The y (or height) component.</param>
231         /// <since_tizen> 3 </since_tizen>
232         public Size2D(int x, int y) : this(NDalicPINVOKE.new_Vector2__SWIG_1((float)x, (float)y), true)
233         {
234             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
235         }
236
237         private Size2D Add(Size2D rhs)
238         {
239             Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Add(swigCPtr, Size2D.getCPtr(rhs)), true);
240             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
241             return ret;
242         }
243
244         private Size2D Subtract(Size2D rhs)
245         {
246             Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
247             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
248             return ret;
249         }
250
251
252         private Size2D Multiply(Size2D rhs)
253         {
254             Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
255             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
256             return ret;
257         }
258
259         private Size2D Multiply(int rhs)
260         {
261             Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, (float)rhs), true);
262             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
263             return ret;
264         }
265
266
267         private Size2D Divide(Size2D rhs)
268         {
269             Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
270             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
271             return ret;
272         }
273
274         private Size2D Divide(int rhs)
275         {
276             Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, (float)rhs), true);
277             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
278             return ret;
279         }
280
281         private Size2D Subtract()
282         {
283             Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Subtract__SWIG_1(swigCPtr), true);
284             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
285             return ret;
286         }
287
288         /// <summary>
289         /// Checks equality.<br>
290         /// Utilizes appropriate machine epsilon values.<br>
291         /// </summary>
292         /// <param name="rhs">The size to test against.</param>
293         /// <returns>True if the sizes are equal.</returns>
294         /// <since_tizen> 3 </since_tizen>
295         public bool EqualTo(Size2D rhs)
296         {
297             bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, Size2D.getCPtr(rhs));
298             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
299             return ret;
300         }
301
302         /// <summary>
303         /// Checks inequality.<br>
304         /// Utilizes appropriate machine epsilon values.<br>
305         /// </summary>
306         /// <param name="rhs">The size to test against.</param>
307         /// <returns>True if the sizes are not equal.</returns>
308         /// <since_tizen> 3 </since_tizen>
309         public bool NotEqualTo(Size2D rhs)
310         {
311             bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, Size2D.getCPtr(rhs));
312             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
313             return ret;
314         }
315
316         private int ValueOfIndex(uint index)
317         {
318             int ret = (int)NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
319             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
320             return ret;
321         }
322
323         /// <summary>
324         /// The property for the width component of a size.
325         /// </summary>
326         /// <since_tizen> 3 </since_tizen>
327         public int Width
328         {
329             set
330             {
331                 NDalicPINVOKE.Vector2_Width_set(swigCPtr, (float)value);
332                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
333             }
334             get
335             {
336                 float ret = NDalicPINVOKE.Vector2_Width_get(swigCPtr);
337                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
338                 return (int)ret;
339             }
340         }
341
342         /// <summary>
343         /// The property for the height component of a size.
344         /// </summary>
345         /// <since_tizen> 3 </since_tizen>
346         public int Height
347         {
348             set
349             {
350                 NDalicPINVOKE.Vector2_Height_set(swigCPtr, (float)value);
351                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
352             }
353             get
354             {
355                 float ret = NDalicPINVOKE.Vector2_Height_get(swigCPtr);
356                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
357                 return (int)ret;
358             }
359         }
360
361         /// <summary>
362         /// The type cast operator, Size2D to Vector2.
363         /// </summary>
364         /// <param name="size">An object of the Size2D type.</param>
365         /// <since_tizen> 3 </since_tizen>
366         public static implicit operator Vector2(Size2D size)
367         {
368             return new Vector2((float)size.Width, (float)size.Height);
369         }
370
371         /// <summary>
372         /// The type cast operator, Vector2 to Size2D type.
373         /// </summary>
374         /// <param name="vec">An object of the Vector2 type.</param>
375         /// <since_tizen> 3 </since_tizen>
376         public static implicit operator Size2D(Vector2 vec)
377         {
378             return new Size2D((int)vec.X, (int)vec.Y);
379         }
380
381         /// <summary>
382         /// The type cast operator, Size2D to Uint16Pair.
383         /// </summary>
384         /// <param name="size2d">An object of the Size2D type.</param>
385         /// <since_tizen> 4 </since_tizen>
386         public static implicit operator Uint16Pair(Size2D size2d)
387         {
388             return new Uint16Pair((uint)size2d.Width, (uint)size2d.Height);
389         }
390
391         /// <summary>
392         /// The type cast operator, Uint16Pair to Size2D type.
393         /// </summary>
394         /// <param name="pair">An object of the Vector2 type.</param>
395         /// <since_tizen> 4 </since_tizen>
396         public static implicit operator Size2D(Uint16Pair pair)
397         {
398             return new Size2D((int)pair.GetWidth(), (int)pair.GetWidth());
399         }
400
401
402     }
403
404 }