/* * Copyright (c) 2019 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ using System; using System.ComponentModel; using Tizen.NUI.Binding; namespace Tizen.NUI { /// /// Position2D is a two-dimensional vector. /// /// 3 [Tizen.NUI.Binding.TypeConverter(typeof(Position2DTypeConverter))] public class Position2D : Disposable, ICloneable { private Position2DChangedCallback callback = null; /// /// The constructor. /// /// /// Position2D and Position are implicitly converted to each other, so these are compatible and can be replaced without any type casting.
/// For example, the followings are possible.
/// view.Position2D = new Position(10.0f, 10.0f, 10.0f); // be aware that here the z value(10.0f) will be lost.
/// view.Position = new Position2D(10, 10); // be aware that here the z value is 0.0f by default.
///
/// 3 public Position2D() : this(Interop.Vector2.NewVector2(), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// The constructor. /// /// Position to create this vector from /// 3 public Position2D(Position position) : this(Interop.Vector2.NewVector2WithVector3(Position.getCPtr(position)), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// The constructor. /// /// x component /// y component /// /// Position2D and Position are implicitly converted to each other, so these are compatible and can be replaced without any type casting.
/// For example, the followings are possible.
/// view.Position2D = new Position(10.0f, 10.0f, 10.0f); // be aware that here the z value(10.0f) will be lost.
/// view.Position = new Position2D(10, 10); // be aware that here the z value is 0.0f by default.
///
/// 3 public Position2D(int x, int y) : this(Interop.Vector2.NewVector2((float)x, (float)y), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } internal Position2D(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn) { } internal Position2D(Position2DChangedCallback cb, int x, int y) : this(Interop.Vector2.NewVector2((float)x, (float)y), true) { callback = cb; if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } internal delegate void Position2DChangedCallback(int x, int y); /// /// The x component. /// /// /// The setter is deprecated in API8 and will be removed in API10. Please use new Position2D(...) constructor. /// /// /// // DO NOT use like the followings! /// Position2D position2d = new Position2D(); /// position2d.X = 1; /// // Please USE like this /// int x = 1, y = 2; /// Position2D position2d = new Position2D(x, y); /// /// 3 public int X { set { Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Position2D(...) constructor"); Interop.Vector2.XSet(swigCPtr, (float)value); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); callback?.Invoke(X, Y); } get { float ret = Interop.Vector2.XGet(swigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); return (int)ret; } } /// /// The y component. /// /// /// The setter is deprecated in API8 and will be removed in API10. Please use new Position2D(...) constructor. /// /// /// // DO NOT use like the followings! /// Position2D position2d = new Position2D(); /// position2d.Y = 2; /// // Please USE like this /// int x = 1, y = 2; /// Position2D position2d = new Position2D(x, y); /// /// 3 public int Y { set { Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Position2D(...) constructor"); Interop.Vector2.YSet(swigCPtr, (float)value); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); callback?.Invoke(X, Y); } get { float ret = Interop.Vector2.YGet(swigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); return (int)ret; } } /// /// The const array subscript operator overload. Should be 0, or 1. /// /// The subscript index. /// The float at the given index. /// 3 public float this[uint index] { get { return ValueOfIndex(index); } } /// /// Convert a string to Position2D. /// /// The string to convert. /// The converted value. static public Position2D ConvertFromString(System.String value) { if (value != null) { string[] parts = value.Split(','); if (parts.Length == 2) { int x = (int)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[0].Trim()); int y = (int)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[1].Trim()); return new Position2D(x, y); } } throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Position2D)}"); } /// /// Constructor a Position2D from a stirng. /// public static implicit operator Position2D(System.String value) { return ConvertFromString(value); } /// /// The addition operator. /// /// The vector to add. /// The vector to add. /// The vector containing the result of the addition. /// 3 public static Position2D operator +(Position2D arg1, Position2D arg2) { return arg1?.Add(arg2); } /// /// The subtraction operator. /// /// The vector to subtract. /// The vector to subtract. /// The vector containing the result of the subtraction. /// 3 public static Position2D operator -(Position2D arg1, Position2D arg2) { return arg1?.Subtract(arg2); } /// /// The unary negation operator. /// /// The vector to negate. /// The vector containing the negation. /// 3 public static Position2D operator -(Position2D arg1) { return arg1?.Subtract(); } /// /// The multiplication operator. /// /// The vector to multiply. /// The vector to multiply. /// The vector containing the result of the multiplication. /// 3 public static Position2D operator *(Position2D arg1, Position2D arg2) { return arg1?.Multiply(arg2); } /// /// The multiplication operator. /// /// The vector to multiply. /// The integer value to scale the vector. /// The vector containing the result of the multiplication. /// 3 public static Position2D operator *(Position2D arg1, int arg2) { return arg1?.Multiply(arg2); } /// /// The division operator. /// /// The vector to divide. /// The vector to divide. /// The vector containing the result of the division. /// 3 public static Position2D operator /(Position2D arg1, Position2D arg2) { return arg1?.Divide(arg2); } /// /// The division operator. /// /// The vector to divide. /// The integer value to scale the vector by. /// The vector containing the result of the division. /// 3 public static Position2D operator /(Position2D arg1, int arg2) { return arg1?.Divide(arg2); } /// /// Determines whether the specified object is equal to the current object. /// /// The object to compare with the current object. /// true if the specified object is equal to the current object; otherwise, false. public override bool Equals(System.Object obj) { Position2D position2D = obj as Position2D; bool equal = false; if (X == position2D?.X && Y == position2D?.Y) { equal = true; } return equal; } /// /// Gets the the hash code of this Position2D. /// /// The Hash Code. /// 6 public override int GetHashCode() { return swigCPtr.Handle.GetHashCode(); } /// /// Compares if the rhs is equal to. /// /// The vector to compare /// Returns true if the two vectors are equal, otherwise false /// 3 public bool EqualTo(Position2D rhs) { bool ret = Interop.Vector2.EqualTo(swigCPtr, Position2D.getCPtr(rhs)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Compares if the rhs is not equal to. /// /// The vector to compare. /// Returns true if the two vectors are not equal, otherwise false. /// 3 public bool NotEqualTo(Position2D rhs) { bool ret = Interop.Vector2.NotEqualTo(swigCPtr, Position2D.getCPtr(rhs)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Converts a Position2D instance to a Vector2 instance. /// /// An object of the Position2D type. /// return an object of the Vector2 type /// 3 public static implicit operator Vector2(Position2D position2d) { return new Vector2((float)position2d?.X, (float)position2d.Y); } /// /// Converts a Vector2 instance to a Position2D instance. /// /// An object of the Vector2 type. /// return an object of the Position2D type /// 3 public static implicit operator Position2D(Vector2 vec) { return new Position2D((int)vec?.X, (int)vec.Y); } /// /// Implicit type cast operator, Position to Position2D /// /// The object of Position type. /// none /// This will be public opened in tizen_next by ACR. [EditorBrowsable(EditorBrowsableState.Never)] public static implicit operator Position2D(Position position) { return new Position2D((int)position?.X, (int)position.Y); } /// [EditorBrowsable(EditorBrowsableState.Never)] public object Clone() => new Position2D(this); internal static Position2D GetPosition2DFromPtr(global::System.IntPtr cPtr) { Position2D ret = new Position2D(cPtr, false); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Position2D obj) { return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; } /// This will not be public opened. [EditorBrowsable(EditorBrowsableState.Never)] protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr) { Interop.Vector2.DeleteVector2(swigCPtr); } private Position2D Add(Position2D rhs) { Position2D ret = new Position2D(Interop.Vector2.Add(swigCPtr, Position2D.getCPtr(rhs)), true); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } private Position2D Subtract(Position2D rhs) { Position2D ret = new Position2D(Interop.Vector2.Subtract(swigCPtr, Position2D.getCPtr(rhs)), true); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } private Position2D Multiply(Position2D rhs) { Position2D ret = new Position2D(Interop.Vector2.Multiply(swigCPtr, Position2D.getCPtr(rhs)), true); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } private Position2D Multiply(int rhs) { Position2D ret = new Position2D(Interop.Vector2.Multiply(swigCPtr, (float)rhs), true); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } private Position2D Divide(Position2D rhs) { Position2D ret = new Position2D(Interop.Vector2.Divide(swigCPtr, Position2D.getCPtr(rhs)), true); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } private Position2D Divide(int rhs) { Position2D ret = new Position2D(Interop.Vector2.Divide(swigCPtr, (float)rhs), true); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } private Position2D Subtract() { Position2D ret = new Position2D(Interop.Vector2.Subtract(swigCPtr), true); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } private int ValueOfIndex(uint index) { int ret = (int)Interop.Vector2.ValueOfIndex(swigCPtr, index); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } } }