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 /// <since_tizen> 3 </since_tizen>
25 public class Position2D : global::System.IDisposable
27 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
31 /// <since_tizen> 3 </since_tizen>
32 protected bool swigCMemOwn;
34 internal Position2D(global::System.IntPtr cPtr, bool cMemoryOwn)
36 swigCMemOwn = cMemoryOwn;
37 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
40 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Position2D obj)
42 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
45 //A Flag to check who called Dispose(). (By User or DisposeQueue)
46 private bool isDisposeQueued = false;
48 /// A Flat to check if it is already disposed.
50 /// <since_tizen> 3 </since_tizen>
51 protected bool disposed = false;
56 /// <since_tizen> 3 </since_tizen>
61 isDisposeQueued = true;
62 DisposeQueue.Instance.Add(this);
69 /// <since_tizen> 3 </since_tizen>
72 //Throw excpetion if Dispose() is called in separate thread.
73 if (!Window.IsInstalled())
75 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
80 Dispose(DisposeTypes.Implicit);
84 Dispose(DisposeTypes.Explicit);
85 System.GC.SuppressFinalize(this);
92 /// <param name="type">The dispose type.</param>
93 /// <since_tizen> 3 </since_tizen>
94 protected virtual void Dispose(DisposeTypes type)
101 if (type == DisposeTypes.Explicit)
104 //Release your own managed resources here.
105 //You should release all of your own disposable objects here.
108 //Release your own unmanaged resources here.
109 //You should not access any managed member here except static instance.
110 //because the execution order of Finalizes is non-deterministic.
112 if (swigCPtr.Handle != global::System.IntPtr.Zero)
117 NDalicPINVOKE.delete_Vector2(swigCPtr);
119 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
125 /// The addition operator.
127 /// <param name="arg1">The vector to add.</param>
128 /// <param name="arg2">The vector to add.</param>
129 /// <returns>The vector containing the result of the addition.</returns>
130 /// <since_tizen> 3 </since_tizen>
131 public static Position2D operator +(Position2D arg1, Position2D arg2)
133 return arg1.Add(arg2);
137 /// The subtraction operator.
139 /// <param name="arg1">The vector to subtract.</param>
140 /// <param name="arg2">The vector to subtract.</param>
141 /// <returns>The vector containing the result of the subtraction.</returns>
142 /// <since_tizen> 3 </since_tizen>
143 public static Position2D operator -(Position2D arg1, Position2D arg2)
145 return arg1.Subtract(arg2);
149 /// The unary negation operator.
151 /// <param name="arg1">The vector to negate.</param>
152 /// <returns>The vector containing the negation.</returns>
153 /// <since_tizen> 3 </since_tizen>
154 public static Position2D operator -(Position2D arg1)
156 return arg1.Subtract();
160 /// The multiplication operator.
162 /// <param name="arg1">The vector to multiply.</param>
163 /// <param name="arg2">The vector to multiply.</param>
164 /// <returns>The vector containing the result of the multiplication.</returns>
165 /// <since_tizen> 3 </since_tizen>
166 public static Position2D operator *(Position2D arg1, Position2D arg2)
168 return arg1.Multiply(arg2);
172 /// The multiplication operator.
174 /// <param name="arg1">The vector to multiply.</param>
175 /// <param name="arg2">The integer value to scale the vector.</param>
176 /// <returns>The vector containing the result of the multiplication.</returns>
177 /// <since_tizen> 3 </since_tizen>
178 public static Position2D operator *(Position2D arg1, int arg2)
180 return arg1.Multiply(arg2);
184 /// The division operator.
186 /// <param name="arg1">The vector to divide.</param>
187 /// <param name="arg2">The vector to divide.</param>
188 /// <returns>The vector containing the result of the division.</returns>
189 /// <since_tizen> 3 </since_tizen>
190 public static Position2D operator /(Position2D arg1, Position2D arg2)
192 return arg1.Divide(arg2);
196 /// The division operator.
198 /// <param name="arg1">The vector to divide.</param>
199 /// <param name="arg2">The integer value to scale the vector by.</param>
200 /// <returns>The vector containing the result of the division.</returns>
201 /// <since_tizen> 3 </since_tizen>
202 public static Position2D operator /(Position2D arg1, int arg2)
204 return arg1.Divide(arg2);
208 /// The const array subscript operator overload. Should be 0, or 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);
221 internal static Position2D GetPosition2DFromPtr(global::System.IntPtr cPtr)
223 Position2D ret = new Position2D(cPtr, false);
224 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
231 /// <since_tizen> 3 </since_tizen>
232 public Position2D() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
234 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
240 /// <param name="x">x component</param>
241 /// <param name="y">y component</param>
242 /// <since_tizen> 3 </since_tizen>
243 public Position2D(int x, int y) : this(NDalicPINVOKE.new_Vector2__SWIG_1((float)x, (float)y), true)
245 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
251 /// <param name="position">Position to create this vector from</param>
252 /// <since_tizen> 3 </since_tizen>
253 public Position2D(Position position) : this(NDalicPINVOKE.new_Vector2__SWIG_3(Position.getCPtr(position)), true)
255 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
258 private Position2D Add(Position2D rhs)
260 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Add(swigCPtr, Position2D.getCPtr(rhs)), true);
261 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
265 private Position2D Subtract(Position2D rhs)
267 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
268 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
273 private Position2D Multiply(Position2D rhs)
275 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
276 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
280 private Position2D Multiply(int rhs)
282 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, (float)rhs), true);
283 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
288 private Position2D Divide(Position2D rhs)
290 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
291 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
295 private Position2D Divide(int rhs)
297 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, (float)rhs), true);
298 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
302 private Position2D Subtract()
304 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Subtract__SWIG_1(swigCPtr), true);
305 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
310 /// Compares if the rhs is equal to.
312 /// <param name="rhs">The vector to compare</param>
313 /// <returns>Returns true if the two vectors are equal, otherwise false</returns>
314 /// <since_tizen> 3 </since_tizen>
315 public bool EqualTo(Position2D rhs)
317 bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, Position2D.getCPtr(rhs));
318 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
323 /// Compares if the rhs is not equal to.
325 /// <param name="rhs">The vector to compare.</param>
326 /// <returns>Returns true if the two vectors are not equal, otherwise false.</returns>
327 /// <since_tizen> 3 </since_tizen>
328 public bool NotEqualTo(Position2D rhs)
330 bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, Position2D.getCPtr(rhs));
331 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
335 private int ValueOfIndex(uint index)
337 int ret = (int)NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
338 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
345 /// <since_tizen> 3 </since_tizen>
350 NDalicPINVOKE.Vector2_X_set(swigCPtr, (float)value);
351 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
355 float ret = NDalicPINVOKE.Vector2_X_get(swigCPtr);
356 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
364 /// <since_tizen> 3 </since_tizen>
369 NDalicPINVOKE.Vector2_Y_set(swigCPtr, (float)value);
370 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
374 float ret = NDalicPINVOKE.Vector2_Y_get(swigCPtr);
375 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
381 /// Converts a Position2D instance to a Vector2 instance.
383 /// <param name="position2d">An object of the Position2D type.</param>
384 /// <returns>return an object of the Vector2 type</returns>
385 /// <since_tizen> 3 </since_tizen>
386 public static implicit operator Vector2(Position2D position2d)
388 return new Vector2((float)position2d.X, (float)position2d.Y);
392 /// Converts a Vector2 instance to a Position2D instance.
394 /// <param name="vec">An object of the Vector2 type.</param>
395 /// <returns>return an object of the Position2D type</returns>
396 /// <since_tizen> 3 </since_tizen>
397 public static implicit operator Position2D(Vector2 vec)
399 return new Position2D((int)vec.X, (int)vec.Y);