2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using Tizen.NUI.Binding;
24 /// RelativeVector2 is a two-dimensional vector.
25 /// Both values (x and y) should be between [0, 1].
27 /// <since_tizen> 3 </since_tizen>
28 [TypeConverter(typeof(RelativeVector2TypeConverter))]
29 public class RelativeVector2 : global::System.IDisposable
31 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
35 /// <since_tizen> 3 </since_tizen>
36 protected bool swigCMemOwn;
38 internal RelativeVector2(global::System.IntPtr cPtr, bool cMemoryOwn)
40 swigCMemOwn = cMemoryOwn;
41 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
44 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(RelativeVector2 obj)
46 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
49 //A Flag to check who called Dispose(). (By User or DisposeQueue)
50 private bool isDisposeQueued = false;
52 /// A Flat to check if it is already disposed.
54 /// <since_tizen> 3 </since_tizen>
55 protected bool disposed = false;
60 /// <since_tizen> 3 </since_tizen>
65 isDisposeQueued = true;
66 DisposeQueue.Instance.Add(this);
73 /// <since_tizen> 3 </since_tizen>
76 //Throw excpetion if Dispose() is called in separate thread.
77 if (!Window.IsInstalled())
79 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
84 Dispose(DisposeTypes.Implicit);
88 Dispose(DisposeTypes.Explicit);
89 System.GC.SuppressFinalize(this);
96 /// <since_tizen> 3 </since_tizen>
97 protected virtual void Dispose(DisposeTypes type)
104 if(type == DisposeTypes.Explicit)
107 //Release your own managed resources here.
108 //You should release all of your own disposable objects here.
111 //Release your own unmanaged resources here.
112 //You should not access any managed member here except static instance.
113 //because the execution order of Finalizes is non-deterministic.
115 if (swigCPtr.Handle != global::System.IntPtr.Zero)
120 NDalicPINVOKE.delete_Vector2(swigCPtr);
122 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
129 /// The addition operator.
131 /// <param name="arg1">The vector to add.</param>
132 /// <param name="arg2">The vector to add.</param>
133 /// <returns>The vector containing the result of the addition.</returns>
134 /// <since_tizen> 3 </since_tizen>
135 public static RelativeVector2 operator +(RelativeVector2 arg1, RelativeVector2 arg2)
137 RelativeVector2 result = arg1.Add(arg2);
138 return ValueCheck(result);
142 /// The subtraction operator.
144 /// <param name="arg1">The vector to subtract.</param>
145 /// <param name="arg2">The vector to subtract.</param>
146 /// <returns>The vector containing the result of the subtraction.</returns>
147 /// <since_tizen> 3 </since_tizen>
148 public static RelativeVector2 operator -(RelativeVector2 arg1, RelativeVector2 arg2)
150 RelativeVector2 result = arg1.Subtract(arg2);
151 return ValueCheck(result);
155 /// The multiplication operator.
157 /// <param name="arg1">The vector to multiply.</param>
158 /// <param name="arg2">The vector to multiply.</param>
159 /// <returns>The vector containing the result of the multiplication.</returns>
160 /// <since_tizen> 3 </since_tizen>
161 public static RelativeVector2 operator *(RelativeVector2 arg1, RelativeVector2 arg2)
163 RelativeVector2 result = arg1.Multiply(arg2);
164 return ValueCheck(result);
168 /// The multiplication operator.
170 /// <param name="arg1">The vector to multiply.</param>
171 /// <param name="arg2">The float value to scale the vector.</param>
172 /// <returns>The vector containing the result of the scaling.</returns>
173 /// <since_tizen> 3 </since_tizen>
174 public static RelativeVector2 operator *(RelativeVector2 arg1, float arg2)
176 RelativeVector2 result = arg1.Multiply(arg2);
177 return ValueCheck(result);
181 /// The division operator.
183 /// <param name="arg1">The vector to divide.</param>
184 /// <param name="arg2">The vector to divide.</param>
185 /// <returns>The vector containing the result of the division.</returns>
186 /// <since_tizen> 3 </since_tizen>
187 public static RelativeVector2 operator /(RelativeVector2 arg1, RelativeVector2 arg2)
189 RelativeVector2 result = arg1.Divide(arg2);
190 return ValueCheck(result);
194 /// The division operator.
196 /// <param name="arg1">The vector to divide.</param>
197 /// <param name="arg2">The float value to scale the vector by.</param>
198 /// <returns>The vector containing the result of the scaling.</returns>
199 /// <since_tizen> 3 </since_tizen>
200 public static RelativeVector2 operator /(RelativeVector2 arg1, float arg2)
202 RelativeVector2 result = arg1.Divide(arg2);
203 return ValueCheck(result);
208 /// The const array subscript operator overload. Should be 0, 1.
210 /// <param name="index">The subscript index.</param>
211 /// <returns>The float at the given index.</returns>
212 /// <since_tizen> 3 </since_tizen>
213 public float this[uint index]
217 return ValueOfIndex(index);
223 internal static RelativeVector2 GetRelativeVector2FromPtr(global::System.IntPtr cPtr)
225 RelativeVector2 ret = new RelativeVector2(cPtr, false);
226 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
234 /// <since_tizen> 3 </since_tizen>
235 public RelativeVector2() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
237 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
243 /// <param name="x">The x component.</param>
244 /// <param name="y">The y component.</param>
245 /// <since_tizen> 3 </since_tizen>
246 public RelativeVector2(float x, float y) : this(NDalicPINVOKE.new_Vector2__SWIG_1(ValueCheck(x), ValueCheck(y)), true)
248 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
254 /// <param name="relativeVector3">The RelativeVector3 to create this vector from.</param>
255 /// <since_tizen> 3 </since_tizen>
256 public RelativeVector2(RelativeVector3 relativeVector3) : this(NDalicPINVOKE.new_Vector2__SWIG_3(RelativeVector3.getCPtr(relativeVector3)), true)
258 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
264 /// <param name="relativeVector4">The RelativeVector4 to create this vector from.</param>
265 /// <since_tizen> 3 </since_tizen>
266 public RelativeVector2(RelativeVector4 relativeVector4) : this(NDalicPINVOKE.new_Vector2__SWIG_4(RelativeVector4.getCPtr(relativeVector4)), true)
268 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
272 private RelativeVector2 Add(RelativeVector2 rhs)
274 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Add(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
275 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
279 private RelativeVector2 Subtract(RelativeVector2 rhs)
281 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
282 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
286 private RelativeVector2 Multiply(RelativeVector2 rhs)
288 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
289 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
293 private RelativeVector2 Multiply(float rhs)
295 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, rhs), true);
296 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
300 private RelativeVector2 Divide(RelativeVector2 rhs)
302 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
303 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
307 private RelativeVector2 Divide(float rhs)
309 RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, rhs), true);
310 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
314 private float ValueOfIndex(uint index)
316 float ret = NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
317 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
322 /// Compares if the rhs is equal to.
324 /// <param name="rhs">The vector to compare.</param>
325 /// <returns>Returns true if the two vectors are equal, otherwise false.</returns>
326 /// <since_tizen> 3 </since_tizen>
327 public bool EqualTo(RelativeVector2 rhs)
329 bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, RelativeVector2.getCPtr(rhs));
330 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
335 /// Compares if the rhs is not equal to.
337 /// <param name="rhs">The vector to compare.</param>
338 /// <returns>Returns true if the two vectors are not equal, otherwise false.</returns>
339 /// <since_tizen> 3 </since_tizen>
340 public bool NotEqualTo(RelativeVector2 rhs)
342 bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, RelativeVector2.getCPtr(rhs));
343 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
351 /// <since_tizen> 3 </since_tizen>
356 NDalicPINVOKE.Vector2_X_set(swigCPtr, ValueCheck(value));
357 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
361 float ret = NDalicPINVOKE.Vector2_X_get(swigCPtr);
362 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
370 /// <since_tizen> 3 </since_tizen>
375 NDalicPINVOKE.Vector2_Y_set(swigCPtr, ValueCheck(value));
376 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
380 float ret = NDalicPINVOKE.Vector2_Y_get(swigCPtr);
381 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
388 /// <since_tizen> 3 </since_tizen>
389 public static implicit operator Vector2(RelativeVector2 relativeVector2)
391 return new Vector2(relativeVector2.X, relativeVector2.Y);
396 /// <since_tizen> 3 </since_tizen>
397 public static implicit operator RelativeVector2(Vector2 vec)
399 return new RelativeVector2(ValueCheck(vec.X), ValueCheck(vec.Y));
402 internal static RelativeVector2 ValueCheck(RelativeVector2 relativeVector2)
404 if(relativeVector2.X < 0.0f)
406 relativeVector2.X = 0.0f;
407 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
409 else if(relativeVector2.X > 1.0f)
411 relativeVector2.X = 1.0f;
412 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
414 if(relativeVector2.Y < 0.0f)
416 relativeVector2.Y = 0.0f;
417 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
419 else if(relativeVector2.Y > 1.0f)
421 relativeVector2.Y = 1.0f;
422 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
424 return relativeVector2;
427 internal static float ValueCheck(float value)
432 NUILog.Error( "The value of Parameters is invalid! Should be between [0, 1].");
434 else if(value > 1.0f)
437 NUILog.Error( "The value of Parameters is invalid! Should be between [0, 1].");