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