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