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