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