41c2cec1aaa17e5e4f16d1de4288b46167d5a805
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / RelativeVector2.cs
1 /*
2  * Copyright (c) 2019 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 using System.ComponentModel;
19 using Tizen.NUI.Binding;
20
21 namespace Tizen.NUI
22 {
23     /// <summary>
24     /// RelativeVector2 is a two-dimensional vector.
25     /// Both values (x and y) should be between [0, 1].
26     /// </summary>
27     /// <since_tizen> 3 </since_tizen>
28     [Binding.TypeConverter(typeof(RelativeVector2TypeConverter))]
29     public class RelativeVector2 : Disposable
30     {
31
32         /// <summary>
33         /// The constructor.
34         /// </summary>
35         /// <since_tizen> 3 </since_tizen>
36         public RelativeVector2() : this(Interop.Vector2.NewVector2(), true)
37         {
38             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
39         }
40
41         /// <summary>
42         /// The constructor.
43         /// </summary>
44         /// <param name="x">The x component.</param>
45         /// <param name="y">The y component.</param>
46         /// <since_tizen> 3 </since_tizen>
47         public RelativeVector2(float x, float y) : this(Interop.Vector2.NewVector2(x, y), true)
48         {
49             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
50         }
51
52         /// <summary>
53         /// The constructor.
54         /// </summary>
55         /// <param name="relativeVector3">The RelativeVector3 to create this vector from.</param>
56         /// <since_tizen> 3 </since_tizen>
57         public RelativeVector2(RelativeVector3 relativeVector3) : this(Interop.Vector2.NewVector2WithVector3(RelativeVector3.getCPtr(relativeVector3)), true)
58         {
59             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
60         }
61
62         /// <summary>
63         /// The constructor.
64         /// </summary>
65         /// <param name="relativeVector4">The RelativeVector4 to create this vector from.</param>
66         /// <since_tizen> 3 </since_tizen>
67         public RelativeVector2(RelativeVector4 relativeVector4) : this(Interop.Vector2.NewVector2WithVector4(RelativeVector4.getCPtr(relativeVector4)), true)
68         {
69             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
70         }
71
72         internal RelativeVector2(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
73         {
74         }
75
76         /// <summary>
77         /// The x component.
78         /// </summary>
79         /// <remarks>
80         /// The setter is deprecated in API8 and will be removed in API10. Please use new RelativeVector2(...) constructor.
81         /// </remarks>
82         /// <code>
83         /// // DO NOT use like the followings!
84         /// RelativeVector2 relativeVector2 = new RelativeVector2();
85         /// relativeVector2.X = 0.1f; 
86         /// // Please USE like this
87         /// float x = 0.1f, y = 0.9f;
88         /// RelativeVector2 relativeVector2 = new RelativeVector2(x, y);
89         /// </code>
90         /// <since_tizen> 3 </since_tizen>
91         public float X
92         {
93             set
94             {
95                 Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new RelativeVector2(...) constructor");
96
97                 Interop.Vector2.XSet(swigCPtr, value);
98                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
99             }
100             get
101             {
102                 float ret = Interop.Vector2.XGet(swigCPtr);
103                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
104                 return ret;
105             }
106         }
107
108         /// <summary>
109         /// The y component.
110         /// </summary>
111         /// <remarks>
112         /// The setter is deprecated in API8 and will be removed in API10. Please use new RelativeVector2(...) constructor.
113         /// </remarks>
114         /// <code>
115         /// // DO NOT use like the followings!
116         /// RelativeVector2 relativeVector2 = new RelativeVector2();
117         /// relativeVector2.Y = 0.9f; 
118         /// // Please USE like this
119         /// float x = 0.1f, y = 0.9f;
120         /// RelativeVector2 relativeVector2 = new RelativeVector2(x, y);
121         /// </code>
122         /// <since_tizen> 3 </since_tizen>
123         public float Y
124         {
125             set
126             {
127                 Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new RelativeVector2(...) constructor");
128
129                 Interop.Vector2.YSet(swigCPtr, value);
130                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
131             }
132             get
133             {
134                 float ret = Interop.Vector2.YGet(swigCPtr);
135                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
136                 return ret;
137             }
138         }
139
140         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(RelativeVector2 obj)
141         {
142             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
143         }
144
145         /// <summary>
146         /// The addition operator.
147         /// </summary>
148         /// <param name="arg1">The vector to add.</param>
149         /// <param name="arg2">The vector to add.</param>
150         /// <returns>The vector containing the result of the addition.</returns>
151         /// <since_tizen> 3 </since_tizen>
152         public static RelativeVector2 operator +(RelativeVector2 arg1, RelativeVector2 arg2)
153         {
154             RelativeVector2 result = arg1?.Add(arg2);
155             return result;
156         }
157
158         /// <summary>
159         /// The subtraction operator.
160         /// </summary>
161         /// <param name="arg1">The vector to subtract.</param>
162         /// <param name="arg2">The vector to subtract.</param>
163         /// <returns>The vector containing the result of the subtraction.</returns>
164         /// <since_tizen> 3 </since_tizen>
165         public static RelativeVector2 operator -(RelativeVector2 arg1, RelativeVector2 arg2)
166         {
167             RelativeVector2 result = arg1?.Subtract(arg2);
168             return result;
169         }
170
171         /// <summary>
172         /// The multiplication operator.
173         /// </summary>
174         /// <param name="arg1">The vector to multiply.</param>
175         /// <param name="arg2">The vector to multiply.</param>
176         /// <returns>The vector containing the result of the multiplication.</returns>
177         /// <since_tizen> 3 </since_tizen>
178         public static RelativeVector2 operator *(RelativeVector2 arg1, RelativeVector2 arg2)
179         {
180             RelativeVector2 result = arg1?.Multiply(arg2);
181             return result;
182         }
183
184         /// <summary>
185         /// The multiplication operator.
186         /// </summary>
187         /// <param name="arg1">The vector to multiply.</param>
188         /// <param name="arg2">The float value to scale the vector.</param>
189         /// <returns>The vector containing the result of the scaling.</returns>
190         /// <since_tizen> 3 </since_tizen>
191         public static RelativeVector2 operator *(RelativeVector2 arg1, float arg2)
192         {
193             RelativeVector2 result = arg1?.Multiply(arg2);
194             return result;
195         }
196
197         /// <summary>
198         /// The division operator.
199         /// </summary>
200         /// <param name="arg1">The vector to divide.</param>
201         /// <param name="arg2">The vector to divide.</param>
202         /// <returns>The vector containing the result of the division.</returns>
203         /// <since_tizen> 3 </since_tizen>
204         public static RelativeVector2 operator /(RelativeVector2 arg1, RelativeVector2 arg2)
205         {
206             RelativeVector2 result = arg1?.Divide(arg2);
207             return result;
208         }
209
210         /// <summary>
211         /// The division operator.
212         /// </summary>
213         /// <param name="arg1">The vector to divide.</param>
214         /// <param name="arg2">The float value to scale the vector by.</param>
215         /// <returns>The vector containing the result of the scaling.</returns>
216         /// <since_tizen> 3 </since_tizen>
217         public static RelativeVector2 operator /(RelativeVector2 arg1, float arg2)
218         {
219             RelativeVector2 result = arg1?.Divide(arg2);
220             return result;
221         }
222
223         /// <summary>
224         /// </summary>
225         /// <since_tizen> 3 </since_tizen>
226         public static implicit operator Vector2(RelativeVector2 relativeVector2)
227         {
228             return new Vector2((float)relativeVector2?.X, (float)relativeVector2.Y);
229         }
230
231         /// <summary>
232         /// </summary>
233         /// <since_tizen> 3 </since_tizen>
234         public static implicit operator RelativeVector2(Vector2 vec)
235         {
236             return new RelativeVector2((float)vec?.X, (float)vec.Y);
237         }
238
239         /// <summary>
240         /// The const array subscript operator overload. Should be 0, 1.
241         /// </summary>
242         /// <param name="index">The subscript index.</param>
243         /// <returns>The float at the given index.</returns>
244         /// <since_tizen> 3 </since_tizen>
245         public float this[uint index]
246         {
247             get
248             {
249                 return ValueOfIndex(index);
250             }
251         }
252
253         /// <summary>
254         /// Determines whether the specified object is equal to the current object.
255         /// </summary>
256         /// <param name="obj">The object to compare with the current object.</param>
257         /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
258         public override bool Equals(System.Object obj)
259         {
260             RelativeVector2 relativeRector2 = obj as RelativeVector2;
261             bool equal = false;
262             if (X == relativeRector2?.X && Y == relativeRector2?.Y)
263             {
264                 equal = true;
265             }
266             return equal;
267         }
268
269         /// <summary>
270         /// Gets the the hash code of this RelativeVector2.
271         /// </summary>
272         /// <returns>The Hash Code.</returns>
273         /// <since_tizen> 6 </since_tizen>
274         public override int GetHashCode()
275         {
276             return swigCPtr.Handle.GetHashCode();
277         }
278
279         /// <summary>
280         /// Compares if the rhs is equal to.
281         /// </summary>
282         /// <param name="rhs">The vector to compare.</param>
283         /// <returns>Returns true if the two vectors are equal, otherwise false.</returns>
284         /// <since_tizen> 3 </since_tizen>
285         public bool EqualTo(RelativeVector2 rhs)
286         {
287             bool ret = Interop.Vector2.EqualTo(swigCPtr, RelativeVector2.getCPtr(rhs));
288             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
289             return ret;
290         }
291
292         /// <summary>
293         /// Compares if the rhs is not equal to.
294         /// </summary>
295         /// <param name="rhs">The vector to compare.</param>
296         /// <returns>Returns true if the two vectors are not equal, otherwise false.</returns>
297         /// <since_tizen> 3 </since_tizen>
298         public bool NotEqualTo(RelativeVector2 rhs)
299         {
300             bool ret = Interop.Vector2.NotEqualTo(swigCPtr, RelativeVector2.getCPtr(rhs));
301             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
302             return ret;
303         }
304
305         /// <summary>
306         /// </summary>
307         internal static RelativeVector2 GetRelativeVector2FromPtr(global::System.IntPtr cPtr)
308         {
309             RelativeVector2 ret = new RelativeVector2(cPtr, false);
310             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
311             return ret;
312         }
313
314         /// This will not be public opened.
315         [EditorBrowsable(EditorBrowsableState.Never)]
316         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
317         {
318             Interop.Vector2.DeleteVector2(swigCPtr);
319         }
320
321         private RelativeVector2 Add(RelativeVector2 rhs)
322         {
323             RelativeVector2 ret = new RelativeVector2(Interop.Vector2.Add(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
324             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
325             return ret;
326         }
327
328         private RelativeVector2 Subtract(RelativeVector2 rhs)
329         {
330             RelativeVector2 ret = new RelativeVector2(Interop.Vector2.Subtract(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
331             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
332             return ret;
333         }
334
335         private RelativeVector2 Multiply(RelativeVector2 rhs)
336         {
337             RelativeVector2 ret = new RelativeVector2(Interop.Vector2.Multiply(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
338             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
339             return ret;
340         }
341
342         private RelativeVector2 Multiply(float rhs)
343         {
344             RelativeVector2 ret = new RelativeVector2(Interop.Vector2.Multiply(swigCPtr, rhs), true);
345             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
346             return ret;
347         }
348
349         private RelativeVector2 Divide(RelativeVector2 rhs)
350         {
351             RelativeVector2 ret = new RelativeVector2(Interop.Vector2.Divide(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
352             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
353             return ret;
354         }
355
356         private RelativeVector2 Divide(float rhs)
357         {
358             RelativeVector2 ret = new RelativeVector2(Interop.Vector2.Divide(swigCPtr, rhs), true);
359             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
360             return ret;
361         }
362
363         private float ValueOfIndex(uint index)
364         {
365             float ret = Interop.Vector2.ValueOfIndex(swigCPtr, index);
366             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
367             return ret;
368         }
369     }
370 }
371
372