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