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 /// <since_tizen> 3 </since_tizen>
92 protected virtual void Dispose(DisposeTypes type)
99 if (type == DisposeTypes.Explicit)
102 //Release your own managed resources here.
103 //You should release all of your own disposable objects here.
106 //Release your own unmanaged resources here.
107 //You should not access any managed member here except static instance.
108 //because the execution order of Finalizes is non-deterministic.
110 if (swigCPtr.Handle != global::System.IntPtr.Zero)
115 NDalicPINVOKE.delete_Vector2(swigCPtr);
117 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
123 /// The addition operator.
125 /// <param name="arg1">The vector to add.</param>
126 /// <param name="arg2">The vector to add.</param>
127 /// <returns>The vector containing the result of the addition.</returns>
128 /// <since_tizen> 3 </since_tizen>
129 public static Position2D operator +(Position2D arg1, Position2D arg2)
131 return arg1.Add(arg2);
135 /// The subtraction operator.
137 /// <param name="arg1">The vector to subtract.</param>
138 /// <param name="arg2">The vector to subtract.</param>
139 /// <returns>The vector containing the result of the subtraction.</returns>
140 /// <since_tizen> 3 </since_tizen>
141 public static Position2D operator -(Position2D arg1, Position2D arg2)
143 return arg1.Subtract(arg2);
147 /// The unary negation operator.
149 /// <param name="arg1">The vector to negate.</param>
150 /// <returns>The vector containing the negation.</returns>
151 /// <since_tizen> 3 </since_tizen>
152 public static Position2D operator -(Position2D arg1)
154 return arg1.Subtract();
158 /// The multiplication operator.
160 /// <param name="arg1">The vector to multiply.</param>
161 /// <param name="arg2">The vector to multiply.</param>
162 /// <returns>The vector containing the result of the multiplication.</returns>
163 /// <since_tizen> 3 </since_tizen>
164 public static Position2D operator *(Position2D arg1, Position2D arg2)
166 return arg1.Multiply(arg2);
170 /// The multiplication operator.
172 /// <param name="arg1">The vector to multiply.</param>
173 /// <param name="arg2">The integer value to scale the vector.</param>
174 /// <returns>The vector containing the result of the multiplication.</returns>
175 /// <since_tizen> 3 </since_tizen>
176 public static Position2D operator *(Position2D arg1, int arg2)
178 return arg1.Multiply(arg2);
182 /// The division operator.
184 /// <param name="arg1">The vector to divide.</param>
185 /// <param name="arg2">The vector to divide.</param>
186 /// <returns>The vector containing the result of the division.</returns>
187 /// <since_tizen> 3 </since_tizen>
188 public static Position2D operator /(Position2D arg1, Position2D arg2)
190 return arg1.Divide(arg2);
194 /// The division operator.
196 /// <param name="arg1">The vector to divide.</param>
197 /// <param name="arg2">The integer value to scale the vector by.</param>
198 /// <returns>The vector containing the result of the division.</returns>
199 /// <since_tizen> 3 </since_tizen>
200 public static Position2D operator /(Position2D arg1, int arg2)
202 return arg1.Divide(arg2);
206 /// The const array subscript operator overload. Should be 0, or 1.
208 /// <param name="index">The subscript index.</param>
209 /// <returns>The float at the given index.</returns>
210 /// <since_tizen> 3 </since_tizen>
211 public float this[uint index]
215 return ValueOfIndex(index);
219 internal static Position2D GetPosition2DFromPtr(global::System.IntPtr cPtr)
221 Position2D ret = new Position2D(cPtr, false);
222 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
229 /// <since_tizen> 3 </since_tizen>
230 public Position2D() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
232 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
238 /// <param name="x">x component</param>
239 /// <param name="y">y component</param>
240 /// <since_tizen> 3 </since_tizen>
241 public Position2D(int x, int y) : this(NDalicPINVOKE.new_Vector2__SWIG_1((float)x, (float)y), true)
243 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
249 /// <param name="position">Position to create this vector from</param>
250 /// <since_tizen> 3 </since_tizen>
251 public Position2D(Position position) : this(NDalicPINVOKE.new_Vector2__SWIG_3(Position.getCPtr(position)), true)
253 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
256 private Position2D Add(Position2D rhs)
258 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Add(swigCPtr, Position2D.getCPtr(rhs)), true);
259 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
263 private Position2D Subtract(Position2D rhs)
265 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
266 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
271 private Position2D Multiply(Position2D rhs)
273 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
274 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
278 private Position2D Multiply(int rhs)
280 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, (float)rhs), true);
281 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
286 private Position2D Divide(Position2D rhs)
288 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
289 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
293 private Position2D Divide(int rhs)
295 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, (float)rhs), true);
296 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
300 private Position2D Subtract()
302 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Subtract__SWIG_1(swigCPtr), true);
303 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
308 /// Compares if the rhs is equal to.
310 /// <param name="rhs">The vector to compare</param>
311 /// <returns>Returns true if the two vectors are equal, otherwise false</returns>
312 /// <since_tizen> 3 </since_tizen>
313 public bool EqualTo(Position2D rhs)
315 bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, Position2D.getCPtr(rhs));
316 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
321 /// Compares if the rhs is not equal to.
323 /// <param name="rhs">The vector to compare.</param>
324 /// <returns>Returns true if the two vectors are not equal, otherwise false.</returns>
325 /// <since_tizen> 3 </since_tizen>
326 public bool NotEqualTo(Position2D rhs)
328 bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, Position2D.getCPtr(rhs));
329 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
333 private int ValueOfIndex(uint index)
335 int ret = (int)NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
336 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
343 /// <since_tizen> 3 </since_tizen>
348 NDalicPINVOKE.Vector2_X_set(swigCPtr, (float)value);
349 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
353 float ret = NDalicPINVOKE.Vector2_X_get(swigCPtr);
354 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
362 /// <since_tizen> 3 </since_tizen>
367 NDalicPINVOKE.Vector2_Y_set(swigCPtr, (float)value);
368 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
372 float ret = NDalicPINVOKE.Vector2_Y_get(swigCPtr);
373 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
379 /// Converts a Position2D instance to a Vector2 instance.
381 /// <since_tizen> 3 </since_tizen>
382 public static implicit operator Vector2(Position2D position2d)
384 return new Vector2((float)position2d.X, (float)position2d.Y);
388 /// Converts a Vector2 instance to a Position2D instance.
390 /// <since_tizen> 3 </since_tizen>
391 public static implicit operator Position2D(Vector2 vec)
393 return new Position2D((int)vec.X, (int)vec.Y);
397 /// Converts a Position2D instance to a Uint16Pair instance.
399 /// <since_tizen> 4 </since_tizen>
400 public static implicit operator Uint16Pair(Position2D position2d)
402 return new Uint16Pair((uint)position2d.X, (uint)position2d.Y);
406 /// Converts a Uint16Pair instance to a Position2D instance.
408 /// <since_tizen> 4 </since_tizen>
409 public static implicit operator Position2D(Uint16Pair pair)
411 return new Position2D((int)pair.GetX(), (int)pair.GetY());