[NUI] Integreation from dalihub (#988)
[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                 callback?.Invoke(Width, Height, Depth);
116             }
117             get
118             {
119                 float ret = Interop.Vector3.Vector3_Width_get(swigCPtr);
120                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
121                 return ret;
122             }
123         }
124
125         /// <summary>
126         /// The Height property for the height component of size.
127         /// </summary>
128         /// <since_tizen> 5 </since_tizen>
129         public float Height
130         {
131             set
132             {
133                 Interop.Vector3.Vector3_Height_set(swigCPtr, value);
134                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
135
136                 callback?.Invoke(Width, Height, Depth);
137             }
138             get
139             {
140                 float ret = Interop.Vector3.Vector3_Height_get(swigCPtr);
141                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
142                 return ret;
143             }
144         }
145
146         /// <summary>
147         /// The Depth property for the depth component of size.
148         /// </summary>
149         /// <since_tizen> 5 </since_tizen>
150         public float Depth
151         {
152             set
153             {
154                 Interop.Vector3.Vector3_Depth_set(swigCPtr, value);
155                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
156
157                 callback?.Invoke(Width, Height, Depth);
158             }
159             get
160             {
161                 float ret = Interop.Vector3.Vector3_Depth_get(swigCPtr);
162                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
163                 return ret;
164             }
165         }
166
167         /// <summary>
168         /// The addition operator for A+B.
169         /// </summary>
170         /// <param name="arg1">Size to assign A.</param>
171         /// <param name="arg2">Size to assign B.</param>
172         /// <returns>A size containing the result of the addition.</returns>
173         /// <since_tizen> 5 </since_tizen>
174         public static Size operator +(Size arg1, Size arg2)
175         {
176             return arg1.Add(arg2);
177         }
178
179         /// <summary>
180         /// The subtraction operator for A-B.
181         /// </summary>
182         /// <param name="arg1">Size to subtract A.</param>
183         /// <param name="arg2">Size to subtract B.</param>
184         /// <returns>The size containing the result of the subtraction.</returns>
185         /// <since_tizen> 5 </since_tizen>
186         public static Size operator -(Size arg1, Size arg2)
187         {
188             return arg1.Subtract(arg2);
189         }
190
191         /// <summary>
192         /// The unary negation operator.
193         /// </summary>
194         /// <param name="arg1">Size for unary negation.</param>
195         /// <returns>A size containing the negation.</returns>
196         /// <since_tizen> 5 </since_tizen>
197         public static Size operator -(Size arg1)
198         {
199             return arg1.Subtract();
200         }
201
202         /// <summary>
203         /// The multiplication operator.
204         /// </summary>
205         /// <param name="arg1">Size for multiplication.</param>
206         /// <param name="arg2">The size to multiply.</param>
207         /// <returns>A size containing the result of the multiplication.</returns>
208         /// <since_tizen> 5 </since_tizen>
209         public static Size operator *(Size arg1, Size arg2)
210         {
211             return arg1.Multiply(arg2);
212         }
213
214         /// <summary>
215         /// The multiplication operator.
216         /// </summary>
217         /// <param name="arg1">Size for multiplication.</param>
218         /// <param name="arg2">The float value to scale the size.</param>
219         /// <returns>A size containing the result of the scaling.</returns>
220         /// <since_tizen> 5 </since_tizen>
221         public static Size operator *(Size arg1, float arg2)
222         {
223             return arg1.Multiply(arg2);
224         }
225
226         /// <summary>
227         /// The division operator.
228         /// </summary>
229         /// <param name="arg1">Size for division.</param>
230         /// <param name="arg2">The size to divide.</param>
231         /// <returns>A size containing the result of the division.</returns>
232         /// <since_tizen> 5 </since_tizen>
233         public static Size operator /(Size arg1, Size arg2)
234         {
235             return arg1.Divide(arg2);
236         }
237
238         /// <summary>
239         /// The division operator.
240         /// </summary>
241         /// <param name="arg1">Size for division.</param>
242         /// <param name="arg2">The float value to scale the size by.</param>
243         /// <returns>A Size containing the result of the scaling.</returns>
244         /// <since_tizen> 5 </since_tizen>
245         public static Size operator /(Size arg1, float arg2)
246         {
247             return arg1.Divide(arg2);
248         }
249
250         /// <summary>
251         /// The array subscript operator.
252         /// </summary>
253         /// <param name="index">Subscript index.</param>
254         /// <returns>The float at the given index.</returns>
255         /// <since_tizen> 5 </since_tizen>
256         public float this[uint index]
257         {
258             get
259             {
260                 return ValueOfIndex(index);
261             }
262         }
263
264         /// <summary>
265         /// Dispose.
266         /// </summary>
267         /// <since_tizen> 5 </since_tizen>
268         public void Dispose()
269         {
270             //Throw excpetion if Dispose() is called in separate thread.
271             if (!Window.IsInstalled())
272             {
273                 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
274             }
275
276             if (isDisposeQueued)
277             {
278                 Dispose(DisposeTypes.Implicit);
279             }
280             else
281             {
282                 Dispose(DisposeTypes.Explicit);
283                 System.GC.SuppressFinalize(this);
284             }
285         }
286
287         /// <summary>
288         /// Determines whether the specified object is equal to the current object.
289         /// </summary>
290         /// <param name="obj">The object to compare with the current object.</param>
291         /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
292         public override bool Equals(System.Object obj)
293         {
294             Size size = obj as Size;
295             bool equal = false;
296             if (Width == size?.Width && Height == size?.Height && Depth == size?.Depth)
297             {
298                 equal = true;
299             }
300             return equal;
301         }
302
303         /// <summary>
304         /// Gets the the hash code of this Size.
305         /// </summary>
306         /// <returns>The Hash Code.</returns>
307         /// <since_tizen> 6 </since_tizen>
308         public override int GetHashCode()
309         {
310             return swigCPtr.Handle.GetHashCode();
311         }
312
313         /// <summary>
314         /// Checks equality.<br />
315         /// Utilizes appropriate machine epsilon values.<br />
316         /// </summary>
317         /// <param name="rhs">The size to test against.</param>
318         /// <returns>True if the sizes are equal.</returns>
319         /// <since_tizen> 5 </since_tizen>
320         public bool EqualTo(Size rhs)
321         {
322             bool ret = Interop.Vector3.Vector3_EqualTo(swigCPtr, Size.getCPtr(rhs));
323             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
324             return ret;
325         }
326
327         /// <summary>
328         /// Checks inequality.<br />
329         /// Utilizes appropriate machine epsilon values.<br />
330         /// </summary>
331         /// <param name="rhs">The size to test against.</param>
332         /// <returns>True if the sizes are not equal.</returns>
333         /// <since_tizen> 5 </since_tizen>
334         public bool NotEqualTo(Size rhs)
335         {
336             bool ret = Interop.Vector3.Vector3_NotEqualTo(swigCPtr, Size.getCPtr(rhs));
337             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
338             return ret;
339         }
340
341
342
343         /// <summary>
344         /// The type cast operator, Size to Vector3.
345         /// </summary>
346         /// <param name="size">The object of size type.</param>
347         /// <since_tizen> 5 </since_tizen>
348         public static implicit operator Vector3(Size size)
349         {
350             return new Vector3(size.Width, size.Height, size.Depth);
351         }
352
353         /// <summary>
354         /// The type cast operator, Vector3 to Size type.
355         /// </summary>
356         /// <param name="vec">The object of Vector3 type.</param>
357         /// <since_tizen> 5 </since_tizen>
358         public static implicit operator Size(Vector3 vec)
359         {
360             return new Size(vec.Width, vec.Height, vec.Depth);
361         }
362
363         internal static Size GetSizeFromPtr(global::System.IntPtr cPtr)
364         {
365             Size ret = new Size(cPtr, false);
366             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
367             return ret;
368         }
369
370         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Size obj)
371         {
372             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
373         }
374
375         internal Size(global::System.IntPtr cPtr, bool cMemoryOwn)
376         {
377             swigCMemOwn = cMemoryOwn;
378             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
379         }
380
381         /// <summary>
382         /// Dispose.
383         /// </summary>
384         /// <since_tizen> 5 </since_tizen>
385         protected virtual void Dispose(DisposeTypes type)
386         {
387             if (disposed)
388             {
389                 return;
390             }
391
392             if (type == DisposeTypes.Explicit)
393             {
394                 //Called by User
395                 //Release your own managed resources here.
396                 //You should release all of your own disposable objects here.
397
398             }
399
400             //Release your own unmanaged resources here.
401             //You should not access any managed member here except static instance.
402             //because the execution order of Finalizes is non-deterministic.
403
404             if (swigCPtr.Handle != global::System.IntPtr.Zero)
405             {
406                 if (swigCMemOwn)
407                 {
408                     swigCMemOwn = false;
409                     Interop.Vector3.delete_Vector3(swigCPtr);
410                 }
411                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
412             }
413
414             disposed = true;
415         }
416
417         private Size Add(Size rhs)
418         {
419             Size ret = new Size(Interop.Vector3.Vector3_Add(swigCPtr, Size.getCPtr(rhs)), true);
420             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
421             return ret;
422         }
423
424         private Size Subtract(Size rhs)
425         {
426             Size ret = new Size(Interop.Vector3.Vector3_Subtract__SWIG_0(swigCPtr, Size.getCPtr(rhs)), true);
427             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
428             return ret;
429         }
430
431         private Size Multiply(Size rhs)
432         {
433             Size ret = new Size(Interop.Vector3.Vector3_Multiply__SWIG_0(swigCPtr, Size.getCPtr(rhs)), true);
434             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
435             return ret;
436         }
437
438         private Size Multiply(float rhs)
439         {
440             Size ret = new Size(Interop.Vector3.Vector3_Multiply__SWIG_1(swigCPtr, rhs), true);
441             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
442             return ret;
443         }
444
445         private Size Divide(Size rhs)
446         {
447             Size ret = new Size(Interop.Vector3.Vector3_Divide__SWIG_0(swigCPtr, Size.getCPtr(rhs)), true);
448             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
449             return ret;
450         }
451
452         private Size Divide(float rhs)
453         {
454             Size ret = new Size(Interop.Vector3.Vector3_Divide__SWIG_1(swigCPtr, rhs), true);
455             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
456             return ret;
457         }
458
459         private Size Subtract()
460         {
461             Size ret = new Size(Interop.Vector3.Vector3_Subtract__SWIG_1(swigCPtr), true);
462             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
463             return ret;
464         }
465
466         private float ValueOfIndex(uint index)
467         {
468             float ret = Interop.Vector3.Vector3_ValueOfIndex__SWIG_0(swigCPtr, index);
469             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
470             return ret;
471         }
472
473         internal delegate void SizeChangedCallback(float width, float height, float depth);
474
475         internal Size(SizeChangedCallback cb, float w, float h, float d) : this(Interop.Vector3.new_Vector3__SWIG_1(w, h, d), true)
476         {
477             callback = cb;
478             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
479         }
480
481         private SizeChangedCallback callback = null;
482     }
483 }
484