Merge "[Information] Add comment for SystemInfo class"
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / RelativeVector2.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     /// RelativeVector2 is a two-dimensional vector.
24     /// Both values (x and y) should be between [0, 1].
25     /// </summary>
26     public class RelativeVector2 : 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 RelativeVector2(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(RelativeVector2 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         ~RelativeVector2()
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_Vector2(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 RelativeVector2 operator +(RelativeVector2 arg1, RelativeVector2 arg2)
133         {
134             RelativeVector2 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 RelativeVector2 operator -(RelativeVector2 arg1, RelativeVector2 arg2)
146         {
147             RelativeVector2 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 RelativeVector2 operator *(RelativeVector2 arg1, RelativeVector2 arg2)
159         {
160             RelativeVector2 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 RelativeVector2 operator *(RelativeVector2 arg1, float arg2)
172         {
173             RelativeVector2 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 RelativeVector2 operator /(RelativeVector2 arg1, RelativeVector2 arg2)
185         {
186             RelativeVector2 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 RelativeVector2 operator /(RelativeVector2 arg1, float arg2)
198         {
199             RelativeVector2 result = arg1.Divide(arg2);
200             return ValueCheck(result);
201         }
202
203
204         /// <summary>
205         /// The const array subscript operator overload. Should be 0, 1.
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 RelativeVector2 GetRelativeVector2FromPtr(global::System.IntPtr cPtr)
221         {
222             RelativeVector2 ret = new RelativeVector2(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 RelativeVector2() : this(NDalicPINVOKE.new_Vector2__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         /// <since_tizen> 3 </since_tizen>
243         public RelativeVector2(float x, float y) : this(NDalicPINVOKE.new_Vector2__SWIG_1(ValueCheck(x), ValueCheck(y)), true)
244         {
245             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
246         }
247
248         /// <summary>
249         /// The constructor.
250         /// </summary>
251         /// <param name="relativeVector3">The RelativeVector3 to create this vector from.</param>
252         /// <since_tizen> 3 </since_tizen>
253         public RelativeVector2(RelativeVector3 relativeVector3) : this(NDalicPINVOKE.new_Vector2__SWIG_3(RelativeVector3.getCPtr(relativeVector3)), true)
254         {
255             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
256         }
257
258         /// <summary>
259         /// The constructor.
260         /// </summary>
261         /// <param name="relativeVector4">The RelativeVector4 to create this vector from.</param>
262         /// <since_tizen> 3 </since_tizen>
263         public RelativeVector2(RelativeVector4 relativeVector4) : this(NDalicPINVOKE.new_Vector2__SWIG_4(RelativeVector4.getCPtr(relativeVector4)), true)
264         {
265             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
266         }
267
268
269         private RelativeVector2 Add(RelativeVector2 rhs)
270         {
271             RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Add(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
272             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
273             return ret;
274         }
275
276         private RelativeVector2 Subtract(RelativeVector2 rhs)
277         {
278             RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
279             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
280             return ret;
281         }
282
283         private RelativeVector2 Multiply(RelativeVector2 rhs)
284         {
285             RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
286             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
287             return ret;
288         }
289
290         private RelativeVector2 Multiply(float rhs)
291         {
292             RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, rhs), true);
293             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
294             return ret;
295         }
296
297         private RelativeVector2 Divide(RelativeVector2 rhs)
298         {
299             RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
300             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
301             return ret;
302         }
303
304         private RelativeVector2 Divide(float rhs)
305         {
306             RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, rhs), true);
307             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
308             return ret;
309         }
310
311         private float ValueOfIndex(uint index)
312         {
313             float ret = NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
314             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
315             return ret;
316         }
317
318         /// <summary>
319         /// Compares if the rhs is equal to.
320         /// </summary>
321         /// <param name="rhs">The vector to compare.</param>
322         /// <returns>Returns true if the two vectors are equal, otherwise false.</returns>
323         /// <since_tizen> 3 </since_tizen>
324         public bool EqualTo(RelativeVector2 rhs)
325         {
326             bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, RelativeVector2.getCPtr(rhs));
327             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
328             return ret;
329         }
330
331         /// <summary>
332         /// Compares if the rhs is not equal to.
333         /// </summary>
334         /// <param name="rhs">The vector to compare.</param>
335         /// <returns>Returns true if the two vectors are not equal, otherwise false.</returns>
336         /// <since_tizen> 3 </since_tizen>
337         public bool NotEqualTo(RelativeVector2 rhs)
338         {
339             bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, RelativeVector2.getCPtr(rhs));
340             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
341             return ret;
342         }
343
344
345         /// <summary>
346         /// The x component.
347         /// </summary>
348         /// <since_tizen> 3 </since_tizen>
349         public float X
350         {
351             set
352             {
353                 NDalicPINVOKE.Vector2_X_set(swigCPtr, ValueCheck(value));
354                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
355             }
356             get
357             {
358                 float ret = NDalicPINVOKE.Vector2_X_get(swigCPtr);
359                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
360                 return ret;
361             }
362         }
363
364         /// <summary>
365         /// The y component.
366         /// </summary>
367         /// <since_tizen> 3 </since_tizen>
368         public float Y
369         {
370             set
371             {
372                 NDalicPINVOKE.Vector2_Y_set(swigCPtr, ValueCheck(value));
373                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
374             }
375             get
376             {
377                 float ret = NDalicPINVOKE.Vector2_Y_get(swigCPtr);
378                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
379                 return ret;
380             }
381         }
382
383         /// <summary>
384         /// </summary>
385         /// <since_tizen> 3 </since_tizen>
386         public static implicit operator Vector2(RelativeVector2 relativeVector2)
387         {
388             return new Vector2(relativeVector2.X, relativeVector2.Y);
389         }
390
391         /// <summary>
392         /// </summary>
393         /// <since_tizen> 3 </since_tizen>
394         public static implicit operator RelativeVector2(Vector2 vec)
395         {
396             return new RelativeVector2(ValueCheck(vec.X), ValueCheck(vec.Y));
397         }
398
399         internal static RelativeVector2 ValueCheck(RelativeVector2 relativeVector2)
400         {
401             if(relativeVector2.X < 0.0f)
402             {
403                 relativeVector2.X = 0.0f;
404                 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
405             }
406             else if(relativeVector2.X > 1.0f)
407             {
408                 relativeVector2.X = 1.0f;
409                 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
410             }
411             if(relativeVector2.Y < 0.0f)
412             {
413                 relativeVector2.Y = 0.0f;
414                 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
415             }
416             else if(relativeVector2.Y > 1.0f)
417             {
418                 relativeVector2.Y = 1.0f;
419                 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
420             }
421             return relativeVector2;
422         }
423
424         internal static float ValueCheck(float value)
425         {
426             if(value < 0.0f)
427             {
428                 value = 0.0f;
429                 NUILog.Error( "The value of Parameters is invalid! Should be between [0, 1].");
430             }
431             else if(value > 1.0f)
432             {
433                 value = 1.0f;
434                 NUILog.Error( "The value of Parameters is invalid! Should be between [0, 1].");
435             }
436             return value;
437         }
438     }
439
440 }
441
442