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;
27 protected bool swigCMemOwn;
29 internal Position2D(global::System.IntPtr cPtr, bool cMemoryOwn)
31 swigCMemOwn = cMemoryOwn;
32 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
35 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Position2D obj)
37 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
40 //A Flag to check who called Dispose(). (By User or DisposeQueue)
41 private bool isDisposeQueued = false;
42 //A Flat to check if it is already disposed.
43 protected bool disposed = false;
49 isDisposeQueued = true;
50 DisposeQueue.Instance.Add(this);
56 //Throw excpetion if Dispose() is called in separate thread.
57 if (!Window.IsInstalled())
59 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
64 Dispose(DisposeTypes.Implicit);
68 Dispose(DisposeTypes.Explicit);
69 System.GC.SuppressFinalize(this);
73 protected virtual void Dispose(DisposeTypes type)
80 if (type == DisposeTypes.Explicit)
83 //Release your own managed resources here.
84 //You should release all of your own disposable objects here.
87 //Release your own unmanaged resources here.
88 //You should not access any managed member here except static instance.
89 //because the execution order of Finalizes is non-deterministic.
91 if (swigCPtr.Handle != global::System.IntPtr.Zero)
96 NDalicPINVOKE.delete_Vector2(swigCPtr);
98 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
104 /// The addition operator.
106 /// <param name="arg1">The vector to add.</param>
107 /// <param name="arg2">The vector to add.</param>
108 /// <returns>The vector containing the result of the addition.</returns>
109 /// <since_tizen> 3 </since_tizen>
110 public static Position2D operator +(Position2D arg1, Position2D arg2)
112 return arg1.Add(arg2);
116 /// The subtraction operator.
118 /// <param name="arg1">The vector to subtract.</param>
119 /// <param name="arg2">The vector to subtract.</param>
120 /// <returns>The vector containing the result of the subtraction.</returns>
121 /// <since_tizen> 3 </since_tizen>
122 public static Position2D operator -(Position2D arg1, Position2D arg2)
124 return arg1.Subtract(arg2);
128 /// The unary negation operator.
130 /// <param name="arg1">The vector to negate.</param>
131 /// <returns>The vector containing the negation.</returns>
132 /// <since_tizen> 3 </since_tizen>
133 public static Position2D operator -(Position2D arg1)
135 return arg1.Subtract();
139 /// The multiplication operator.
141 /// <param name="arg1">The vector to multiply.</param>
142 /// <param name="arg2">The vector to multiply.</param>
143 /// <returns>The vector containing the result of the multiplication.</returns>
144 /// <since_tizen> 3 </since_tizen>
145 public static Position2D operator *(Position2D arg1, Position2D arg2)
147 return arg1.Multiply(arg2);
151 /// The multiplication operator.
153 /// <param name="arg1">The vector to multiply.</param>
154 /// <param name="arg2">The integer value to scale the vector.</param>
155 /// <returns>The vector containing the result of the multiplication.</returns>
156 /// <since_tizen> 3 </since_tizen>
157 public static Position2D operator *(Position2D arg1, int arg2)
159 return arg1.Multiply(arg2);
163 /// The division operator.
165 /// <param name="arg1">The vector to divide.</param>
166 /// <param name="arg2">The vector to divide.</param>
167 /// <returns>The vector containing the result of the division.</returns>
168 /// <since_tizen> 3 </since_tizen>
169 public static Position2D operator /(Position2D arg1, Position2D arg2)
171 return arg1.Divide(arg2);
175 /// The division operator.
177 /// <param name="arg1">The vector to divide.</param>
178 /// <param name="arg2">The integer value to scale the vector by.</param>
179 /// <returns>The vector containing the result of the division.</returns>
180 /// <since_tizen> 3 </since_tizen>
181 public static Position2D operator /(Position2D arg1, int arg2)
183 return arg1.Divide(arg2);
187 /// The const array subscript operator overload. Should be 0, or 1.
189 /// <param name="index">The subscript index.</param>
190 /// <returns>The float at the given index.</returns>
191 /// <since_tizen> 3 </since_tizen>
192 public float this[uint index]
196 return ValueOfIndex(index);
200 internal static Position2D GetPosition2DFromPtr(global::System.IntPtr cPtr)
202 Position2D ret = new Position2D(cPtr, false);
203 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
210 /// <since_tizen> 3 </since_tizen>
211 public Position2D() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
213 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
219 /// <param name="x">x component</param>
220 /// <param name="y">y component</param>
221 /// <since_tizen> 3 </since_tizen>
222 public Position2D(int x, int y) : this(NDalicPINVOKE.new_Vector2__SWIG_1((float)x, (float)y), true)
224 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
230 /// <param name="position">Position to create this vector from</param>
231 /// <since_tizen> 3 </since_tizen>
232 public Position2D(Position position) : this(NDalicPINVOKE.new_Vector2__SWIG_3(Position.getCPtr(position)), true)
234 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
237 private Position2D Add(Position2D rhs)
239 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Add(swigCPtr, Position2D.getCPtr(rhs)), true);
240 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
244 private Position2D Subtract(Position2D rhs)
246 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
247 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
252 private Position2D Multiply(Position2D rhs)
254 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
255 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
259 private Position2D Multiply(int rhs)
261 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, (float)rhs), true);
262 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
267 private Position2D Divide(Position2D rhs)
269 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
270 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
274 private Position2D Divide(int rhs)
276 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, (float)rhs), true);
277 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
281 private Position2D Subtract()
283 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Subtract__SWIG_1(swigCPtr), true);
284 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
289 /// Compares if the rhs is equal to.
291 /// <param name="rhs">The vector to compare</param>
292 /// <returns>Returns true if the two vectors are equal, otherwise false</returns>
293 /// <since_tizen> 3 </since_tizen>
294 public bool EqualTo(Position2D rhs)
296 bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, Position2D.getCPtr(rhs));
297 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
302 /// Compares if the rhs is not equal to.
304 /// <param name="rhs">The vector to compare.</param>
305 /// <returns>Returns true if the two vectors are not equal, otherwise false.</returns>
306 /// <since_tizen> 3 </since_tizen>
307 public bool NotEqualTo(Position2D rhs)
309 bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, Position2D.getCPtr(rhs));
310 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
314 private int ValueOfIndex(uint index)
316 int ret = (int)NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
317 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
324 /// <since_tizen> 3 </since_tizen>
329 NDalicPINVOKE.Vector2_X_set(swigCPtr, (float)value);
330 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
334 float ret = NDalicPINVOKE.Vector2_X_get(swigCPtr);
335 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
343 /// <since_tizen> 3 </since_tizen>
348 NDalicPINVOKE.Vector2_Y_set(swigCPtr, (float)value);
349 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
353 float ret = NDalicPINVOKE.Vector2_Y_get(swigCPtr);
354 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
360 /// Converts a Position2D instance to a Vector2 instance.
362 /// <since_tizen> 3 </since_tizen>
363 public static implicit operator Vector2(Position2D position2d)
365 return new Vector2((float)position2d.X, (float)position2d.Y);
369 /// Converts a Vector2 instance to a Position2D instance.
371 /// <since_tizen> 3 </since_tizen>
372 public static implicit operator Position2D(Vector2 vec)
374 return new Position2D((int)vec.X, (int)vec.Y);
378 /// Converts a Position2D instance to a Uint16Pair instance.
380 /// <since_tizen> 4 </since_tizen>
381 public static implicit operator Uint16Pair(Position2D position2d)
383 return new Uint16Pair((uint)position2d.X, (uint)position2d.Y);
387 /// Converts a Uint16Pair instance to a Position2D instance.
389 /// <since_tizen> 4 </since_tizen>
390 public static implicit operator Position2D(Uint16Pair pair)
392 return new Position2D((int)pair.GetX(), (int)pair.GetY());