[NUI] Setting since_tizen 3/4 on Tizen.NUI API
[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     /// <since_tizen> 3 </since_tizen>
27     public class RelativeVector2 : 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 RelativeVector2(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(RelativeVector2 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         ~RelativeVector2()
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_Vector2(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 RelativeVector2 operator +(RelativeVector2 arg1, RelativeVector2 arg2)
134         {
135             RelativeVector2 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 RelativeVector2 operator -(RelativeVector2 arg1, RelativeVector2 arg2)
147         {
148             RelativeVector2 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 RelativeVector2 operator *(RelativeVector2 arg1, RelativeVector2 arg2)
160         {
161             RelativeVector2 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 RelativeVector2 operator *(RelativeVector2 arg1, float arg2)
173         {
174             RelativeVector2 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 RelativeVector2 operator /(RelativeVector2 arg1, RelativeVector2 arg2)
186         {
187             RelativeVector2 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 RelativeVector2 operator /(RelativeVector2 arg1, float arg2)
199         {
200             RelativeVector2 result = arg1.Divide(arg2);
201             return ValueCheck(result);
202         }
203
204
205         /// <summary>
206         /// The const array subscript operator overload. Should be 0, 1.
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 RelativeVector2 GetRelativeVector2FromPtr(global::System.IntPtr cPtr)
222         {
223             RelativeVector2 ret = new RelativeVector2(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 RelativeVector2() : this(NDalicPINVOKE.new_Vector2__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         /// <since_tizen> 3 </since_tizen>
244         public RelativeVector2(float x, float y) : this(NDalicPINVOKE.new_Vector2__SWIG_1(ValueCheck(x), ValueCheck(y)), true)
245         {
246             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
247         }
248
249         /// <summary>
250         /// The constructor.
251         /// </summary>
252         /// <param name="relativeVector3">The RelativeVector3 to create this vector from.</param>
253         /// <since_tizen> 3 </since_tizen>
254         public RelativeVector2(RelativeVector3 relativeVector3) : this(NDalicPINVOKE.new_Vector2__SWIG_3(RelativeVector3.getCPtr(relativeVector3)), true)
255         {
256             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
257         }
258
259         /// <summary>
260         /// The constructor.
261         /// </summary>
262         /// <param name="relativeVector4">The RelativeVector4 to create this vector from.</param>
263         /// <since_tizen> 3 </since_tizen>
264         public RelativeVector2(RelativeVector4 relativeVector4) : this(NDalicPINVOKE.new_Vector2__SWIG_4(RelativeVector4.getCPtr(relativeVector4)), true)
265         {
266             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
267         }
268
269
270         private RelativeVector2 Add(RelativeVector2 rhs)
271         {
272             RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Add(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
273             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
274             return ret;
275         }
276
277         private RelativeVector2 Subtract(RelativeVector2 rhs)
278         {
279             RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
280             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
281             return ret;
282         }
283
284         private RelativeVector2 Multiply(RelativeVector2 rhs)
285         {
286             RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
287             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
288             return ret;
289         }
290
291         private RelativeVector2 Multiply(float rhs)
292         {
293             RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, rhs), true);
294             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
295             return ret;
296         }
297
298         private RelativeVector2 Divide(RelativeVector2 rhs)
299         {
300             RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
301             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
302             return ret;
303         }
304
305         private RelativeVector2 Divide(float rhs)
306         {
307             RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_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.Vector2_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(RelativeVector2 rhs)
326         {
327             bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, RelativeVector2.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(RelativeVector2 rhs)
339         {
340             bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, RelativeVector2.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.Vector2_X_set(swigCPtr, ValueCheck(value));
355                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
356             }
357             get
358             {
359                 float ret = NDalicPINVOKE.Vector2_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.Vector2_Y_set(swigCPtr, ValueCheck(value));
374                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
375             }
376             get
377             {
378                 float ret = NDalicPINVOKE.Vector2_Y_get(swigCPtr);
379                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
380                 return ret;
381             }
382         }
383
384         /// <summary>
385         /// </summary>
386         /// <since_tizen> 3 </since_tizen>
387         public static implicit operator Vector2(RelativeVector2 relativeVector2)
388         {
389             return new Vector2(relativeVector2.X, relativeVector2.Y);
390         }
391
392         /// <summary>
393         /// </summary>
394         /// <since_tizen> 3 </since_tizen>
395         public static implicit operator RelativeVector2(Vector2 vec)
396         {
397             return new RelativeVector2(ValueCheck(vec.X), ValueCheck(vec.Y));
398         }
399
400         internal static RelativeVector2 ValueCheck(RelativeVector2 relativeVector2)
401         {
402             if(relativeVector2.X < 0.0f)
403             {
404                 relativeVector2.X = 0.0f;
405                 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
406             }
407             else if(relativeVector2.X > 1.0f)
408             {
409                 relativeVector2.X = 1.0f;
410                 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
411             }
412             if(relativeVector2.Y < 0.0f)
413             {
414                 relativeVector2.Y = 0.0f;
415                 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
416             }
417             else if(relativeVector2.Y > 1.0f)
418             {
419                 relativeVector2.Y = 1.0f;
420                 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
421             }
422             return relativeVector2;
423         }
424
425         internal static float ValueCheck(float value)
426         {
427             if(value < 0.0f)
428             {
429                 value = 0.0f;
430                 NUILog.Error( "The value of Parameters is invalid! Should be between [0, 1].");
431             }
432             else if(value > 1.0f)
433             {
434                 value = 1.0f;
435                 NUILog.Error( "The value of Parameters is invalid! Should be between [0, 1].");
436             }
437             return value;
438         }
439     }
440
441 }
442
443