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