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