[NUI] Fix Dropdown runtime error (#1232)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Vector2.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 using System.ComponentModel;
18 using Tizen.NUI.Binding;
19
20 namespace Tizen.NUI
21 {
22
23     /// <summary>
24     /// A two-dimensional vector.
25     /// </summary>
26     /// <since_tizen> 3 </since_tizen>
27     [Binding.TypeConverter(typeof(Vector2TypeConverter))]
28     public class Vector2 : Disposable
29     {
30
31         /// <summary>
32         /// The default constructor initializes the vector to 0.
33         /// </summary>
34         /// <since_tizen> 3 </since_tizen>
35         public Vector2() : this(Interop.Vector2.new_Vector2__SWIG_0(), true)
36         {
37             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
38         }
39
40         /// <summary>
41         /// The constructor.
42         /// </summary>
43         /// <param name="x">The x or width component.</param>
44         /// <param name="y">The y or height component.</param>
45         /// <since_tizen> 3 </since_tizen>
46         public Vector2(float x, float y) : this(Interop.Vector2.new_Vector2__SWIG_1(x, y), true)
47         {
48             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
49         }
50
51         /// <summary>
52         /// The conversion constructor from an array of two floats.
53         /// </summary>
54         /// <param name="array">The array of xy.</param>
55         /// <since_tizen> 3 </since_tizen>
56         public Vector2(float[] array) : this(Interop.Vector2.new_Vector2__SWIG_2(array), true)
57         {
58             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
59         }
60
61         /// <summary>
62         /// The constructor.
63         /// </summary>
64         /// <param name="vec3">Vector3 to create this vector from.</param>
65         /// <since_tizen> 3 </since_tizen>
66         public Vector2(Vector3 vec3) : this(Interop.Vector2.new_Vector2__SWIG_3(Vector3.getCPtr(vec3)), true)
67         {
68             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
69         }
70
71         /// <summary>
72         /// The constructor.
73         /// </summary>
74         /// <param name="vec4">Vector4 to create this vector from.</param>
75         /// <since_tizen> 3 </since_tizen>
76         public Vector2(Vector4 vec4) : this(Interop.Vector2.new_Vector2__SWIG_4(Vector4.getCPtr(vec4)), true)
77         {
78             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
79         }
80
81         internal Vector2(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
82         {
83         }
84
85         internal Vector2(Vector2ChangedCallback cb, float x, float y) : this(Interop.Vector2.new_Vector2__SWIG_1(x, y), true)
86         {
87             callback = cb;
88             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
89         }
90         internal delegate void Vector2ChangedCallback(float x, float y);
91         private Vector2ChangedCallback callback = null;
92
93         /// <summary>
94         /// (1.0f,1.0f).
95         /// </summary>
96         /// <since_tizen> 3 </since_tizen>
97         public static Vector2 One
98         {
99             get
100             {
101                 global::System.IntPtr cPtr = Interop.Vector2.Vector2_ONE_get();
102                 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
103                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
104                 return ret;
105             }
106         }
107
108         /// <summary>
109         /// The vector representing the x-axis.
110         /// </summary>
111         /// <since_tizen> 3 </since_tizen>
112         public static Vector2 XAxis
113         {
114             get
115             {
116                 global::System.IntPtr cPtr = Interop.Vector2.Vector2_XAXIS_get();
117                 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
118                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
119                 return ret;
120             }
121         }
122
123         /// <summary>
124         /// The vector representing the y-axis.
125         /// </summary>
126         /// <since_tizen> 3 </since_tizen>
127         public static Vector2 YAxis
128         {
129             get
130             {
131                 global::System.IntPtr cPtr = Interop.Vector2.Vector2_YAXIS_get();
132                 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
133                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
134                 return ret;
135             }
136         }
137
138         /// <summary>
139         /// The vector representing the negative x-axis.
140         /// </summary>
141         /// <since_tizen> 3 </since_tizen>
142         public static Vector2 NegativeXAxis
143         {
144             get
145             {
146                 global::System.IntPtr cPtr = Interop.Vector2.Vector2_NEGATIVE_XAXIS_get();
147                 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
148                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
149                 return ret;
150             }
151         }
152
153         /// <summary>
154         /// The vector representing the negative y-axis.
155         /// </summary>
156         /// <since_tizen> 3 </since_tizen>
157         public static Vector2 NegativeYAxis
158         {
159             get
160             {
161                 global::System.IntPtr cPtr = Interop.Vector2.Vector2_NEGATIVE_YAXIS_get();
162                 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
163                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
164                 return ret;
165             }
166         }
167
168         /// <summary>
169         /// (0.0f, 0.0f).
170         /// </summary>
171         /// <since_tizen> 3 </since_tizen>
172         public static Vector2 Zero
173         {
174             get
175             {
176                 global::System.IntPtr cPtr = Interop.Vector2.Vector2_ZERO_get();
177                 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
178                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
179                 return ret;
180             }
181         }
182
183         /// <summary>
184         /// The x component.
185         /// </summary>
186         /// <since_tizen> 3 </since_tizen>
187         public float X
188         {
189             set
190             {
191                 Interop.Vector2.Vector2_X_set(swigCPtr, value);
192                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
193
194                 callback?.Invoke(X, Y);
195             }
196             get
197             {
198                 float ret = Interop.Vector2.Vector2_X_get(swigCPtr);
199                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
200                 return ret;
201             }
202         }
203
204         /// <summary>
205         /// The width.
206         /// </summary>
207         /// <since_tizen> 3 </since_tizen>
208         public float Width
209         {
210             set
211             {
212                 Interop.Vector2.Vector2_Width_set(swigCPtr, value);
213                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
214
215                 callback?.Invoke(X, Y);
216             }
217             get
218             {
219                 float ret = Interop.Vector2.Vector2_Width_get(swigCPtr);
220                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
221                 return ret;
222             }
223         }
224
225         /// <summary>
226         /// The y component.
227         /// </summary>
228         /// <since_tizen> 3 </since_tizen>
229         public float Y
230         {
231             set
232             {
233                 Interop.Vector2.Vector2_Y_set(swigCPtr, value);
234                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
235
236                 callback?.Invoke(X, Y);
237             }
238             get
239             {
240                 float ret = Interop.Vector2.Vector2_Y_get(swigCPtr);
241                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
242                 return ret;
243             }
244         }
245
246         /// <summary>
247         /// The height.
248         /// </summary>
249         /// <since_tizen> 3 </since_tizen>
250         public float Height
251         {
252             set
253             {
254                 Interop.Vector2.Vector2_Height_set(swigCPtr, value);
255                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
256
257                 callback?.Invoke(X, Y);
258             }
259             get
260             {
261                 float ret = Interop.Vector2.Vector2_Height_get(swigCPtr);
262                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
263                 return ret;
264             }
265         }
266
267         /// <summary>
268         /// The array subscript operator overload.
269         /// </summary>
270         /// <param name="index">The subscript index.</param>
271         /// <returns>The float at the given index.</returns>
272         /// <since_tizen> 3 </since_tizen>
273         public float this[uint index]
274         {
275             get
276             {
277                 return ValueOfIndex(index);
278             }
279         }
280
281         /// <summary>
282         /// The addition operator.
283         /// </summary>
284         /// <param name="arg1">The first value.</param>
285         /// <param name="arg2">The second value.</param>
286         /// <returns>The vector containing the result of the addition.</returns>
287         /// <since_tizen> 3 </since_tizen>
288         public static Vector2 operator +(Vector2 arg1, Vector2 arg2)
289         {
290             return arg1.Add(arg2);
291         }
292
293         /// <summary>
294         /// The subtraction operator.
295         /// </summary>
296         /// <param name="arg1">The first value.</param>
297         /// <param name="arg2">The second value.</param>
298         /// <returns>The vector containing the result of the subtraction.</returns>
299         /// <since_tizen> 3 </since_tizen>
300         public static Vector2 operator -(Vector2 arg1, Vector2 arg2)
301         {
302             return arg1.Subtract(arg2);
303         }
304
305         /// <summary>
306         /// The unary negation operator.
307         /// </summary>
308         /// <param name="arg1">The target value.</param>
309         /// <returns>The vector containing the negation.</returns>
310         /// <since_tizen> 3 </since_tizen>
311         public static Vector2 operator -(Vector2 arg1)
312         {
313             return arg1.Subtract();
314         }
315
316         /// <summary>
317         /// The multiplication operator.
318         /// </summary>
319         /// <param name="arg1">The first value.</param>
320         /// <param name="arg2">The second value.</param>
321         /// <returns>The vector containing the result of the multiplication.</returns>
322         /// <since_tizen> 3 </since_tizen>
323         public static Vector2 operator *(Vector2 arg1, Vector2 arg2)
324         {
325             return arg1.Multiply(arg2);
326         }
327
328         /// <summary>
329         /// Th multiplication operator.
330         /// </summary>
331         /// <param name="arg1">The first value.</param>
332         /// <param name="arg2">The float value to scale the vector.</param>
333         /// <returns>The vector containing the result of the scaling.</returns>
334         /// <since_tizen> 3 </since_tizen>
335         public static Vector2 operator *(Vector2 arg1, float arg2)
336         {
337             return arg1.Multiply(arg2);
338         }
339
340         /// <summary>
341         /// The division operator.
342         /// </summary>
343         /// <param name="arg1">The first value.</param>
344         /// <param name="arg2">The second value.</param>
345         /// <returns>The vector containing the result of the division.</returns>
346         /// <since_tizen> 3 </since_tizen>
347         public static Vector2 operator /(Vector2 arg1, Vector2 arg2)
348         {
349             return arg1.Divide(arg2);
350         }
351
352         /// <summary>
353         /// Th division operator.
354         /// </summary>
355         /// <param name="arg1">The first value.</param>
356         /// <param name="arg2">The float value to scale the vector by.</param>
357         /// <returns>The vector containing the result of the scaling.</returns>
358         /// <since_tizen> 3 </since_tizen>
359         public static Vector2 operator /(Vector2 arg1, float arg2)
360         {
361             return arg1.Divide(arg2);
362         }
363
364         /// <summary>
365         /// Determines whether the specified object is equal to the current object.
366         /// </summary>
367         /// <param name="obj">The object to compare with the current object.</param>
368         /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
369         public override bool Equals(System.Object obj)
370         {
371             Vector2 vector2 = obj as Vector2;
372             bool equal = false;
373             if (X == vector2?.X && Y == vector2?.Y)
374             {
375                 equal = true;
376             }
377             return equal;
378         }
379
380         /// <summary>
381         /// Gets the the hash code of this Vector2.
382         /// </summary>
383         /// <returns>The Hash Code.</returns>
384         /// <since_tizen> 6 </since_tizen>
385         public override int GetHashCode()
386         {
387             return swigCPtr.Handle.GetHashCode();
388         }
389
390         /// <summary>
391         /// Returns the length of the vector.
392         /// </summary>
393         /// <returns>The length of the vector.</returns>
394         /// <since_tizen> 3 </since_tizen>
395         public float Length()
396         {
397             float ret = Interop.Vector2.Vector2_Length(swigCPtr);
398             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
399             return ret;
400         }
401
402         /// <summary>
403         /// Returns the length of the vector squared.<br />
404         /// This is more efficient than Length() for threshold
405         /// testing as it avoids the use of a square root.<br />
406         /// </summary>
407         /// <returns>The length of the vector squared</returns>
408         /// <since_tizen> 3 </since_tizen>
409         public float LengthSquared()
410         {
411             float ret = Interop.Vector2.Vector2_LengthSquared(swigCPtr);
412             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
413             return ret;
414         }
415
416         /// <summary>
417         /// Sets the vector to be the unit length, whilst maintaining its direction.
418         /// </summary>
419         /// <since_tizen> 3 </since_tizen>
420         public void Normalize()
421         {
422             Interop.Vector2.Vector2_Normalize(swigCPtr);
423             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
424         }
425
426         /// <summary>
427         /// Clamps the vector between minimum and maximum vectors.
428         /// </summary>
429         /// <param name="min">The minimum vector.</param>
430         /// <param name="max">The maximum vector.</param>
431         /// <since_tizen> 3 </since_tizen>
432         public void Clamp(Vector2 min, Vector2 max)
433         {
434             Interop.Vector2.Vector2_Clamp(swigCPtr, Vector2.getCPtr(min), Vector2.getCPtr(max));
435             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
436         }
437
438         internal static Vector2 GetVector2FromPtr(global::System.IntPtr cPtr)
439         {
440             Vector2 ret = new Vector2(cPtr, false);
441             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
442             return ret;
443         }
444
445         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Vector2 obj)
446         {
447             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
448         }
449
450         internal SWIGTYPE_p_float AsFloat()
451         {
452             global::System.IntPtr cPtr = Interop.Vector2.Vector2_AsFloat__SWIG_0(swigCPtr);
453             SWIGTYPE_p_float ret = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_float(cPtr, false);
454             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
455             return ret;
456         }
457
458         /// This will not be public opened.
459         [EditorBrowsable(EditorBrowsableState.Never)]
460         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
461         {
462             Interop.Vector2.delete_Vector2(swigCPtr);
463         }
464
465         private Vector2 Add(Vector2 rhs)
466         {
467             Vector2 ret = new Vector2(Interop.Vector2.Vector2_Add(swigCPtr, Vector2.getCPtr(rhs)), true);
468             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
469             return ret;
470         }
471
472         private Vector2 AddAssign(Vector2 rhs)
473         {
474             Vector2 ret = new Vector2(Interop.Vector2.Vector2_AddAssign(swigCPtr, Vector2.getCPtr(rhs)), false);
475             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
476             return ret;
477         }
478
479         private Vector2 Subtract(Vector2 rhs)
480         {
481             Vector2 ret = new Vector2(Interop.Vector2.Vector2_Subtract__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), true);
482             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
483             return ret;
484         }
485
486         private Vector2 SubtractAssign(Vector2 rhs)
487         {
488             Vector2 ret = new Vector2(Interop.Vector2.Vector2_SubtractAssign(swigCPtr, Vector2.getCPtr(rhs)), false);
489             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
490             return ret;
491         }
492
493         private Vector2 Multiply(Vector2 rhs)
494         {
495             Vector2 ret = new Vector2(Interop.Vector2.Vector2_Multiply__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), true);
496             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
497             return ret;
498         }
499
500         private Vector2 Multiply(float rhs)
501         {
502             Vector2 ret = new Vector2(Interop.Vector2.Vector2_Multiply__SWIG_1(swigCPtr, rhs), true);
503             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
504             return ret;
505         }
506
507         private Vector2 MultiplyAssign(Vector2 rhs)
508         {
509             Vector2 ret = new Vector2(Interop.Vector2.Vector2_MultiplyAssign__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), false);
510             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
511             return ret;
512         }
513
514         private Vector2 MultiplyAssign(float rhs)
515         {
516             Vector2 ret = new Vector2(Interop.Vector2.Vector2_MultiplyAssign__SWIG_1(swigCPtr, rhs), false);
517             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
518             return ret;
519         }
520
521         private Vector2 Divide(Vector2 rhs)
522         {
523             Vector2 ret = new Vector2(Interop.Vector2.Vector2_Divide__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), true);
524             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
525             return ret;
526         }
527
528         private Vector2 Divide(float rhs)
529         {
530             Vector2 ret = new Vector2(Interop.Vector2.Vector2_Divide__SWIG_1(swigCPtr, rhs), true);
531             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
532             return ret;
533         }
534
535         private Vector2 DivideAssign(Vector2 rhs)
536         {
537             Vector2 ret = new Vector2(Interop.Vector2.Vector2_DivideAssign__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), false);
538             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
539             return ret;
540         }
541
542         private Vector2 DivideAssign(float rhs)
543         {
544             Vector2 ret = new Vector2(Interop.Vector2.Vector2_DivideAssign__SWIG_1(swigCPtr, rhs), false);
545             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
546             return ret;
547         }
548
549         private Vector2 Subtract()
550         {
551             Vector2 ret = new Vector2(Interop.Vector2.Vector2_Subtract__SWIG_1(swigCPtr), true);
552             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
553             return ret;
554         }
555
556         private bool EqualTo(Vector2 rhs)
557         {
558             bool ret = Interop.Vector2.Vector2_EqualTo(swigCPtr, Vector2.getCPtr(rhs));
559             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
560             return ret;
561         }
562
563         private bool NotEqualTo(Vector2 rhs)
564         {
565             bool ret = Interop.Vector2.Vector2_NotEqualTo(swigCPtr, Vector2.getCPtr(rhs));
566             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
567             return ret;
568         }
569
570         private float ValueOfIndex(uint index)
571         {
572             float ret = Interop.Vector2.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
573             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
574             return ret;
575         }
576
577     }
578
579 }