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.
22 /// Position2D is a two-dimensional vector.
24 public class Position2D : global::System.IDisposable
26 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
30 /// <since_tizen> 3 </since_tizen>
31 protected bool swigCMemOwn;
33 internal Position2D(global::System.IntPtr cPtr, bool cMemoryOwn)
35 swigCMemOwn = cMemoryOwn;
36 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
39 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Position2D obj)
41 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
44 //A Flag to check who called Dispose(). (By User or DisposeQueue)
45 private bool isDisposeQueued = false;
47 /// <since_tizen> 3 </since_tizen>
48 /// A Flat to check if it is already disposed.
50 protected bool disposed = false;
55 /// <since_tizen> 3 </since_tizen>
60 isDisposeQueued = true;
61 DisposeQueue.Instance.Add(this);
68 /// <since_tizen> 3 </since_tizen>
71 //Throw excpetion if Dispose() is called in separate thread.
72 if (!Window.IsInstalled())
74 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
79 Dispose(DisposeTypes.Implicit);
83 Dispose(DisposeTypes.Explicit);
84 System.GC.SuppressFinalize(this);
91 /// <param name="type">The dispose type.</param>
92 /// <since_tizen> 3 </since_tizen>
93 protected virtual void Dispose(DisposeTypes type)
100 if (type == DisposeTypes.Explicit)
103 //Release your own managed resources here.
104 //You should release all of your own disposable objects here.
107 //Release your own unmanaged resources here.
108 //You should not access any managed member here except static instance.
109 //because the execution order of Finalizes is non-deterministic.
111 if (swigCPtr.Handle != global::System.IntPtr.Zero)
116 NDalicPINVOKE.delete_Vector2(swigCPtr);
118 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
124 /// The addition operator.
126 /// <param name="arg1">The vector to add.</param>
127 /// <param name="arg2">The vector to add.</param>
128 /// <returns>The vector containing the result of the addition.</returns>
129 /// <since_tizen> 3 </since_tizen>
130 public static Position2D operator +(Position2D arg1, Position2D arg2)
132 return arg1.Add(arg2);
136 /// The subtraction operator.
138 /// <param name="arg1">The vector to subtract.</param>
139 /// <param name="arg2">The vector to subtract.</param>
140 /// <returns>The vector containing the result of the subtraction.</returns>
141 /// <since_tizen> 3 </since_tizen>
142 public static Position2D operator -(Position2D arg1, Position2D arg2)
144 return arg1.Subtract(arg2);
148 /// The unary negation operator.
150 /// <param name="arg1">The vector to negate.</param>
151 /// <returns>The vector containing the negation.</returns>
152 /// <since_tizen> 3 </since_tizen>
153 public static Position2D operator -(Position2D arg1)
155 return arg1.Subtract();
159 /// The multiplication operator.
161 /// <param name="arg1">The vector to multiply.</param>
162 /// <param name="arg2">The vector to multiply.</param>
163 /// <returns>The vector containing the result of the multiplication.</returns>
164 /// <since_tizen> 3 </since_tizen>
165 public static Position2D operator *(Position2D arg1, Position2D arg2)
167 return arg1.Multiply(arg2);
171 /// The multiplication operator.
173 /// <param name="arg1">The vector to multiply.</param>
174 /// <param name="arg2">The integer value to scale the vector.</param>
175 /// <returns>The vector containing the result of the multiplication.</returns>
176 /// <since_tizen> 3 </since_tizen>
177 public static Position2D operator *(Position2D arg1, int arg2)
179 return arg1.Multiply(arg2);
183 /// The division operator.
185 /// <param name="arg1">The vector to divide.</param>
186 /// <param name="arg2">The vector to divide.</param>
187 /// <returns>The vector containing the result of the division.</returns>
188 /// <since_tizen> 3 </since_tizen>
189 public static Position2D operator /(Position2D arg1, Position2D arg2)
191 return arg1.Divide(arg2);
195 /// The division operator.
197 /// <param name="arg1">The vector to divide.</param>
198 /// <param name="arg2">The integer value to scale the vector by.</param>
199 /// <returns>The vector containing the result of the division.</returns>
200 /// <since_tizen> 3 </since_tizen>
201 public static Position2D operator /(Position2D arg1, int arg2)
203 return arg1.Divide(arg2);
207 /// The const array subscript operator overload. Should be 0, or 1.
209 /// <param name="index">The subscript index.</param>
210 /// <returns>The float at the given index.</returns>
211 /// <since_tizen> 3 </since_tizen>
212 public float this[uint index]
216 return ValueOfIndex(index);
220 internal static Position2D GetPosition2DFromPtr(global::System.IntPtr cPtr)
222 Position2D ret = new Position2D(cPtr, false);
223 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
230 /// <since_tizen> 3 </since_tizen>
231 public Position2D() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
233 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
239 /// <param name="x">x component</param>
240 /// <param name="y">y component</param>
241 /// <since_tizen> 3 </since_tizen>
242 public Position2D(int x, int y) : this(NDalicPINVOKE.new_Vector2__SWIG_1((float)x, (float)y), true)
244 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
250 /// <param name="position">Position to create this vector from</param>
251 /// <since_tizen> 3 </since_tizen>
252 public Position2D(Position position) : this(NDalicPINVOKE.new_Vector2__SWIG_3(Position.getCPtr(position)), true)
254 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
257 private Position2D Add(Position2D rhs)
259 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Add(swigCPtr, Position2D.getCPtr(rhs)), true);
260 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
264 private Position2D Subtract(Position2D rhs)
266 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
267 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
272 private Position2D Multiply(Position2D rhs)
274 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
275 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
279 private Position2D Multiply(int rhs)
281 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, (float)rhs), true);
282 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
287 private Position2D Divide(Position2D rhs)
289 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
290 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
294 private Position2D Divide(int rhs)
296 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, (float)rhs), true);
297 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
301 private Position2D Subtract()
303 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Subtract__SWIG_1(swigCPtr), true);
304 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
309 /// Compares if the rhs is equal to.
311 /// <param name="rhs">The vector to compare</param>
312 /// <returns>Returns true if the two vectors are equal, otherwise false</returns>
313 /// <since_tizen> 3 </since_tizen>
314 public bool EqualTo(Position2D rhs)
316 bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, Position2D.getCPtr(rhs));
317 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
322 /// Compares if the rhs is not equal to.
324 /// <param name="rhs">The vector to compare.</param>
325 /// <returns>Returns true if the two vectors are not equal, otherwise false.</returns>
326 /// <since_tizen> 3 </since_tizen>
327 public bool NotEqualTo(Position2D rhs)
329 bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, Position2D.getCPtr(rhs));
330 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
334 private int ValueOfIndex(uint index)
336 int ret = (int)NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
337 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
344 /// <since_tizen> 3 </since_tizen>
349 NDalicPINVOKE.Vector2_X_set(swigCPtr, (float)value);
350 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
354 float ret = NDalicPINVOKE.Vector2_X_get(swigCPtr);
355 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
363 /// <since_tizen> 3 </since_tizen>
368 NDalicPINVOKE.Vector2_Y_set(swigCPtr, (float)value);
369 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
373 float ret = NDalicPINVOKE.Vector2_Y_get(swigCPtr);
374 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
380 /// Converts a Position2D instance to a Vector2 instance.
382 /// <param name="position2d">An object of the Position2D type.</param>
383 /// <returns>return an object of the Vector2 type</returns>
384 /// <since_tizen> 3 </since_tizen>
385 public static implicit operator Vector2(Position2D position2d)
387 return new Vector2((float)position2d.X, (float)position2d.Y);
391 /// Converts a Vector2 instance to a Position2D instance.
393 /// <param name="vec">An object of the Vector2 type.</param>
394 /// <returns>return an object of the Position2D type</returns>
395 /// <since_tizen> 3 </since_tizen>
396 public static implicit operator Position2D(Vector2 vec)
398 return new Position2D((int)vec.X, (int)vec.Y);
402 /// Converts a Position2D instance to a Uint16Pair instance.
404 /// <param name="position2d">An object of the Position2D type.</param>
405 /// <returns>return an object of the Uint16Pair type</returns>
406 /// <since_tizen> 4 </since_tizen>
407 public static implicit operator Uint16Pair(Position2D position2d)
409 return new Uint16Pair((uint)position2d.X, (uint)position2d.Y);
413 /// Converts a Uint16Pair instance to a Position2D instance.
415 /// <param name="pair">An object of the Uint16Pair type.</param>
416 /// <returns>return an object of the Position2D type</returns>
417 /// <since_tizen> 4 </since_tizen>
418 public static implicit operator Position2D(Uint16Pair pair)
420 return new Position2D((int)pair.GetX(), (int)pair.GetY());