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
\r
26 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
\r
27 protected bool swigCMemOwn;
\r
29 internal Position2D(global::System.IntPtr cPtr, bool cMemoryOwn)
\r
31 swigCMemOwn = cMemoryOwn;
\r
32 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
\r
35 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Position2D obj)
\r
37 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
\r
40 //A Flag to check who called Dispose(). (By User or DisposeQueue)
\r
41 private bool isDisposeQueued = false;
\r
42 //A Flat to check if it is already disposed.
\r
43 protected bool disposed = false;
\r
47 if (!isDisposeQueued)
\r
49 isDisposeQueued = true;
\r
50 DisposeQueue.Instance.Add(this);
\r
54 public void Dispose()
\r
56 //Throw excpetion if Dispose() is called in separate thread.
\r
57 if (!Window.IsInstalled())
\r
59 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
\r
62 if (isDisposeQueued)
\r
64 Dispose(DisposeTypes.Implicit);
\r
68 Dispose(DisposeTypes.Explicit);
\r
69 System.GC.SuppressFinalize(this);
\r
73 protected virtual void Dispose(DisposeTypes type)
\r
80 if (type == DisposeTypes.Explicit)
\r
83 //Release your own managed resources here.
\r
84 //You should release all of your own disposable objects here.
\r
87 //Release your own unmanaged resources here.
\r
88 //You should not access any managed member here except static instance.
\r
89 //because the execution order of Finalizes is non-deterministic.
\r
91 if (swigCPtr.Handle != global::System.IntPtr.Zero)
\r
95 swigCMemOwn = false;
\r
96 NDalicPINVOKE.delete_Vector2(swigCPtr);
\r
98 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
\r
104 /// Addition operator.
106 /// <param name="arg1">Vector to add</param>
107 /// <param name="arg2">Vector to add</param>
108 /// <returns>A vector containing the result of the addition</returns>
109 public static Position2D operator +(Position2D arg1, Position2D arg2)
\r
111 return arg1.Add(arg2);
\r
115 /// Subtraction operator.
117 /// <param name="arg1">Vector to subtract</param>
118 /// <param name="arg2">Vector to subtract</param>
119 /// <returns>A vector containing the result of the subtraction</returns>
120 public static Position2D operator -(Position2D arg1, Position2D arg2)
\r
122 return arg1.Subtract(arg2);
\r
126 /// Unary negation operator.
128 /// <param name="arg1">Vector to netate</param>
129 /// <returns>A vector containing the negation</returns>
130 public static Position2D operator -(Position2D arg1)
\r
132 return arg1.Subtract();
\r
136 /// Multiplication operator.
138 /// <param name="arg1">Vector to multiply</param>
139 /// <param name="arg2">Vector to multiply</param>
140 /// <returns>A vector containing the result of the multiplication</returns>
141 public static Position2D operator *(Position2D arg1, Position2D arg2)
\r
143 return arg1.Multiply(arg2);
\r
147 /// Multiplication operator.
149 /// <param name="arg1">Vector to multiply</param>
150 /// <param name="arg2">The int value to scale the vector</param>
151 /// <returns>A vector containing the result of the multiplication</returns>
152 public static Position2D operator *(Position2D arg1, int arg2)
\r
154 return arg1.Multiply(arg2);
\r
158 /// Division operator.
160 /// <param name="arg1">Vector to divide</param>
161 /// <param name="arg2">Vector to divide</param>
162 /// <returns>A vector containing the result of the division</returns>
163 public static Position2D operator /(Position2D arg1, Position2D arg2)
\r
165 return arg1.Divide(arg2);
\r
169 /// Division operator.
171 /// <param name="arg1">Vector to divide</param>
172 /// <param name="arg2">The int value to scale the vector by</param>
173 /// <returns>A vector containing the result of the division</returns>
174 public static Position2D operator /(Position2D arg1, int arg2)
\r
176 return arg1.Divide(arg2);
\r
180 /// Const array subscript operator overload. Should be 0, or 1.
182 /// <param name="index">Subscript index</param>
183 /// <returns>The float at the given index</returns>
184 public float this[uint index]
\r
188 return ValueOfIndex(index);
\r
192 internal static Position2D GetPosition2DFromPtr(global::System.IntPtr cPtr)
\r
194 Position2D ret = new Position2D(cPtr, false);
\r
195 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
\r
202 public Position2D() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
\r
204 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
\r
210 /// <param name="x">x component</param>
211 /// <param name="y">y component</param>
212 public Position2D(int x, int y) : this(NDalicPINVOKE.new_Vector2__SWIG_1((float)x, (float)y), true)
\r
214 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
\r
220 /// <param name="position">Position to create this vector from</param>
221 public Position2D(Position position) : this(NDalicPINVOKE.new_Vector2__SWIG_3(Position.getCPtr(position)), true)
\r
223 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
\r
226 private Position2D Add(Position2D rhs)
\r
228 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Add(swigCPtr, Position2D.getCPtr(rhs)), true);
\r
229 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
\r
233 private Position2D Subtract(Position2D rhs)
\r
235 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
\r
236 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
\r
241 private Position2D Multiply(Position2D rhs)
\r
243 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
\r
244 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
\r
248 private Position2D Multiply(int rhs)
\r
250 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, (float)rhs), true);
\r
251 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
\r
256 private Position2D Divide(Position2D rhs)
\r
258 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
\r
259 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
\r
263 private Position2D Divide(int rhs)
\r
265 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, (float)rhs), true);
\r
266 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
\r
270 private Position2D Subtract()
\r
272 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Subtract__SWIG_1(swigCPtr), true);
\r
273 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
\r
278 /// Compare if rhs is equal to.
280 /// <param name="rhs">The vector to compare</param>
281 /// <returns>Returns true if the two vectors are equal, otherwise false</returns>
282 public bool EqualTo(Position2D rhs)
\r
284 bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, Position2D.getCPtr(rhs));
\r
285 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
\r
290 /// Compare if rhs is not equal to.
292 /// <param name="rhs">The vector to compare</param>
293 /// <returns>Returns true if the two vectors are not equal, otherwise false</returns>
294 public bool NotEqualTo(Position2D rhs)
\r
296 bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, Position2D.getCPtr(rhs));
\r
297 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
\r
301 private int ValueOfIndex(uint index)
\r
303 int ret = (int)NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
\r
304 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
\r
315 NDalicPINVOKE.Vector2_X_set(swigCPtr, (float)value);
\r
316 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
\r
320 float ret = NDalicPINVOKE.Vector2_X_get(swigCPtr);
\r
321 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
\r
333 NDalicPINVOKE.Vector2_Y_set(swigCPtr, (float)value);
\r
334 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
\r
338 float ret = NDalicPINVOKE.Vector2_Y_get(swigCPtr);
\r
339 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
\r
345 /// Convert a position2D instance to a vector2 instance.
347 public static implicit operator Vector2(Position2D position2d)
\r
349 return new Vector2((float)position2d.X, (float)position2d.Y);
\r
353 /// Convert a vector2 instance to a position2D instance.
355 public static implicit operator Position2D(Vector2 vec)
\r
357 return new Position2D((int)vec.X, (int)vec.Y);
\r