[NUI] replace NUI.ISelectorItem with System.ICloneable (#1965)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Size.cs
index 85fe256..72a1014 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * 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.
  *
  */
 
-namespace NUI
-{
-  using System;
-
-  public class Size
-  {
-    private float width;
-    private float height;
-
-    /**
-     * @brief constructor
-     *
-     * @since 1.0.0
-     * @param [in] a Width value .
-     * @param [in] b Height value.
-     */
-    public Size(float a, float b)
-    {
-      width = a;
-      height = b;
-    }
-    /**
-     * @brief default constructor
-     *
-     * @since 1.0.0
-     */
-    public Size()
-    {
-      width = 0.0f;
-      height = 0.0f;
-    }
-
-    /**
-     * @brief constructor with base class object
-     *
-     * @since 1.0.0
-     * @param [in] o The Vector2 with Width, Height values.
-     */
-    public Size(Vector2 o)
-    {
-      width = o.X;
-      height = o.Y;
-    }
-
-    /**
-     * @brief Copy constructor
-     *
-     * @since 1.0.0
-     * @param [in] o The Size having Width & Y.
-     */
-    public Size(Size a)
-    {
-      width = a.width;
-      height = a.height;
-    }
-
-    ///< name "W", type float (Size Width value)
-    //@since 1.0.0
-    public float W
-    {
-      get { return width; }
-      set { width = value; }
-    }
-
-    ///< name "H", type float (Size Height value)
-    //@since 1.0.0
-    public float H
-    {
-      get { return height; }
-      set { height = value; }
-    }
-
-    public float Width
-    {
-      get { return width; }
-      set { width = value; }
-    }
-
-    public float Height
-    {
-      get { return height; }
-      set { height = value; }
-    }
-
-    /**
-     * @brief operator+
-     *
-     * @since 1.0.0
-     * @param [in] l The Size to add.
-     * @param [in] r The Size to add
-     * @return A reference to this
-     */
-    public static Size operator +(Size l, Size r)
-    {
-      return new Size(l.W + r.W, l.H + r.H);
-    }
-
-    /**
-     * @brief operator-
-     *
-     * @since 1.0.0
-     * @param [in] l The Size to substract.
-     * @param [in] r The Size to substract
-     * @return A reference to this
-     */
-    public static Size operator -(Size l, Size r)
-    {
-      return new Size(l.W - r.W, l.H - r.H);
-    }
-
-    /**
-     * @brief operator*
-     *
-     * @since 1.0.0
-     * @param [in] a The Size to multiply
-     * @param [in] b The constant to multiply of type double.
-     * @return A reference to this
-     */
-    public static Size operator *(Size a, double b)
-    {
-      return new Size((float)(a.W * b), (float)(a.H * b));
-    }
-
-    /**
-     * @brief operator/
-     *
-     * @since 1.0.0
-     * @param [in] a The Size to divide.
-     * @param [in] b The Size to divide
-     * @return float of the size division
-     */
-    public static float operator /(Size a, Size b)
-    {
-      return (float)System.Math.Sqrt((a.W / b.W) * (a.H / b.H));
-    }
-
-    /**
-     * @brief Operator ==
-     *
-     * @since 1.0.0
-     * @param [in] a The Size object to compare.
-     * @param [in] b The Size object to compare.
-     * @return bool, whether Size are equal or not
-     */
-    public static bool operator == (Size a, Size b)
-    {
-      return a.W == b.W && a.H == b.H ;
-    }
-
-    /**
-     * @brief Operator !=
-     *
-     * @since 1.0.0
-     * @param [in] a The Size object to compare.
-     * @param [in] b The Size object to compare.
-     * @return bool, whether Size are equal or not
-     */
-    public static bool operator != (Size a, Size b)
-    {
-      return a.W != b.W || a.H != b.H;
-    }
-
-    /**
-     * @brief GetHashCode
-     *
-     * @since 1.0.0
-     * @return int, hascode of Size
-     */
-    public override int GetHashCode()
-    {
-      return (int)(W + H);
-    }
-
-    /**
-     * @brief Clone
-     *
-     * @since 1.0.0
-     * @return returns a copy of Size object
-     */
-    public Size Clone()
-    {
-      Size copy = new Size(W, H);
-      return copy;
-    }
-
-    // User-defined conversion from Position to Vector2
-    public static implicit operator Vector2(Size size)
-    {
-      return new Vector2(size.width, size.height);
-    }
-
-    public static implicit operator Size(Vector2 vec)
-    {
-      return new Size(vec.X, vec.Y);
-    }
-  }
-
-  public class Size3D
-  {
-    private float width;
-    private float height;
-    private float depth;
-
-    public Size3D(float a, float b, float c)
-    {
-      width = a;
-      height = b;
-      depth = c;
-    }
-
-    public Size3D()
-    {
-      width = 0.0f;
-      height = 0.0f;
-      depth = 0.0f;
-    }
-
-    public Size3D(Vector3 o)
-    {
-      width = o.X;
-      height = o.Y;
-      depth = o.Z;
-    }
-
-    public Size3D(Vector2 o)
-    {
-      width = o.X;
-      height = o.Y;
-      depth = 0.0f;
-    }
-
-    public Size3D(Size3D a)
-    {
-      width = a.width;
-      height = a.height;
-      depth = a.depth;
-    }
-
-    public float W
-    {
-      get { return width; }
-      set { width = value; }
-    }
-
-    public float H
-    {
-      get { return height; }
-      set { height = value; }
-    }
-
-    public float D
-    {
-      get { return depth; }
-      set { depth = value; }
-    }
+using System;
+using System.ComponentModel;
+using Tizen.NUI.Binding;
 
-    public float Width
-    {
-      get { return width; }
-      set { width = value; }
-    }
-
-    public float Height
-    {
-      get { return height; }
-      set { height = value; }
-    }
-
-    public float Depth
-    {
-      get { return depth; }
-      set { depth = value; }
-    }
-
-    public float X
-    {
-      get { return width; }
-      set { width = value; }
-    }
-
-    public float Y
-    {
-      get { return height; }
-      set { height = value; }
-    }
-
-    public float Z
-    {
-      get { return depth; }
-      set { depth = value; }
-    }
-
-    // User-defined conversion from Position to Vector3
-    public static implicit operator Vector3(Size3D size)
-    {
-      return new Vector3(size.width, size.height, size.depth);
-    }
-
-    public static implicit operator Size3D(Vector3 vec)
-    {
-      return new Size3D(vec.X, vec.Y, vec.Z);
+namespace Tizen.NUI
+{
+    /// <summary>
+    /// A three-dimensional size.
+    /// </summary>
+    /// <since_tizen> 5 </since_tizen>
+    [Tizen.NUI.Binding.TypeConverter(typeof(SizeTypeConverter))]
+    public class Size : Disposable, ICloneable
+    {
+
+        /// <summary>
+        /// The constructor.
+        /// </summary>
+        /// <remarks>
+        /// Size2D and Size are implicitly converted to each other, so these are compatible and can be replaced without any type casting. <br />
+        /// For example, the followings are possible. <br />
+        /// view.Size2D = new Size(10.0f, 10.0f, 10.0f); // be aware that here the depth value(10.0f) will be lost. <br />
+        /// view.Size = new Size2D(10, 10); // be aware that here the depth value is 0.0f by default. <br />
+        /// view.MinimumSize = new Size(10, 10, 0); <br />
+        /// Size Tmp = view.MaximumSize; //here Tmp.Depth will be 0.0f. <br />
+        /// </remarks>
+        /// <since_tizen> 5 </since_tizen>
+        public Size() : this(Interop.Vector3.new_Vector3__SWIG_0(), true)
+        {
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        /// <summary>
+        /// The constructor.
+        /// </summary>
+        /// <param name="width">The width component.</param>
+        /// <param name="height">The height component.</param>
+        /// <param name="depth">The depth component(optional).</param>
+        /// <remarks>
+        /// Size2D and Size are implicitly converted to each other, so these are compatible and can be replaced without any type casting. <br />
+        /// For example, the followings are possible. <br />
+        /// view.Size2D = new Size(10.0f, 10.0f, 10.0f); // be aware that here the depth value(10.0f) will be lost. <br />
+        /// view.Size = new Size2D(10, 10); // be aware that here the depth value is 0.0f by default. <br />
+        /// view.MinimumSize = new Size(10, 10, 0); <br />
+        /// Size Tmp = view.MaximumSize; //here Tmp.Depth will be 0.0f. <br />
+        /// </remarks>
+        /// <since_tizen> 5 </since_tizen>
+        public Size(float width, float height, float depth = 0.0f) : this(Interop.Vector3.new_Vector3__SWIG_1(width, height, depth), true)
+        {
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        /// <summary>
+        /// The constructor.
+        /// </summary>
+        /// <param name="size2d">Size2D with width and height.</param>
+        /// <since_tizen> 5 </since_tizen>
+        public Size(Size2D size2d) : this(Interop.Vector3.new_Vector3__SWIG_3(Size2D.getCPtr(size2d)), true)
+        {
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        /// <summary>
+        /// The Zero constant, (0.0f, 0.0f, 0.0f).
+        /// </summary>
+        /// <since_tizen> 5 </since_tizen>
+        public static Size Zero
+        {
+            get
+            {
+                global::System.IntPtr cPtr = Interop.Vector3.Vector3_ZERO_get();
+                Size ret = (cPtr == global::System.IntPtr.Zero) ? null : new Size(cPtr, false);
+                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+                return ret;
+            }
+        }
+
+        /// <summary>
+        /// The Width property for the width component of size
+        /// </summary>
+        /// <since_tizen> 5 </since_tizen>
+        public float Width
+        {
+            set
+            {
+                Interop.Vector3.Vector3_Width_set(swigCPtr, value);
+                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+
+                callback?.Invoke(value, null, null);
+            }
+            get
+            {
+                float ret = Interop.Vector3.Vector3_Width_get(swigCPtr);
+                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+                return ret;
+            }
+        }
+
+        /// <summary>
+        /// The Height property for the height component of size.
+        /// </summary>
+        /// <since_tizen> 5 </since_tizen>
+        public float Height
+        {
+            set
+            {
+                Interop.Vector3.Vector3_Height_set(swigCPtr, value);
+                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+
+                callback?.Invoke(null, value, null);
+            }
+            get
+            {
+                float ret = Interop.Vector3.Vector3_Height_get(swigCPtr);
+                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+                return ret;
+            }
+        }
+
+        /// <summary>
+        /// The Depth property for the depth component of size.
+        /// </summary>
+        /// <since_tizen> 5 </since_tizen>
+        public float Depth
+        {
+            set
+            {
+                Interop.Vector3.Vector3_Depth_set(swigCPtr, value);
+                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+
+                callback?.Invoke(null, null, value);
+            }
+            get
+            {
+                float ret = Interop.Vector3.Vector3_Depth_get(swigCPtr);
+                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+                return ret;
+            }
+        }
+
+        /// <summary>
+        /// The addition operator for A+B.
+        /// </summary>
+        /// <param name="arg1">Size to assign A.</param>
+        /// <param name="arg2">Size to assign B.</param>
+        /// <returns>A size containing the result of the addition.</returns>
+        /// <since_tizen> 5 </since_tizen>
+        public static Size operator +(Size arg1, Size arg2)
+        {
+            return arg1.Add(arg2);
+        }
+
+        /// <summary>
+        /// The subtraction operator for A-B.
+        /// </summary>
+        /// <param name="arg1">Size to subtract A.</param>
+        /// <param name="arg2">Size to subtract B.</param>
+        /// <returns>The size containing the result of the subtraction.</returns>
+        /// <since_tizen> 5 </since_tizen>
+        public static Size operator -(Size arg1, Size arg2)
+        {
+            return arg1.Subtract(arg2);
+        }
+
+        /// <summary>
+        /// The unary negation operator.
+        /// </summary>
+        /// <param name="arg1">Size for unary negation.</param>
+        /// <returns>A size containing the negation.</returns>
+        /// <since_tizen> 5 </since_tizen>
+        public static Size operator -(Size arg1)
+        {
+            return arg1.Subtract();
+        }
+
+        /// <summary>
+        /// The multiplication operator.
+        /// </summary>
+        /// <param name="arg1">Size for multiplication.</param>
+        /// <param name="arg2">The size to multiply.</param>
+        /// <returns>A size containing the result of the multiplication.</returns>
+        /// <since_tizen> 5 </since_tizen>
+        public static Size operator *(Size arg1, Size arg2)
+        {
+            return arg1.Multiply(arg2);
+        }
+
+        /// <summary>
+        /// The multiplication operator.
+        /// </summary>
+        /// <param name="arg1">Size for multiplication.</param>
+        /// <param name="arg2">The float value to scale the size.</param>
+        /// <returns>A size containing the result of the scaling.</returns>
+        /// <since_tizen> 5 </since_tizen>
+        public static Size operator *(Size arg1, float arg2)
+        {
+            return arg1.Multiply(arg2);
+        }
+
+        /// <summary>
+        /// The division operator.
+        /// </summary>
+        /// <param name="arg1">Size for division.</param>
+        /// <param name="arg2">The size to divide.</param>
+        /// <returns>A size containing the result of the division.</returns>
+        /// <since_tizen> 5 </since_tizen>
+        public static Size operator /(Size arg1, Size arg2)
+        {
+            return arg1.Divide(arg2);
+        }
+
+        /// <summary>
+        /// The division operator.
+        /// </summary>
+        /// <param name="arg1">Size for division.</param>
+        /// <param name="arg2">The float value to scale the size by.</param>
+        /// <returns>A Size containing the result of the scaling.</returns>
+        /// <since_tizen> 5 </since_tizen>
+        public static Size operator /(Size arg1, float arg2)
+        {
+            return arg1.Divide(arg2);
+        }
+
+        /// <summary>
+        /// The array subscript operator.
+        /// </summary>
+        /// <param name="index">Subscript index.</param>
+        /// <returns>The float at the given index.</returns>
+        /// <since_tizen> 5 </since_tizen>
+        public float this[uint index]
+        {
+            get
+            {
+                return ValueOfIndex(index);
+            }
+        }
+
+        /// <summary>
+        /// Determines whether the specified object is equal to the current object.
+        /// </summary>
+        /// <param name="obj">The object to compare with the current object.</param>
+        /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
+        public override bool Equals(System.Object obj)
+        {
+            Size size = obj as Size;
+            bool equal = false;
+            if (Width == size?.Width && Height == size?.Height && Depth == size?.Depth)
+            {
+                equal = true;
+            }
+            return equal;
+        }
+
+        /// <summary>
+        /// Gets the the hash code of this Size.
+        /// </summary>
+        /// <returns>The Hash Code.</returns>
+        /// <since_tizen> 6 </since_tizen>
+        public override int GetHashCode()
+        {
+            return swigCPtr.Handle.GetHashCode();
+        }
+
+        /// <summary>
+        /// Checks equality.<br />
+        /// Utilizes appropriate machine epsilon values.<br />
+        /// </summary>
+        /// <param name="rhs">The size to test against.</param>
+        /// <returns>True if the sizes are equal.</returns>
+        /// <since_tizen> 5 </since_tizen>
+        public bool EqualTo(Size rhs)
+        {
+            bool ret = Interop.Vector3.Vector3_EqualTo(swigCPtr, Size.getCPtr(rhs));
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        /// <summary>
+        /// Checks inequality.<br />
+        /// Utilizes appropriate machine epsilon values.<br />
+        /// </summary>
+        /// <param name="rhs">The size to test against.</param>
+        /// <returns>True if the sizes are not equal.</returns>
+        /// <since_tizen> 5 </since_tizen>
+        public bool NotEqualTo(Size rhs)
+        {
+            bool ret = Interop.Vector3.Vector3_NotEqualTo(swigCPtr, Size.getCPtr(rhs));
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        /// <inheritdoc/>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public object Clone() => new Size(Width, Height, Depth);
+
+        /// <summary>
+        /// The type cast operator, Size to Vector3.
+        /// </summary>
+        /// <param name="size">The object of size type.</param>
+        /// <since_tizen> 5 </since_tizen>
+        public static implicit operator Vector3(Size size)
+        {
+            return new Vector3(size.Width, size.Height, size.Depth);
+        }
+
+        /// <summary>
+        /// The type cast operator, Vector3 to Size type.
+        /// </summary>
+        /// <param name="vec">The object of Vector3 type.</param>
+        /// <since_tizen> 5 </since_tizen>
+        public static implicit operator Size(Vector3 vec)
+        {
+            return new Size(vec.Width, vec.Height, vec.Depth);
+        }
+
+        /// <summary>
+        /// Implicit type cast operator, Size2D to Size
+        /// </summary>
+        /// <param name="size2d">The object of Size2D type.</param>
+        /// <since_tizen> none </since_tizen>
+        /// This will be public opened in tizen_next by ACR.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static implicit operator Size(Size2D size2d)
+        {
+            return new Size(size2d.Width, size2d.Height, 0);
+        }
+        
+
+        internal static Size GetSizeFromPtr(global::System.IntPtr cPtr)
+        {
+            Size ret = new Size(cPtr, false);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Size obj)
+        {
+            return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
+        }
+
+        internal Size(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
+        {
+        }
+
+        /// This will not be public opened.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
+        {
+            Interop.Vector3.delete_Vector3(swigCPtr);
+        }
+
+        private Size Add(Size rhs)
+        {
+            Size ret = new Size(Interop.Vector3.Vector3_Add(swigCPtr, Size.getCPtr(rhs)), true);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        private Size Subtract(Size rhs)
+        {
+            Size ret = new Size(Interop.Vector3.Vector3_Subtract__SWIG_0(swigCPtr, Size.getCPtr(rhs)), true);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        private Size Multiply(Size rhs)
+        {
+            Size ret = new Size(Interop.Vector3.Vector3_Multiply__SWIG_0(swigCPtr, Size.getCPtr(rhs)), true);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        private Size Multiply(float rhs)
+        {
+            Size ret = new Size(Interop.Vector3.Vector3_Multiply__SWIG_1(swigCPtr, rhs), true);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        private Size Divide(Size rhs)
+        {
+            Size ret = new Size(Interop.Vector3.Vector3_Divide__SWIG_0(swigCPtr, Size.getCPtr(rhs)), true);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        private Size Divide(float rhs)
+        {
+            Size ret = new Size(Interop.Vector3.Vector3_Divide__SWIG_1(swigCPtr, rhs), true);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        private Size Subtract()
+        {
+            Size ret = new Size(Interop.Vector3.Vector3_Subtract__SWIG_1(swigCPtr), true);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        private float ValueOfIndex(uint index)
+        {
+            float ret = Interop.Vector3.Vector3_ValueOfIndex__SWIG_0(swigCPtr, index);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        internal delegate void SizeChangedCallback(float? width, float? height, float? depth);
+
+        internal Size(SizeChangedCallback cb, float w, float h, float d) : this(Interop.Vector3.new_Vector3__SWIG_1(w, h, d), true)
+        {
+            callback = cb;
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        internal Size(SizeChangedCallback cb, Size other) : this(cb, other.Width, other.Height, other.Depth)
+        {
+        }
+
+        private SizeChangedCallback callback = null;
     }
-
-  }
-
 }
+