[NUI] Split NUI Interop class (#804)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Size.cs
1 /*
2  * Copyright (c) 2018 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 using System;
19 using System.ComponentModel;
20 using Tizen.NUI.Binding;
21
22 namespace Tizen.NUI
23 {
24     /// <summary>
25     /// A three-dimensional size.
26     /// </summary>
27     /// <since_tizen> 5 </since_tizen>
28     [Tizen.NUI.Binding.TypeConverter(typeof(SizeTypeConverter))]
29     public class Size : global::System.IDisposable
30     {
31         /// <summary>swigCMemOwn.</summary>
32         /// <since_tizen> 5 </since_tizen>
33         protected bool swigCMemOwn;
34
35         /// <summary>
36         /// A Flat to check if it is already disposed.
37         /// </summary>
38         /// <since_tizen> 5 </since_tizen>
39         protected bool disposed = false;
40
41         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
42
43         //A Flag to check who called Dispose(). (By User or DisposeQueue)
44         private bool isDisposeQueued = false;
45
46         /// <summary>
47         /// The constructor.
48         /// </summary>
49         /// <since_tizen> 5 </since_tizen>
50         public Size() : this(Interop.Vector3.new_Vector3__SWIG_0(), true)
51         {
52             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
53         }
54
55         /// <summary>
56         /// The constructor.
57         /// </summary>
58         /// <param name="x">The x (or width) component.</param>
59         /// <param name="y">The y (or height) component.</param>
60         /// <param name="z">The z (or depth) component.</param>
61         /// <since_tizen> 5 </since_tizen>
62         public Size(float x, float y, float z) : this(Interop.Vector3.new_Vector3__SWIG_1(x, y, z), true)
63         {
64             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
65         }
66
67         /// <summary>
68         /// The constructor.
69         /// </summary>
70         /// <param name="size2d">Size2D with x (width) and y (height).</param>
71         /// <since_tizen> 5 </since_tizen>
72         public Size(Size2D size2d) : this(Interop.Vector3.new_Vector3__SWIG_3(Size2D.getCPtr(size2d)), true)
73         {
74             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
75         }
76
77         /// <summary>
78         /// Dispose.
79         /// </summary>
80         ~Size()
81         {
82             if (!isDisposeQueued)
83             {
84                 isDisposeQueued = true;
85                 DisposeQueue.Instance.Add(this);
86             }
87         }
88
89         /// <summary>
90         /// The Zero constant, (0.0f, 0.0f, 0.0f).
91         /// </summary>
92         /// <since_tizen> 5 </since_tizen>
93         public static Size Zero
94         {
95             get
96             {
97                 global::System.IntPtr cPtr = Interop.Vector3.Vector3_ZERO_get();
98                 Size ret = (cPtr == global::System.IntPtr.Zero) ? null : new Size(cPtr, false);
99                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
100                 return ret;
101             }
102         }
103
104         /// <summary>
105         /// The Width property for the width component of size
106         /// </summary>
107         /// <since_tizen> 5 </since_tizen>
108         public float Width
109         {
110             set
111             {
112                 Interop.Vector3.Vector3_Width_set(swigCPtr, value);
113                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
114             }
115             get
116             {
117                 float ret = Interop.Vector3.Vector3_Width_get(swigCPtr);
118                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
119                 return ret;
120             }
121         }
122
123         /// <summary>
124         /// The Height property for the height component of size.
125         /// </summary>
126         /// <since_tizen> 5 </since_tizen>
127         public float Height
128         {
129             set
130             {
131                 Interop.Vector3.Vector3_Height_set(swigCPtr, value);
132                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
133             }
134             get
135             {
136                 float ret = Interop.Vector3.Vector3_Height_get(swigCPtr);
137                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
138                 return ret;
139             }
140         }
141
142         /// <summary>
143         /// The Depth property for the depth component of size.
144         /// </summary>
145         /// <since_tizen> 5 </since_tizen>
146         public float Depth
147         {
148             set
149             {
150                 Interop.Vector3.Vector3_Depth_set(swigCPtr, value);
151                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
152             }
153             get
154             {
155                 float ret = Interop.Vector3.Vector3_Depth_get(swigCPtr);
156                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
157                 return ret;
158             }
159         }
160
161         /// <summary>
162         /// The addition operator for A+B.
163         /// </summary>
164         /// <param name="arg1">Size to assign A.</param>
165         /// <param name="arg2">Size to assign B.</param>
166         /// <returns>A size containing the result of the addition.</returns>
167         /// <since_tizen> 5 </since_tizen>
168         public static Size operator +(Size arg1, Size arg2)
169         {
170             return arg1.Add(arg2);
171         }
172
173         /// <summary>
174         /// The subtraction operator for A-B.
175         /// </summary>
176         /// <param name="arg1">Size to subtract A.</param>
177         /// <param name="arg2">Size to subtract B.</param>
178         /// <returns>The size containing the result of the subtraction.</returns>
179         /// <since_tizen> 5 </since_tizen>
180         public static Size operator -(Size arg1, Size arg2)
181         {
182             return arg1.Subtract(arg2);
183         }
184
185         /// <summary>
186         /// The unary negation operator.
187         /// </summary>
188         /// <param name="arg1">Size for unary negation.</param>
189         /// <returns>A size containing the negation.</returns>
190         /// <since_tizen> 5 </since_tizen>
191         public static Size operator -(Size arg1)
192         {
193             return arg1.Subtract();
194         }
195
196         /// <summary>
197         /// The multiplication operator.
198         /// </summary>
199         /// <param name="arg1">Size for multiplication.</param>
200         /// <param name="arg2">The size to multiply.</param>
201         /// <returns>A size containing the result of the multiplication.</returns>
202         /// <since_tizen> 5 </since_tizen>
203         public static Size operator *(Size arg1, Size arg2)
204         {
205             return arg1.Multiply(arg2);
206         }
207
208         /// <summary>
209         /// The multiplication operator.
210         /// </summary>
211         /// <param name="arg1">Size for multiplication.</param>
212         /// <param name="arg2">The float value to scale the size.</param>
213         /// <returns>A size containing the result of the scaling.</returns>
214         /// <since_tizen> 5 </since_tizen>
215         public static Size operator *(Size arg1, float arg2)
216         {
217             return arg1.Multiply(arg2);
218         }
219
220         /// <summary>
221         /// The division operator.
222         /// </summary>
223         /// <param name="arg1">Size for division.</param>
224         /// <param name="arg2">The size to divide.</param>
225         /// <returns>A size containing the result of the division.</returns>
226         /// <since_tizen> 5 </since_tizen>
227         public static Size operator /(Size arg1, Size arg2)
228         {
229             return arg1.Divide(arg2);
230         }
231
232         /// <summary>
233         /// The division operator.
234         /// </summary>
235         /// <param name="arg1">Size for division.</param>
236         /// <param name="arg2">The float value to scale the size by.</param>
237         /// <returns>A Size containing the result of the scaling.</returns>
238         /// <since_tizen> 5 </since_tizen>
239         public static Size operator /(Size arg1, float arg2)
240         {
241             return arg1.Divide(arg2);
242         }
243
244         /// <summary>
245         /// The array subscript operator.
246         /// </summary>
247         /// <param name="index">Subscript index.</param>
248         /// <returns>The float at the given index.</returns>
249         /// <since_tizen> 5 </since_tizen>
250         public float this[uint index]
251         {
252             get
253             {
254                 return ValueOfIndex(index);
255             }
256         }
257
258         /// <summary>
259         /// Dispose.
260         /// </summary>
261         /// <since_tizen> 5 </since_tizen>
262         public void Dispose()
263         {
264             //Throw excpetion if Dispose() is called in separate thread.
265             if (!Window.IsInstalled())
266             {
267                 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
268             }
269
270             if (isDisposeQueued)
271             {
272                 Dispose(DisposeTypes.Implicit);
273             }
274             else
275             {
276                 Dispose(DisposeTypes.Explicit);
277                 System.GC.SuppressFinalize(this);
278             }
279         }
280
281         /// <summary>
282         /// Determines whether the specified object is equal to the current object.
283         /// </summary>
284         /// <param name="obj">The object to compare with the current object.</param>
285         /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
286         public override bool Equals(System.Object obj)
287         {
288             Size size = obj as Size;
289             bool equal = false;
290             if (Width == size?.Width && Height == size?.Height && Depth == size?.Depth)
291             {
292                 equal = true;
293             }
294             return equal;
295         }
296
297         /// <summary>
298         /// Gets the the hash code of this Size.
299         /// </summary>
300         /// <returns>The Hash Code.</returns>
301         /// <since_tizen> 6 </since_tizen>
302         public override int GetHashCode()
303         {
304             return swigCPtr.Handle.GetHashCode();
305         }
306
307         /// <summary>
308         /// Checks equality.<br />
309         /// Utilizes appropriate machine epsilon values.<br />
310         /// </summary>
311         /// <param name="rhs">The size to test against.</param>
312         /// <returns>True if the sizes are equal.</returns>
313         /// <since_tizen> 5 </since_tizen>
314         public bool EqualTo(Size rhs)
315         {
316             bool ret = Interop.Vector3.Vector3_EqualTo(swigCPtr, Size.getCPtr(rhs));
317             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
318             return ret;
319         }
320
321         /// <summary>
322         /// Checks inequality.<br />
323         /// Utilizes appropriate machine epsilon values.<br />
324         /// </summary>
325         /// <param name="rhs">The size to test against.</param>
326         /// <returns>True if the sizes are not equal.</returns>
327         /// <since_tizen> 5 </since_tizen>
328         public bool NotEqualTo(Size rhs)
329         {
330             bool ret = Interop.Vector3.Vector3_NotEqualTo(swigCPtr, Size.getCPtr(rhs));
331             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
332             return ret;
333         }
334
335
336
337         /// <summary>
338         /// The type cast operator, Size to Vector3.
339         /// </summary>
340         /// <param name="size">The object of size type.</param>
341         /// <since_tizen> 5 </since_tizen>
342         public static implicit operator Vector3(Size size)
343         {
344             return new Vector3(size.Width, size.Height, size.Depth);
345         }
346
347         /// <summary>
348         /// The type cast operator, Vector3 to Size type.
349         /// </summary>
350         /// <param name="vec">The object of Vector3 type.</param>
351         /// <since_tizen> 5 </since_tizen>
352         public static implicit operator Size(Vector3 vec)
353         {
354             return new Size(vec.Width, vec.Height, vec.Depth);
355         }
356
357         internal static Size GetSizeFromPtr(global::System.IntPtr cPtr)
358         {
359             Size ret = new Size(cPtr, false);
360             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
361             return ret;
362         }
363
364         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Size obj)
365         {
366             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
367         }
368
369         internal Size(global::System.IntPtr cPtr, bool cMemoryOwn)
370         {
371             swigCMemOwn = cMemoryOwn;
372             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
373         }
374
375         /// <summary>
376         /// Dispose.
377         /// </summary>
378         /// <since_tizen> 5 </since_tizen>
379         protected virtual void Dispose(DisposeTypes type)
380         {
381             if (disposed)
382             {
383                 return;
384             }
385
386             if (type == DisposeTypes.Explicit)
387             {
388                 //Called by User
389                 //Release your own managed resources here.
390                 //You should release all of your own disposable objects here.
391
392             }
393
394             //Release your own unmanaged resources here.
395             //You should not access any managed member here except static instance.
396             //because the execution order of Finalizes is non-deterministic.
397
398             if (swigCPtr.Handle != global::System.IntPtr.Zero)
399             {
400                 if (swigCMemOwn)
401                 {
402                     swigCMemOwn = false;
403                     Interop.Vector3.delete_Vector3(swigCPtr);
404                 }
405                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
406             }
407
408             disposed = true;
409         }
410
411         private Size Add(Size rhs)
412         {
413             Size ret = new Size(Interop.Vector3.Vector3_Add(swigCPtr, Size.getCPtr(rhs)), true);
414             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
415             return ret;
416         }
417
418         private Size Subtract(Size rhs)
419         {
420             Size ret = new Size(Interop.Vector3.Vector3_Subtract__SWIG_0(swigCPtr, Size.getCPtr(rhs)), true);
421             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
422             return ret;
423         }
424
425         private Size Multiply(Size rhs)
426         {
427             Size ret = new Size(Interop.Vector3.Vector3_Multiply__SWIG_0(swigCPtr, Size.getCPtr(rhs)), true);
428             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
429             return ret;
430         }
431
432         private Size Multiply(float rhs)
433         {
434             Size ret = new Size(Interop.Vector3.Vector3_Multiply__SWIG_1(swigCPtr, rhs), true);
435             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
436             return ret;
437         }
438
439         private Size Divide(Size rhs)
440         {
441             Size ret = new Size(Interop.Vector3.Vector3_Divide__SWIG_0(swigCPtr, Size.getCPtr(rhs)), true);
442             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
443             return ret;
444         }
445
446         private Size Divide(float rhs)
447         {
448             Size ret = new Size(Interop.Vector3.Vector3_Divide__SWIG_1(swigCPtr, rhs), true);
449             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
450             return ret;
451         }
452
453         private Size Subtract()
454         {
455             Size ret = new Size(Interop.Vector3.Vector3_Subtract__SWIG_1(swigCPtr), true);
456             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
457             return ret;
458         }
459
460         private float ValueOfIndex(uint index)
461         {
462             float ret = Interop.Vector3.Vector3_ValueOfIndex__SWIG_0(swigCPtr, index);
463             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
464             return ret;
465         }
466     }
467 }
468