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