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 /// Position2D is a two-dimensional vector.
26 /// <since_tizen> 3 </since_tizen>
27 [Tizen.NUI.Binding.TypeConverter(typeof(Position2DTypeConverter))]
28 public class Position2D : global::System.IDisposable
30 static public Position2D ConvertFromString(System.String value)
34 string[] parts = value.Split(',');
35 if (parts.Length == 2)
37 return new Position2D(int.Parse(parts[0].Trim()), int.Parse(parts[1].Trim()));
41 throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Position2D)}");
44 public static implicit operator Position2D(System.String value)
46 return ConvertFromString(value);
49 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
53 /// <since_tizen> 3 </since_tizen>
54 protected bool swigCMemOwn;
56 internal Position2D(global::System.IntPtr cPtr, bool cMemoryOwn)
58 swigCMemOwn = cMemoryOwn;
59 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
62 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Position2D obj)
64 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
67 //A Flag to check who called Dispose(). (By User or DisposeQueue)
68 private bool isDisposeQueued = false;
70 /// A Flat to check if it is already disposed.
72 /// <since_tizen> 3 </since_tizen>
73 protected bool disposed = false;
78 /// <since_tizen> 3 </since_tizen>
83 isDisposeQueued = true;
84 DisposeQueue.Instance.Add(this);
91 /// <since_tizen> 3 </since_tizen>
94 //Throw excpetion if Dispose() is called in separate thread.
95 if (!Window.IsInstalled())
97 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
102 Dispose(DisposeTypes.Implicit);
106 Dispose(DisposeTypes.Explicit);
107 System.GC.SuppressFinalize(this);
114 /// <param name="type">The dispose type.</param>
115 /// <since_tizen> 3 </since_tizen>
116 protected virtual void Dispose(DisposeTypes type)
123 if (type == DisposeTypes.Explicit)
126 //Release your own managed resources here.
127 //You should release all of your own disposable objects here.
130 //Release your own unmanaged resources here.
131 //You should not access any managed member here except static instance.
132 //because the execution order of Finalizes is non-deterministic.
134 if (swigCPtr.Handle != global::System.IntPtr.Zero)
139 NDalicPINVOKE.delete_Vector2(swigCPtr);
141 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
147 /// The addition operator.
149 /// <param name="arg1">The vector to add.</param>
150 /// <param name="arg2">The vector to add.</param>
151 /// <returns>The vector containing the result of the addition.</returns>
152 /// <since_tizen> 3 </since_tizen>
153 public static Position2D operator +(Position2D arg1, Position2D arg2)
155 return arg1.Add(arg2);
159 /// The subtraction operator.
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 Position2D operator -(Position2D arg1, Position2D arg2)
167 return arg1.Subtract(arg2);
171 /// The unary negation operator.
173 /// <param name="arg1">The vector to negate.</param>
174 /// <returns>The vector containing the negation.</returns>
175 /// <since_tizen> 3 </since_tizen>
176 public static Position2D operator -(Position2D arg1)
178 return arg1.Subtract();
182 /// The multiplication operator.
184 /// <param name="arg1">The vector to multiply.</param>
185 /// <param name="arg2">The vector to multiply.</param>
186 /// <returns>The vector containing the result of the multiplication.</returns>
187 /// <since_tizen> 3 </since_tizen>
188 public static Position2D operator *(Position2D arg1, Position2D arg2)
190 return arg1.Multiply(arg2);
194 /// The multiplication operator.
196 /// <param name="arg1">The vector to multiply.</param>
197 /// <param name="arg2">The integer value to scale the vector.</param>
198 /// <returns>The vector containing the result of the multiplication.</returns>
199 /// <since_tizen> 3 </since_tizen>
200 public static Position2D operator *(Position2D arg1, int arg2)
202 return arg1.Multiply(arg2);
206 /// The division operator.
208 /// <param name="arg1">The vector to divide.</param>
209 /// <param name="arg2">The vector to divide.</param>
210 /// <returns>The vector containing the result of the division.</returns>
211 /// <since_tizen> 3 </since_tizen>
212 public static Position2D operator /(Position2D arg1, Position2D arg2)
214 return arg1.Divide(arg2);
218 /// The division operator.
220 /// <param name="arg1">The vector to divide.</param>
221 /// <param name="arg2">The integer value to scale the vector by.</param>
222 /// <returns>The vector containing the result of the division.</returns>
223 /// <since_tizen> 3 </since_tizen>
224 public static Position2D operator /(Position2D arg1, int arg2)
226 return arg1.Divide(arg2);
230 /// The const array subscript operator overload. Should be 0, or 1.
232 /// <param name="index">The subscript index.</param>
233 /// <returns>The float at the given index.</returns>
234 /// <since_tizen> 3 </since_tizen>
235 public float this[uint index]
239 return ValueOfIndex(index);
243 internal static Position2D GetPosition2DFromPtr(global::System.IntPtr cPtr)
245 Position2D ret = new Position2D(cPtr, false);
246 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
253 /// <since_tizen> 3 </since_tizen>
254 public Position2D() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
256 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
262 /// <param name="x">x component</param>
263 /// <param name="y">y component</param>
264 /// <since_tizen> 3 </since_tizen>
265 public Position2D(int x, int y) : this(NDalicPINVOKE.new_Vector2__SWIG_1((float)x, (float)y), true)
267 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
273 /// <param name="position">Position to create this vector from</param>
274 /// <since_tizen> 3 </since_tizen>
275 public Position2D(Position position) : this(NDalicPINVOKE.new_Vector2__SWIG_3(Position.getCPtr(position)), true)
277 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
280 private Position2D Add(Position2D rhs)
282 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Add(swigCPtr, Position2D.getCPtr(rhs)), true);
283 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
287 private Position2D Subtract(Position2D rhs)
289 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
290 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
295 private Position2D Multiply(Position2D rhs)
297 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
298 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
302 private Position2D Multiply(int rhs)
304 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, (float)rhs), true);
305 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
310 private Position2D Divide(Position2D rhs)
312 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
313 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
317 private Position2D Divide(int rhs)
319 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, (float)rhs), true);
320 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
324 private Position2D Subtract()
326 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Subtract__SWIG_1(swigCPtr), true);
327 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
332 /// Determines whether the specified object is equal to the current object.
334 /// <param name="obj">The object to compare with the current object.</param>
335 /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
336 public override bool Equals(System.Object obj)
338 Position2D position2D = obj as Position2D;
340 if (X == position2D?.X && Y == position2D?.Y)
348 /// Compares if the rhs is equal to.
350 /// <param name="rhs">The vector to compare</param>
351 /// <returns>Returns true if the two vectors are equal, otherwise false</returns>
352 /// <since_tizen> 3 </since_tizen>
353 public bool EqualTo(Position2D rhs)
355 bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, Position2D.getCPtr(rhs));
356 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
361 /// Compares if the rhs is not equal to.
363 /// <param name="rhs">The vector to compare.</param>
364 /// <returns>Returns true if the two vectors are not equal, otherwise false.</returns>
365 /// <since_tizen> 3 </since_tizen>
366 public bool NotEqualTo(Position2D rhs)
368 bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, Position2D.getCPtr(rhs));
369 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
373 private int ValueOfIndex(uint index)
375 int ret = (int)NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
376 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
383 /// <since_tizen> 3 </since_tizen>
388 NDalicPINVOKE.Vector2_X_set(swigCPtr, (float)value);
389 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
393 float ret = NDalicPINVOKE.Vector2_X_get(swigCPtr);
394 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
402 /// <since_tizen> 3 </since_tizen>
407 NDalicPINVOKE.Vector2_Y_set(swigCPtr, (float)value);
408 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
412 float ret = NDalicPINVOKE.Vector2_Y_get(swigCPtr);
413 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
419 /// Converts a Position2D instance to a Vector2 instance.
421 /// <param name="position2d">An object of the Position2D type.</param>
422 /// <returns>return an object of the Vector2 type</returns>
423 /// <since_tizen> 3 </since_tizen>
424 public static implicit operator Vector2(Position2D position2d)
426 return new Vector2((float)position2d.X, (float)position2d.Y);
430 /// Converts a Vector2 instance to a Position2D instance.
432 /// <param name="vec">An object of the Vector2 type.</param>
433 /// <returns>return an object of the Position2D type</returns>
434 /// <since_tizen> 3 </since_tizen>
435 public static implicit operator Position2D(Vector2 vec)
437 return new Position2D((int)vec.X, (int)vec.Y);