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