2 * Copyright (c) 2019 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.
18 using System.ComponentModel;
19 using Tizen.NUI.Binding;
24 /// Position2D is a two-dimensional vector.
26 /// <since_tizen> 3 </since_tizen>
27 [Tizen.NUI.Binding.TypeConverter(typeof(Position2DTypeConverter))]
28 public class Position2D : Disposable, ICloneable
30 private Position2DChangedCallback callback = null;
36 /// Position2D and Position are implicitly converted to each other, so these are compatible and can be replaced without any type casting. <br />
37 /// For example, the followings are possible. <br />
38 /// view.Position2D = new Position(10.0f, 10.0f, 10.0f); // be aware that here the z value(10.0f) will be lost. <br />
39 /// view.Position = new Position2D(10, 10); // be aware that here the z value is 0.0f by default. <br />
41 /// <since_tizen> 3 </since_tizen>
42 public Position2D() : this(Interop.Vector2.new_Vector2__SWIG_0(), true)
44 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
50 /// <param name="position">Position to create this vector from</param>
51 /// <since_tizen> 3 </since_tizen>
52 public Position2D(Position position) : this(Interop.Vector2.new_Vector2__SWIG_3(Position.getCPtr(position)), true)
54 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
60 /// <param name="x">x component</param>
61 /// <param name="y">y component</param>
63 /// Position2D and Position are implicitly converted to each other, so these are compatible and can be replaced without any type casting. <br />
64 /// For example, the followings are possible. <br />
65 /// view.Position2D = new Position(10.0f, 10.0f, 10.0f); // be aware that here the z value(10.0f) will be lost. <br />
66 /// view.Position = new Position2D(10, 10); // be aware that here the z value is 0.0f by default. <br />
68 /// <since_tizen> 3 </since_tizen>
69 public Position2D(int x, int y) : this(Interop.Vector2.new_Vector2__SWIG_1((float)x, (float)y), true)
71 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
74 internal Position2D(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
78 internal Position2D(Position2DChangedCallback cb, int x, int y) : this(Interop.Vector2.new_Vector2__SWIG_1((float)x, (float)y), true)
81 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
84 internal delegate void Position2DChangedCallback(int x, int y);
90 /// The setter is deprecated in API8 and will be removed in API10. Please use new Position2D(...) constructor.
93 /// // DO NOT use like the followings!
94 /// Position2D position2d = new Position2D();
96 /// // Please USE like this
98 /// Position2D position2d = new Position2D(x, y);
100 /// <since_tizen> 3 </since_tizen>
105 Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Position2D(...) constructor");
107 Interop.Vector2.Vector2_X_set(swigCPtr, (float)value);
108 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
110 callback?.Invoke(X, Y);
114 float ret = Interop.Vector2.Vector2_X_get(swigCPtr);
115 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
124 /// The setter is deprecated in API8 and will be removed in API10. Please use new Position2D(...) constructor.
127 /// // DO NOT use like the followings!
128 /// Position2D position2d = new Position2D();
129 /// position2d.Y = 2;
130 /// // Please USE like this
131 /// int x = 1, y = 2;
132 /// Position2D position2d = new Position2D(x, y);
134 /// <since_tizen> 3 </since_tizen>
139 Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Position2D(...) constructor");
141 Interop.Vector2.Vector2_Y_set(swigCPtr, (float)value);
142 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
144 callback?.Invoke(X, Y);
148 float ret = Interop.Vector2.Vector2_Y_get(swigCPtr);
149 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
155 /// The const array subscript operator overload. Should be 0, or 1.
157 /// <param name="index">The subscript index.</param>
158 /// <returns>The float at the given index.</returns>
159 /// <since_tizen> 3 </since_tizen>
160 public float this[uint index]
164 return ValueOfIndex(index);
169 /// Convert a string to Position2D.
171 /// <param name="value">The string to convert.</param>
172 /// <returns>The converted value.</returns>
173 static public Position2D ConvertFromString(System.String value)
177 string[] parts = value.Split(',');
178 if (parts.Length == 2)
180 int x = (int)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[0].Trim());
181 int y = (int)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[1].Trim());
182 return new Position2D(x, y);
186 throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Position2D)}");
190 /// Constructor a Position2D from a stirng.
192 public static implicit operator Position2D(System.String value)
194 return ConvertFromString(value);
198 /// The addition operator.
200 /// <param name="arg1">The vector to add.</param>
201 /// <param name="arg2">The vector to add.</param>
202 /// <returns>The vector containing the result of the addition.</returns>
203 /// <since_tizen> 3 </since_tizen>
204 public static Position2D operator +(Position2D arg1, Position2D arg2)
206 return arg1.Add(arg2);
210 /// The subtraction operator.
212 /// <param name="arg1">The vector to subtract.</param>
213 /// <param name="arg2">The vector to subtract.</param>
214 /// <returns>The vector containing the result of the subtraction.</returns>
215 /// <since_tizen> 3 </since_tizen>
216 public static Position2D operator -(Position2D arg1, Position2D arg2)
218 return arg1.Subtract(arg2);
222 /// The unary negation operator.
224 /// <param name="arg1">The vector to negate.</param>
225 /// <returns>The vector containing the negation.</returns>
226 /// <since_tizen> 3 </since_tizen>
227 public static Position2D operator -(Position2D arg1)
229 return arg1.Subtract();
233 /// The multiplication operator.
235 /// <param name="arg1">The vector to multiply.</param>
236 /// <param name="arg2">The vector to multiply.</param>
237 /// <returns>The vector containing the result of the multiplication.</returns>
238 /// <since_tizen> 3 </since_tizen>
239 public static Position2D operator *(Position2D arg1, Position2D arg2)
241 return arg1.Multiply(arg2);
245 /// The multiplication operator.
247 /// <param name="arg1">The vector to multiply.</param>
248 /// <param name="arg2">The integer value to scale the vector.</param>
249 /// <returns>The vector containing the result of the multiplication.</returns>
250 /// <since_tizen> 3 </since_tizen>
251 public static Position2D operator *(Position2D arg1, int arg2)
253 return arg1.Multiply(arg2);
257 /// The division operator.
259 /// <param name="arg1">The vector to divide.</param>
260 /// <param name="arg2">The vector to divide.</param>
261 /// <returns>The vector containing the result of the division.</returns>
262 /// <since_tizen> 3 </since_tizen>
263 public static Position2D operator /(Position2D arg1, Position2D arg2)
265 return arg1.Divide(arg2);
269 /// The division operator.
271 /// <param name="arg1">The vector to divide.</param>
272 /// <param name="arg2">The integer value to scale the vector by.</param>
273 /// <returns>The vector containing the result of the division.</returns>
274 /// <since_tizen> 3 </since_tizen>
275 public static Position2D operator /(Position2D arg1, int arg2)
277 return arg1.Divide(arg2);
281 /// Determines whether the specified object is equal to the current object.
283 /// <param name="obj">The object to compare with the current object.</param>
284 /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
285 public override bool Equals(System.Object obj)
287 Position2D position2D = obj as Position2D;
289 if (X == position2D?.X && Y == position2D?.Y)
297 /// Gets the the hash code of this Position2D.
299 /// <returns>The Hash Code.</returns>
300 /// <since_tizen> 6 </since_tizen>
301 public override int GetHashCode()
303 return swigCPtr.Handle.GetHashCode();
307 /// Compares if the rhs is equal to.
309 /// <param name="rhs">The vector to compare</param>
310 /// <returns>Returns true if the two vectors are equal, otherwise false</returns>
311 /// <since_tizen> 3 </since_tizen>
312 public bool EqualTo(Position2D rhs)
314 bool ret = Interop.Vector2.Vector2_EqualTo(swigCPtr, Position2D.getCPtr(rhs));
315 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
320 /// Compares if the rhs is not equal to.
322 /// <param name="rhs">The vector to compare.</param>
323 /// <returns>Returns true if the two vectors are not equal, otherwise false.</returns>
324 /// <since_tizen> 3 </since_tizen>
325 public bool NotEqualTo(Position2D rhs)
327 bool ret = Interop.Vector2.Vector2_NotEqualTo(swigCPtr, Position2D.getCPtr(rhs));
328 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
333 /// Converts a Position2D instance to a Vector2 instance.
335 /// <param name="position2d">An object of the Position2D type.</param>
336 /// <returns>return an object of the Vector2 type</returns>
337 /// <since_tizen> 3 </since_tizen>
338 public static implicit operator Vector2(Position2D position2d)
340 return new Vector2((float)position2d.X, (float)position2d.Y);
344 /// Converts a Vector2 instance to a Position2D instance.
346 /// <param name="vec">An object of the Vector2 type.</param>
347 /// <returns>return an object of the Position2D type</returns>
348 /// <since_tizen> 3 </since_tizen>
349 public static implicit operator Position2D(Vector2 vec)
351 return new Position2D((int)vec.X, (int)vec.Y);
355 /// Implicit type cast operator, Position to Position2D
357 /// <param name="position">The object of Position type.</param>
358 /// <since_tizen> none </since_tizen>
359 /// This will be public opened in tizen_next by ACR.
360 [EditorBrowsable(EditorBrowsableState.Never)]
361 public static implicit operator Position2D(Position position)
363 return new Position2D((int)position.X, (int)position.Y);
367 [EditorBrowsable(EditorBrowsableState.Never)]
368 public object Clone() => new Position2D(this);
370 internal static Position2D GetPosition2DFromPtr(global::System.IntPtr cPtr)
372 Position2D ret = new Position2D(cPtr, false);
373 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
377 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Position2D obj)
379 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
382 /// This will not be public opened.
383 [EditorBrowsable(EditorBrowsableState.Never)]
384 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
386 Interop.Vector2.delete_Vector2(swigCPtr);
389 private Position2D Add(Position2D rhs)
391 Position2D ret = new Position2D(Interop.Vector2.Vector2_Add(swigCPtr, Position2D.getCPtr(rhs)), true);
392 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
396 private Position2D Subtract(Position2D rhs)
398 Position2D ret = new Position2D(Interop.Vector2.Vector2_Subtract__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
399 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
403 private Position2D Multiply(Position2D rhs)
405 Position2D ret = new Position2D(Interop.Vector2.Vector2_Multiply__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
406 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
410 private Position2D Multiply(int rhs)
412 Position2D ret = new Position2D(Interop.Vector2.Vector2_Multiply__SWIG_1(swigCPtr, (float)rhs), true);
413 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
417 private Position2D Divide(Position2D rhs)
419 Position2D ret = new Position2D(Interop.Vector2.Vector2_Divide__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
420 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
424 private Position2D Divide(int rhs)
426 Position2D ret = new Position2D(Interop.Vector2.Vector2_Divide__SWIG_1(swigCPtr, (float)rhs), true);
427 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
431 private Position2D Subtract()
433 Position2D ret = new Position2D(Interop.Vector2.Vector2_Subtract__SWIG_1(swigCPtr), true);
434 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
438 private int ValueOfIndex(uint index)
440 int ret = (int)Interop.Vector2.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
441 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();