[NUI] nui 60 version integration
[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             return ValueCheck(result);
136         }
137
138         /// <summary>
139         /// The subtraction operator.
140         /// </summary>
141         /// <param name="arg1">The vector to subtract.</param>
142         /// <param name="arg2">The vector to subtract.</param>
143         /// <returns>The vector containing the result of the subtraction.</returns>
144         /// <since_tizen> 3 </since_tizen>
145         public static RelativeVector4 operator -(RelativeVector4 arg1, RelativeVector4 arg2)
146         {
147             RelativeVector4 result = arg1.Subtract(arg2);
148             return ValueCheck(result);
149         }
150
151         /// <summary>
152         /// The multiplication operator.
153         /// </summary>
154         /// <param name="arg1">The vector to multiply.</param>
155         /// <param name="arg2">The vector to multiply.</param>
156         /// <returns>The vector containing the result of the multiplication.</returns>
157         /// <since_tizen> 3 </since_tizen>
158         public static RelativeVector4 operator *(RelativeVector4 arg1, RelativeVector4 arg2)
159         {
160             RelativeVector4 result = arg1.Multiply(arg2);
161             return ValueCheck(result);
162         }
163
164         /// <summary>
165         /// The multiplication operator.
166         /// </summary>
167         /// <param name="arg1">The vector to multiply.</param>
168         /// <param name="arg2">The float value to scale the vector.</param>
169         /// <returns>The vector containing the result of the scaling.</returns>
170         /// <since_tizen> 3 </since_tizen>
171         public static RelativeVector4 operator *(RelativeVector4 arg1, float arg2)
172         {
173             RelativeVector4 result = arg1.Multiply(arg2);
174             return ValueCheck(result);
175         }
176
177         /// <summary>
178         /// The division operator.
179         /// </summary>
180         /// <param name="arg1">The vector to divide.</param>
181         /// <param name="arg2">The vector to divide.</param>
182         /// <returns>The vector containing the result of the division.</returns>
183         /// <since_tizen> 3 </since_tizen>
184         public static RelativeVector4 operator /(RelativeVector4 arg1, RelativeVector4 arg2)
185         {
186             RelativeVector4 result = arg1.Divide(arg2);
187             return ValueCheck(result);
188         }
189
190         /// <summary>
191         /// The division operator.
192         /// </summary>
193         /// <param name="arg1">The vector to divide.</param>
194         /// <param name="arg2">The float value to scale the vector by.</param>
195         /// <returns>The vector containing the result of the scaling.</returns>
196         /// <since_tizen> 3 </since_tizen>
197         public static RelativeVector4 operator /(RelativeVector4 arg1, float arg2)
198         {
199             RelativeVector4 result = arg1.Divide(arg2);
200             return ValueCheck(result);
201         }
202
203
204         /// <summary>
205         /// The const array subscript operator overload. Should be 0, 1 3 or 3.
206         /// </summary>
207         /// <param name="index">The subscript index.</param>
208         /// <returns>The float at the given index.</returns>
209         /// <since_tizen> 3 </since_tizen>
210         public float this[uint index]
211         {
212             get
213             {
214                 return ValueOfIndex(index);
215             }
216         }
217
218         /// <summary>
219         /// </summary>
220         internal static RelativeVector4 GetRelativeVector4FromPtr(global::System.IntPtr cPtr)
221         {
222             RelativeVector4 ret = new RelativeVector4(cPtr, false);
223             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
224             return ret;
225         }
226
227
228         /// <summary>
229         /// The constructor.
230         /// </summary>
231         /// <since_tizen> 3 </since_tizen>
232         public RelativeVector4() : this(NDalicPINVOKE.new_Vector4__SWIG_0(), true)
233         {
234             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
235         }
236
237         /// <summary>
238         /// The constructor.
239         /// </summary>
240         /// <param name="x">The x component.</param>
241         /// <param name="y">The y component.</param>
242         /// <param name="z">The z component.</param>
243         /// <param name="w">The w component.</param>
244         /// <since_tizen> 3 </since_tizen>
245         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)
246         {
247             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
248         }
249
250         /// <summary>
251         /// The constructor.
252         /// </summary>
253         /// <param name="relativeVector2">The RelativeVector2 to create this vector from.</param>
254         /// <since_tizen> 3 </since_tizen>
255         public RelativeVector4(RelativeVector2 relativeVector2) : this(NDalicPINVOKE.new_Vector4__SWIG_3(RelativeVector2.getCPtr(relativeVector2)), true)
256         {
257             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
258         }
259
260         /// <summary>
261         /// The constructor.
262         /// </summary>
263         /// <param name="relativeVector3">The RelativeVector3 to create this vector from.</param>
264         /// <since_tizen> 3 </since_tizen>
265         public RelativeVector4(RelativeVector3 relativeVector3) : this(NDalicPINVOKE.new_Vector4__SWIG_4(RelativeVector3.getCPtr(relativeVector3)), true)
266         {
267             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
268         }
269
270         private RelativeVector4 Add(RelativeVector4 rhs)
271         {
272             RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Add(swigCPtr, RelativeVector4.getCPtr(rhs)), true);
273             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
274             return ret;
275         }
276
277         private RelativeVector4 Subtract(RelativeVector4 rhs)
278         {
279             RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Subtract__SWIG_0(swigCPtr, RelativeVector4.getCPtr(rhs)), true);
280             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
281             return ret;
282         }
283
284         private RelativeVector4 Multiply(RelativeVector4 rhs)
285         {
286             RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Multiply__SWIG_0(swigCPtr, RelativeVector4.getCPtr(rhs)), true);
287             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
288             return ret;
289         }
290
291         private RelativeVector4 Multiply(float rhs)
292         {
293             RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Multiply__SWIG_1(swigCPtr, rhs), true);
294             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
295             return ret;
296         }
297
298         private RelativeVector4 Divide(RelativeVector4 rhs)
299         {
300             RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Divide__SWIG_0(swigCPtr, RelativeVector4.getCPtr(rhs)), true);
301             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
302             return ret;
303         }
304
305         private RelativeVector4 Divide(float rhs)
306         {
307             RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Divide__SWIG_1(swigCPtr, rhs), true);
308             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
309             return ret;
310         }
311
312         private float ValueOfIndex(uint index)
313         {
314             float ret = NDalicPINVOKE.Vector4_ValueOfIndex__SWIG_0(swigCPtr, index);
315             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
316             return ret;
317         }
318
319         /// <summary>
320         /// Compares if the rhs is equal to.
321         /// </summary>
322         /// <param name="rhs">The vector to compare.</param>
323         /// <returns>Returns true if the two vectors are equal, otherwise false.</returns>
324         /// <since_tizen> 3 </since_tizen>
325         public bool EqualTo(RelativeVector4 rhs)
326         {
327             bool ret = NDalicPINVOKE.Vector4_EqualTo(swigCPtr, RelativeVector4.getCPtr(rhs));
328             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
329             return ret;
330         }
331
332         /// <summary>
333         /// Compares if the rhs is not equal to.
334         /// </summary>
335         /// <param name="rhs">The vector to compare.</param>
336         /// <returns>Returns true if the two vectors are not equal, otherwise false.</returns>
337         /// <since_tizen> 3 </since_tizen>
338         public bool NotEqualTo(RelativeVector4 rhs)
339         {
340             bool ret = NDalicPINVOKE.Vector4_NotEqualTo(swigCPtr, RelativeVector4.getCPtr(rhs));
341             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
342             return ret;
343         }
344
345
346         /// <summary>
347         /// The x component.
348         /// </summary>
349         /// <since_tizen> 3 </since_tizen>
350         public float X
351         {
352             set
353             {
354                 NDalicPINVOKE.Vector4_X_set(swigCPtr, ValueCheck(value));
355                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
356             }
357             get
358             {
359                 float ret = NDalicPINVOKE.Vector4_X_get(swigCPtr);
360                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
361                 return ret;
362             }
363         }
364
365         /// <summary>
366         /// The y component.
367         /// </summary>
368         /// <since_tizen> 3 </since_tizen>
369         public float Y
370         {
371             set
372             {
373                 NDalicPINVOKE.Vector4_Y_set(swigCPtr, ValueCheck(value));
374                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
375             }
376             get
377             {
378                 float ret = NDalicPINVOKE.Vector4_Y_get(swigCPtr);
379                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
380                 return ret;
381             }
382         }
383
384         /// <summary>
385         /// The z component.
386         /// </summary>
387         /// <since_tizen> 3 </since_tizen>
388         public float Z
389         {
390             set
391             {
392                 NDalicPINVOKE.Vector4_Z_set(swigCPtr, ValueCheck(value));
393                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
394             }
395             get
396             {
397                 float ret = NDalicPINVOKE.Vector4_Z_get(swigCPtr);
398                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
399                 return ret;
400             }
401         }
402
403         /// <summary>
404         /// The w component.
405         /// </summary>
406         /// <since_tizen> 3 </since_tizen>
407         public float W
408         {
409             set
410             {
411                 NDalicPINVOKE.Vector4_W_set(swigCPtr, ValueCheck(value));
412                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
413             }
414             get
415             {
416                 float ret = NDalicPINVOKE.Vector4_W_get(swigCPtr);
417                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
418                 return ret;
419             }
420         }
421
422         /// <summary>
423         /// </summary>
424         /// <since_tizen> 3 </since_tizen>
425         public static implicit operator Vector4(RelativeVector4 relativeVector4)
426         {
427             return new Vector4(relativeVector4.X, relativeVector4.Y, relativeVector4.Z, relativeVector4.W);
428         }
429
430         /// <summary>
431         /// </summary>
432         /// <since_tizen> 3 </since_tizen>
433         public static implicit operator RelativeVector4(Vector4 vec)
434         {
435             return new RelativeVector4(ValueCheck(vec.X), ValueCheck(vec.Y), ValueCheck(vec.Z), ValueCheck(vec.W));
436         }
437
438         internal static RelativeVector4 ValueCheck(RelativeVector4 relativeVector4)
439         {
440             if(relativeVector4.X < 0.0f)
441             {
442                 relativeVector4.X = 0.0f;
443                 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
444             }
445             else if(relativeVector4.X > 1.0f)
446             {
447                 relativeVector4.X = 1.0f;
448                 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
449             }
450             if(relativeVector4.Y < 0.0f)
451             {
452                 relativeVector4.Y = 0.0f;
453                 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
454             }
455             else if(relativeVector4.Y > 1.0f)
456             {
457                 relativeVector4.Y = 1.0f;
458                 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
459             }
460             if(relativeVector4.Z < 0.0f)
461             {
462                 relativeVector4.Z = 0.0f;
463                 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
464             }
465             else if(relativeVector4.Z > 1.0f)
466             {
467                 relativeVector4.Z = 1.0f;
468                 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
469             }
470             if(relativeVector4.W < 0.0f)
471             {
472                 relativeVector4.W = 0.0f;
473                 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
474             }
475             else if(relativeVector4.W > 1.0f)
476             {
477                 relativeVector4.W = 1.0f;
478                 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
479             }
480             return relativeVector4;
481         }
482
483         internal static float ValueCheck(float value)
484         {
485             if(value < 0.0f)
486             {
487                 value = 0.0f;
488                 NUILog.Error( "The value of Parameters is invalid! Should be between [0, 1].");
489             }
490             else if(value > 1.0f)
491             {
492                 value = 1.0f;
493                 NUILog.Error( "The value of Parameters is invalid! Should be between [0, 1].");
494             }
495             return value;
496         }
497
498     }
499 }
500
501