d8180461cde4508859c27025c038410001fe0e01
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / RelativeVector4.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  using System;
18  using Tizen.NUI.Binding;
19
20 namespace Tizen.NUI
21 {
22     /// <summary>
23     /// RelativeVector4 is a four-dimensional vector.
24     /// All values (x, y, and z) should be between [0, 1].
25     /// </summary>
26     /// <since_tizen> 3 </since_tizen>
27     [TypeConverter(typeof(RelativeVector4TypeConverter))]
28     public class RelativeVector4 : global::System.IDisposable
29     {
30         /// <summary>
31         /// swigCMemOwn
32         /// </summary>
33         /// <since_tizen> 3 </since_tizen>
34         protected bool swigCMemOwn;
35
36         /// <summary>
37         /// A Flat to check if it is already disposed.
38         /// </summary>
39         /// <since_tizen> 3 </since_tizen>
40         protected bool disposed = false;
41
42         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
43
44         //A Flag to check who called Dispose(). (By User or DisposeQueue)
45         private bool isDisposeQueued = false;
46
47         /// <summary>
48         /// The constructor.
49         /// </summary>
50         /// <since_tizen> 3 </since_tizen>
51         public RelativeVector4() : this(NDalicPINVOKE.new_Vector4__SWIG_0(), true)
52         {
53             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
54         }
55
56         /// <summary>
57         /// The constructor.
58         /// </summary>
59         /// <param name="x">The x component.</param>
60         /// <param name="y">The y component.</param>
61         /// <param name="z">The z component.</param>
62         /// <param name="w">The w component.</param>
63         /// <since_tizen> 3 </since_tizen>
64         public RelativeVector4(float x, float y, float z, float w) : this(NDalicPINVOKE.new_Vector4__SWIG_1(ValueCheck(x), ValueCheck(y), ValueCheck(z), ValueCheck(w)), true)
65         {
66             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
67         }
68
69         /// <summary>
70         /// The constructor.
71         /// </summary>
72         /// <param name="relativeVector2">The RelativeVector2 to create this vector from.</param>
73         /// <since_tizen> 3 </since_tizen>
74         public RelativeVector4(RelativeVector2 relativeVector2) : this(NDalicPINVOKE.new_Vector4__SWIG_3(RelativeVector2.getCPtr(relativeVector2)), true)
75         {
76             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
77         }
78
79         /// <summary>
80         /// The constructor.
81         /// </summary>
82         /// <param name="relativeVector3">The RelativeVector3 to create this vector from.</param>
83         /// <since_tizen> 3 </since_tizen>
84         public RelativeVector4(RelativeVector3 relativeVector3) : this(NDalicPINVOKE.new_Vector4__SWIG_4(RelativeVector3.getCPtr(relativeVector3)), true)
85         {
86             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
87         }
88
89         /// <summary>
90         /// Dispose.
91         /// </summary>
92         /// <since_tizen> 3 </since_tizen>
93         ~RelativeVector4()
94         {
95             if(!isDisposeQueued)
96             {
97                 isDisposeQueued = true;
98                 DisposeQueue.Instance.Add(this);
99             }
100         }
101
102         /// <summary>
103         /// The x component.
104         /// </summary>
105         /// <since_tizen> 3 </since_tizen>
106         public float X
107         {
108             set
109             {
110                 NDalicPINVOKE.Vector4_X_set(swigCPtr, ValueCheck(value));
111                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
112             }
113             get
114             {
115                 float ret = NDalicPINVOKE.Vector4_X_get(swigCPtr);
116                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
117                 return ret;
118             }
119         }
120
121         /// <summary>
122         /// The y component.
123         /// </summary>
124         /// <since_tizen> 3 </since_tizen>
125         public float Y
126         {
127             set
128             {
129                 NDalicPINVOKE.Vector4_Y_set(swigCPtr, ValueCheck(value));
130                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
131             }
132             get
133             {
134                 float ret = NDalicPINVOKE.Vector4_Y_get(swigCPtr);
135                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
136                 return ret;
137             }
138         }
139
140         /// <summary>
141         /// The z component.
142         /// </summary>
143         /// <since_tizen> 3 </since_tizen>
144         public float Z
145         {
146             set
147             {
148                 NDalicPINVOKE.Vector4_Z_set(swigCPtr, ValueCheck(value));
149                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
150             }
151             get
152             {
153                 float ret = NDalicPINVOKE.Vector4_Z_get(swigCPtr);
154                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
155                 return ret;
156             }
157         }
158
159         /// <summary>
160         /// The w component.
161         /// </summary>
162         /// <since_tizen> 3 </since_tizen>
163         public float W
164         {
165             set
166             {
167                 NDalicPINVOKE.Vector4_W_set(swigCPtr, ValueCheck(value));
168                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
169             }
170             get
171             {
172                 float ret = NDalicPINVOKE.Vector4_W_get(swigCPtr);
173                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
174                 return ret;
175             }
176         }
177
178         /// <summary>
179         /// The addition operator.
180         /// </summary>
181         /// <param name="arg1">The vector to add.</param>
182         /// <param name="arg2">The vector to add.</param>
183         /// <returns>The vector containing the result of the addition.</returns>
184         /// <since_tizen> 3 </since_tizen>
185         public static RelativeVector4 operator +(RelativeVector4 arg1, RelativeVector4 arg2)
186         {
187             RelativeVector4 result = arg1.Add(arg2);
188             return ValueCheck(result);
189         }
190
191         /// <summary>
192         /// The subtraction operator.
193         /// </summary>
194         /// <param name="arg1">The vector to subtract.</param>
195         /// <param name="arg2">The vector to subtract.</param>
196         /// <returns>The vector containing the result of the subtraction.</returns>
197         /// <since_tizen> 3 </since_tizen>
198         public static RelativeVector4 operator -(RelativeVector4 arg1, RelativeVector4 arg2)
199         {
200             RelativeVector4 result = arg1.Subtract(arg2);
201             return ValueCheck(result);
202         }
203
204         /// <summary>
205         /// The multiplication operator.
206         /// </summary>
207         /// <param name="arg1">The vector to multiply.</param>
208         /// <param name="arg2">The vector to multiply.</param>
209         /// <returns>The vector containing the result of the multiplication.</returns>
210         /// <since_tizen> 3 </since_tizen>
211         public static RelativeVector4 operator *(RelativeVector4 arg1, RelativeVector4 arg2)
212         {
213             RelativeVector4 result = arg1.Multiply(arg2);
214             return ValueCheck(result);
215         }
216
217         /// <summary>
218         /// The multiplication operator.
219         /// </summary>
220         /// <param name="arg1">The vector to multiply.</param>
221         /// <param name="arg2">The float value to scale the vector.</param>
222         /// <returns>The vector containing the result of the scaling.</returns>
223         /// <since_tizen> 3 </since_tizen>
224         public static RelativeVector4 operator *(RelativeVector4 arg1, float arg2)
225         {
226             RelativeVector4 result = arg1.Multiply(arg2);
227             return ValueCheck(result);
228         }
229
230         /// <summary>
231         /// The division operator.
232         /// </summary>
233         /// <param name="arg1">The vector to divide.</param>
234         /// <param name="arg2">The vector to divide.</param>
235         /// <returns>The vector containing the result of the division.</returns>
236         /// <since_tizen> 3 </since_tizen>
237         public static RelativeVector4 operator /(RelativeVector4 arg1, RelativeVector4 arg2)
238         {
239             RelativeVector4 result = arg1.Divide(arg2);
240             return ValueCheck(result);
241         }
242
243         /// <summary>
244         /// The division operator.
245         /// </summary>
246         /// <param name="arg1">The vector to divide.</param>
247         /// <param name="arg2">The float value to scale the vector by.</param>
248         /// <returns>The vector containing the result of the scaling.</returns>
249         /// <since_tizen> 3 </since_tizen>
250         public static RelativeVector4 operator /(RelativeVector4 arg1, float arg2)
251         {
252             RelativeVector4 result = arg1.Divide(arg2);
253             return ValueCheck(result);
254         }
255
256         /// <summary>
257         /// </summary>
258         /// <since_tizen> 3 </since_tizen>
259         public static implicit operator Vector4(RelativeVector4 relativeVector4)
260         {
261             return new Vector4(relativeVector4.X, relativeVector4.Y, relativeVector4.Z, relativeVector4.W);
262         }
263
264         /// <summary>
265         /// </summary>
266         /// <since_tizen> 3 </since_tizen>
267         public static implicit operator RelativeVector4(Vector4 vec)
268         {
269             return new RelativeVector4(ValueCheck(vec.X), ValueCheck(vec.Y), ValueCheck(vec.Z), ValueCheck(vec.W));
270         }
271
272         /// <summary>
273         /// Dispose.
274         /// </summary>
275         /// <since_tizen> 3 </since_tizen>
276         public void Dispose()
277         {
278             //Throw excpetion if Dispose() is called in separate thread.
279             if (!Window.IsInstalled())
280             {
281                 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
282             }
283
284             if (isDisposeQueued)
285             {
286                 Dispose(DisposeTypes.Implicit);
287             }
288             else
289             {
290                 Dispose(DisposeTypes.Explicit);
291                 System.GC.SuppressFinalize(this);
292             }
293         }
294
295         /// <summary>
296         /// The const array subscript operator overload. Should be 0, 1 3 or 3.
297         /// </summary>
298         /// <param name="index">The subscript index.</param>
299         /// <returns>The float at the given index.</returns>
300         /// <since_tizen> 3 </since_tizen>
301         public float this[uint index]
302         {
303             get
304             {
305                 return ValueOfIndex(index);
306             }
307         }
308
309         /// <summary>
310         /// Determines whether the specified object is equal to the current object.
311         /// </summary>
312         /// <param name="obj">The object to compare with the current object.</param>
313         /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
314         public override bool Equals(System.Object obj)
315         {
316             RelativeVector4 relativeVector4 = obj as RelativeVector4;
317             bool equal = false;
318             if (X == relativeVector4?.X && Y == relativeVector4?.Y && Z == relativeVector4?.Z && W == relativeVector4?.W)
319             {
320                 equal = true;
321             }
322             return equal;
323         }
324
325         /// <summary>
326         /// Gets the the hash code of this RelativeVector4.
327         /// </summary>
328         /// <returns>The Hash Code.</returns>
329         /// <since_tizen> 6 </since_tizen>
330         public override int GetHashCode()
331         {
332             return swigCPtr.Handle.GetHashCode();
333         }
334
335         /// <summary>
336         /// Compares if the rhs is equal to.
337         /// </summary>
338         /// <param name="rhs">The vector to compare.</param>
339         /// <returns>Returns true if the two vectors are equal, otherwise false.</returns>
340         /// <since_tizen> 3 </since_tizen>
341         public bool EqualTo(RelativeVector4 rhs)
342         {
343             bool ret = NDalicPINVOKE.Vector4_EqualTo(swigCPtr, RelativeVector4.getCPtr(rhs));
344             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
345             return ret;
346         }
347
348         /// <summary>
349         /// Compares if the rhs is not equal to.
350         /// </summary>
351         /// <param name="rhs">The vector to compare.</param>
352         /// <returns>Returns true if the two vectors are not equal, otherwise false.</returns>
353         /// <since_tizen> 3 </since_tizen>
354         public bool NotEqualTo(RelativeVector4 rhs)
355         {
356             bool ret = NDalicPINVOKE.Vector4_NotEqualTo(swigCPtr, RelativeVector4.getCPtr(rhs));
357             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
358             return ret;
359         }
360
361         /// <summary>
362         /// </summary>
363         internal static RelativeVector4 GetRelativeVector4FromPtr(global::System.IntPtr cPtr)
364         {
365             RelativeVector4 ret = new RelativeVector4(cPtr, false);
366             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
367             return ret;
368         }
369
370         internal static RelativeVector4 ValueCheck(RelativeVector4 relativeVector4)
371         {
372             if (relativeVector4.X < 0.0f)
373             {
374                 relativeVector4.X = 0.0f;
375                 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
376             }
377             else if (relativeVector4.X > 1.0f)
378             {
379                 relativeVector4.X = 1.0f;
380                 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
381             }
382             if (relativeVector4.Y < 0.0f)
383             {
384                 relativeVector4.Y = 0.0f;
385                 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
386             }
387             else if (relativeVector4.Y > 1.0f)
388             {
389                 relativeVector4.Y = 1.0f;
390                 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
391             }
392             if (relativeVector4.Z < 0.0f)
393             {
394                 relativeVector4.Z = 0.0f;
395                 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
396             }
397             else if (relativeVector4.Z > 1.0f)
398             {
399                 relativeVector4.Z = 1.0f;
400                 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
401             }
402             if (relativeVector4.W < 0.0f)
403             {
404                 relativeVector4.W = 0.0f;
405                 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
406             }
407             else if (relativeVector4.W > 1.0f)
408             {
409                 relativeVector4.W = 1.0f;
410                 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
411             }
412             return relativeVector4;
413         }
414
415         internal static float ValueCheck(float value)
416         {
417             if (value < 0.0f)
418             {
419                 value = 0.0f;
420                 NUILog.Error("The value of Parameters is invalid! Should be between [0, 1].");
421             }
422             else if (value > 1.0f)
423             {
424                 value = 1.0f;
425                 NUILog.Error("The value of Parameters is invalid! Should be between [0, 1].");
426             }
427             return value;
428         }
429
430         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(RelativeVector4 obj)
431         {
432             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
433         }
434
435         internal RelativeVector4(global::System.IntPtr cPtr, bool cMemoryOwn)
436         {
437             swigCMemOwn = cMemoryOwn;
438             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
439         }
440
441         /// <summary>
442         /// Dispose.
443         /// </summary>
444         /// <since_tizen> 3 </since_tizen>
445         protected virtual void Dispose(DisposeTypes type)
446         {
447             if (disposed)
448             {
449                 return;
450             }
451
452             if(type == DisposeTypes.Explicit)
453             {
454                 //Called by User
455                 //Release your own managed resources here.
456                 //You should release all of your own disposable objects here.
457             }
458
459             //Release your own unmanaged resources here.
460             //You should not access any managed member here except static instance.
461             //because the execution order of Finalizes is non-deterministic.
462
463             if (swigCPtr.Handle != global::System.IntPtr.Zero)
464             {
465                 if (swigCMemOwn)
466                 {
467                     swigCMemOwn = false;
468                     NDalicPINVOKE.delete_Vector4(swigCPtr);
469                 }
470                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
471             }
472             disposed = true;
473         }
474
475         private RelativeVector4 Add(RelativeVector4 rhs)
476         {
477             RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Add(swigCPtr, RelativeVector4.getCPtr(rhs)), true);
478             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
479             return ret;
480         }
481
482         private RelativeVector4 Subtract(RelativeVector4 rhs)
483         {
484             RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Subtract__SWIG_0(swigCPtr, RelativeVector4.getCPtr(rhs)), true);
485             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
486             return ret;
487         }
488
489         private RelativeVector4 Multiply(RelativeVector4 rhs)
490         {
491             RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Multiply__SWIG_0(swigCPtr, RelativeVector4.getCPtr(rhs)), true);
492             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
493             return ret;
494         }
495
496         private RelativeVector4 Multiply(float rhs)
497         {
498             RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Multiply__SWIG_1(swigCPtr, rhs), true);
499             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
500             return ret;
501         }
502
503         private RelativeVector4 Divide(RelativeVector4 rhs)
504         {
505             RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Divide__SWIG_0(swigCPtr, RelativeVector4.getCPtr(rhs)), true);
506             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
507             return ret;
508         }
509
510         private RelativeVector4 Divide(float rhs)
511         {
512             RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Divide__SWIG_1(swigCPtr, rhs), true);
513             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
514             return ret;
515         }
516
517         private float ValueOfIndex(uint index)
518         {
519             float ret = NDalicPINVOKE.Vector4_ValueOfIndex__SWIG_0(swigCPtr, index);
520             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
521             return ret;
522         }
523     }
524 }
525
526