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