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);
89 /// <since_tizen> 3 </since_tizen>
90 [Obsolete("Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Position2D(...) constructor")]
95 Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Position2D(...) constructor");
97 Interop.Vector2.Vector2_X_set(swigCPtr, (float)value);
98 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
100 callback?.Invoke(X, Y);
104 float ret = Interop.Vector2.Vector2_X_get(swigCPtr);
105 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
113 /// <since_tizen> 3 </since_tizen>
114 [Obsolete("Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Position2D(...) constructor")]
119 Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Position2D(...) constructor");
121 Interop.Vector2.Vector2_Y_set(swigCPtr, (float)value);
122 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
124 callback?.Invoke(X, Y);
128 float ret = Interop.Vector2.Vector2_Y_get(swigCPtr);
129 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
135 /// The const array subscript operator overload. Should be 0, or 1.
137 /// <param name="index">The subscript index.</param>
138 /// <returns>The float at the given index.</returns>
139 /// <since_tizen> 3 </since_tizen>
140 public float this[uint index]
144 return ValueOfIndex(index);
149 /// Convert a string to Position2D.
151 /// <param name="value">The string to convert.</param>
152 /// <returns>The converted value.</returns>
153 static public Position2D ConvertFromString(System.String value)
157 string[] parts = value.Split(',');
158 if (parts.Length == 2)
160 int x = (int)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[0].Trim());
161 int y = (int)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[1].Trim());
162 return new Position2D(x, y);
166 throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Position2D)}");
170 /// Constructor a Position2D from a stirng.
172 public static implicit operator Position2D(System.String value)
174 return ConvertFromString(value);
178 /// The addition operator.
180 /// <param name="arg1">The vector to add.</param>
181 /// <param name="arg2">The vector to add.</param>
182 /// <returns>The vector containing the result of the addition.</returns>
183 /// <since_tizen> 3 </since_tizen>
184 public static Position2D operator +(Position2D arg1, Position2D arg2)
186 return arg1.Add(arg2);
190 /// The subtraction operator.
192 /// <param name="arg1">The vector to subtract.</param>
193 /// <param name="arg2">The vector to subtract.</param>
194 /// <returns>The vector containing the result of the subtraction.</returns>
195 /// <since_tizen> 3 </since_tizen>
196 public static Position2D operator -(Position2D arg1, Position2D arg2)
198 return arg1.Subtract(arg2);
202 /// The unary negation operator.
204 /// <param name="arg1">The vector to negate.</param>
205 /// <returns>The vector containing the negation.</returns>
206 /// <since_tizen> 3 </since_tizen>
207 public static Position2D operator -(Position2D arg1)
209 return arg1.Subtract();
213 /// The multiplication operator.
215 /// <param name="arg1">The vector to multiply.</param>
216 /// <param name="arg2">The vector to multiply.</param>
217 /// <returns>The vector containing the result of the multiplication.</returns>
218 /// <since_tizen> 3 </since_tizen>
219 public static Position2D operator *(Position2D arg1, Position2D arg2)
221 return arg1.Multiply(arg2);
225 /// The multiplication operator.
227 /// <param name="arg1">The vector to multiply.</param>
228 /// <param name="arg2">The integer value to scale the vector.</param>
229 /// <returns>The vector containing the result of the multiplication.</returns>
230 /// <since_tizen> 3 </since_tizen>
231 public static Position2D operator *(Position2D arg1, int arg2)
233 return arg1.Multiply(arg2);
237 /// The division operator.
239 /// <param name="arg1">The vector to divide.</param>
240 /// <param name="arg2">The vector to divide.</param>
241 /// <returns>The vector containing the result of the division.</returns>
242 /// <since_tizen> 3 </since_tizen>
243 public static Position2D operator /(Position2D arg1, Position2D arg2)
245 return arg1.Divide(arg2);
249 /// The division operator.
251 /// <param name="arg1">The vector to divide.</param>
252 /// <param name="arg2">The integer value to scale the vector by.</param>
253 /// <returns>The vector containing the result of the division.</returns>
254 /// <since_tizen> 3 </since_tizen>
255 public static Position2D operator /(Position2D arg1, int arg2)
257 return arg1.Divide(arg2);
261 /// Determines whether the specified object is equal to the current object.
263 /// <param name="obj">The object to compare with the current object.</param>
264 /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
265 public override bool Equals(System.Object obj)
267 Position2D position2D = obj as Position2D;
269 if (X == position2D?.X && Y == position2D?.Y)
277 /// Gets the the hash code of this Position2D.
279 /// <returns>The Hash Code.</returns>
280 /// <since_tizen> 6 </since_tizen>
281 public override int GetHashCode()
283 return swigCPtr.Handle.GetHashCode();
287 /// Compares if the rhs is equal to.
289 /// <param name="rhs">The vector to compare</param>
290 /// <returns>Returns true if the two vectors are equal, otherwise false</returns>
291 /// <since_tizen> 3 </since_tizen>
292 public bool EqualTo(Position2D rhs)
294 bool ret = Interop.Vector2.Vector2_EqualTo(swigCPtr, Position2D.getCPtr(rhs));
295 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
300 /// Compares if the rhs is not equal to.
302 /// <param name="rhs">The vector to compare.</param>
303 /// <returns>Returns true if the two vectors are not equal, otherwise false.</returns>
304 /// <since_tizen> 3 </since_tizen>
305 public bool NotEqualTo(Position2D rhs)
307 bool ret = Interop.Vector2.Vector2_NotEqualTo(swigCPtr, Position2D.getCPtr(rhs));
308 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
313 /// Converts a Position2D instance to a Vector2 instance.
315 /// <param name="position2d">An object of the Position2D type.</param>
316 /// <returns>return an object of the Vector2 type</returns>
317 /// <since_tizen> 3 </since_tizen>
318 public static implicit operator Vector2(Position2D position2d)
320 return new Vector2((float)position2d.X, (float)position2d.Y);
324 /// Converts a Vector2 instance to a Position2D instance.
326 /// <param name="vec">An object of the Vector2 type.</param>
327 /// <returns>return an object of the Position2D type</returns>
328 /// <since_tizen> 3 </since_tizen>
329 public static implicit operator Position2D(Vector2 vec)
331 return new Position2D((int)vec.X, (int)vec.Y);
335 /// Implicit type cast operator, Position to Position2D
337 /// <param name="position">The object of Position type.</param>
338 /// <since_tizen> none </since_tizen>
339 /// This will be public opened in tizen_next by ACR.
340 [EditorBrowsable(EditorBrowsableState.Never)]
341 public static implicit operator Position2D(Position position)
343 return new Position2D((int)position.X, (int)position.Y);
347 [EditorBrowsable(EditorBrowsableState.Never)]
348 public object Clone() => new Position2D(this);
350 internal static Position2D GetPosition2DFromPtr(global::System.IntPtr cPtr)
352 Position2D ret = new Position2D(cPtr, false);
353 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
357 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Position2D obj)
359 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
362 /// This will not be public opened.
363 [EditorBrowsable(EditorBrowsableState.Never)]
364 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
366 Interop.Vector2.delete_Vector2(swigCPtr);
369 private Position2D Add(Position2D rhs)
371 Position2D ret = new Position2D(Interop.Vector2.Vector2_Add(swigCPtr, Position2D.getCPtr(rhs)), true);
372 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
376 private Position2D Subtract(Position2D rhs)
378 Position2D ret = new Position2D(Interop.Vector2.Vector2_Subtract__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
379 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
383 private Position2D Multiply(Position2D rhs)
385 Position2D ret = new Position2D(Interop.Vector2.Vector2_Multiply__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
386 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
390 private Position2D Multiply(int rhs)
392 Position2D ret = new Position2D(Interop.Vector2.Vector2_Multiply__SWIG_1(swigCPtr, (float)rhs), true);
393 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
397 private Position2D Divide(Position2D rhs)
399 Position2D ret = new Position2D(Interop.Vector2.Vector2_Divide__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
400 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
404 private Position2D Divide(int rhs)
406 Position2D ret = new Position2D(Interop.Vector2.Vector2_Divide__SWIG_1(swigCPtr, (float)rhs), true);
407 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
411 private Position2D Subtract()
413 Position2D ret = new Position2D(Interop.Vector2.Vector2_Subtract__SWIG_1(swigCPtr), true);
414 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
418 private int ValueOfIndex(uint index)
420 int ret = (int)Interop.Vector2.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
421 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();