/*
- * Copyright (c) 2017 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.
* limitations under the License.
*
*/
+using System;
+using System.ComponentModel;
+using Tizen.NUI.Binding;
+using System;
namespace Tizen.NUI
{
-
/// <summary>
/// A two-dimensional size.
/// </summary>
- public class Size2D : global::System.IDisposable
+ /// <since_tizen> 3 </since_tizen>
+ [Tizen.NUI.Binding.TypeConverter(typeof(Size2DTypeConverter))]
+ public class Size2D : Disposable, ICloneable
{
- private global::System.Runtime.InteropServices.HandleRef swigCPtr;
- protected bool swigCMemOwn;
- internal Size2D(global::System.IntPtr cPtr, bool cMemoryOwn)
- {
- swigCMemOwn = cMemoryOwn;
- swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
- }
+ private Size2DChangedCallback callback = null;
- internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Size2D obj)
+ /// <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> 3 </since_tizen>
+ public Size2D() : this(Interop.Vector2.NewVector2(), true)
{
- return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
- //A Flag to check who called Dispose(). (By User or DisposeQueue)
- private bool isDisposeQueued = false;
- //A Flat to check if it is already disposed.
- protected bool disposed = false;
-
- ~Size2D()
+ /// <summary>
+ /// The constructor.
+ /// </summary>
+ /// <param name="width">The width component.</param>
+ /// <param name="height">The height component.</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> 3 </since_tizen>
+ public Size2D(int width, int height) : this(Interop.Vector2.NewVector2((float)width, (float)height), true)
{
- if(!isDisposeQueued)
- {
- isDisposeQueued = true;
- DisposeQueue.Instance.Add(this);
- }
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
+ internal delegate void Size2DChangedCallback(int? width, int? height);
+
/// <summary>
- /// Dispose.
+ /// The property for the width component of a size.
/// </summary>
+ /// <remarks>
+ /// The setter is deprecated in API8 and will be removed in API10. Please use new Size2D(...) constructor.
+ /// </remarks>
+ /// <code>
+ /// // DO NOT use like the followings!
+ /// Size2D size2d = new Size2D();
+ /// size2d.Width = 1;
+ /// // Please USE like this
+ /// int width = 1, height = 2;
+ /// Size2D size2d = new Size2D(width, height);
+ /// </code>
/// <since_tizen> 3 </since_tizen>
- public void Dispose()
+ public int Width
{
- //Throw excpetion if Dispose() is called in separate thread.
- if (!Window.IsInstalled())
+ set
{
- throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
- }
+ Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Size2D(...) constructor");
- if (isDisposeQueued)
- {
- Dispose(DisposeTypes.Implicit);
+ Interop.Vector2.WidthSet(swigCPtr, (float)value);
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+
+ callback?.Invoke(value, null);
}
- else
+ get
{
- Dispose(DisposeTypes.Explicit);
- System.GC.SuppressFinalize(this);
+ float ret = Interop.Vector2.WidthGet(swigCPtr);
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ return (int)ret;
}
}
- protected virtual void Dispose(DisposeTypes type)
+ /// <summary>
+ /// The property for the height component of a size.
+ /// </summary>
+ /// <remarks>
+ /// The setter is deprecated in API8 and will be removed in API10. Please use new Size2D(...) constructor.
+ /// </remarks>
+ /// <code>
+ /// // DO NOT use like the followings!
+ /// Size2D size2d = new Size2D();
+ /// size2d.Height = 2;
+ /// // Please USE like this
+ /// int width = 1, height = 2;
+ /// Size2D size2d = new Size2D(width, height);
+ /// </code>
+ /// <since_tizen> 3 </since_tizen>
+ public int Height
{
- if (disposed)
- {
- return;
- }
-
- if(type == DisposeTypes.Explicit)
+ set
{
- //Called by User
- //Release your own managed resources here.
- //You should release all of your own disposable objects here.
- }
+ Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Size2D(...) constructor");
- //Release your own unmanaged resources here.
- //You should not access any managed member here except static instance.
- //because the execution order of Finalizes is non-deterministic.
+ Interop.Vector2.HeightSet(swigCPtr, (float)value);
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
- if (swigCPtr.Handle != global::System.IntPtr.Zero)
+ callback?.Invoke(null, value);
+ }
+ get
{
- if (swigCMemOwn)
- {
- swigCMemOwn = false;
- NDalicPINVOKE.delete_Vector2(swigCPtr);
- }
- swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+ float ret = Interop.Vector2.HeightGet(swigCPtr);
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ return (int)ret;
}
- disposed = true;
}
/// <summary>
/// <since_tizen> 3 </since_tizen>
public static Size2D operator +(Size2D arg1, Size2D arg2)
{
- return arg1.Add(arg2);
+ return arg1?.Add(arg2);
}
/// <summary>
/// <since_tizen> 3 </since_tizen>
public static Size2D operator -(Size2D arg1, Size2D arg2)
{
- return arg1.Subtract(arg2);
+ return arg1?.Subtract(arg2);
}
/// <summary>
/// <since_tizen> 3 </since_tizen>
public static Size2D operator -(Size2D arg1)
{
- return arg1.Subtract();
+ return arg1?.Subtract();
}
/// <summary>
/// <since_tizen> 3 </since_tizen>
public static Size2D operator *(Size2D arg1, Size2D arg2)
{
- return arg1.Multiply(arg2);
+ return arg1?.Multiply(arg2);
}
/// <summary>
/// <since_tizen> 3 </since_tizen>
public static Size2D operator *(Size2D arg1, int arg2)
{
- return arg1.Multiply(arg2);
+ return arg1?.Multiply(arg2);
}
/// <summary>
/// <since_tizen> 3 </since_tizen>
public static Size2D operator /(Size2D arg1, Size2D arg2)
{
- return arg1.Divide(arg2);
+ return arg1?.Divide(arg2);
}
/// <summary>
/// <since_tizen> 3 </since_tizen>
public static Size2D operator /(Size2D arg1, int arg2)
{
- return arg1.Divide(arg2);
+ return arg1?.Divide(arg2);
+ }
+
+ /// <summary>
+ /// The type cast operator, Size2D to Vector2.
+ /// </summary>
+ /// <param name="size">An object of the Size2D type.</param>
+ /// <returns>return a Vector2 instance</returns>
+ /// <since_tizen> 3 </since_tizen>
+ public static implicit operator Vector2(Size2D size)
+ {
+ return new Vector2((float)size?.Width, (float)size.Height);
}
/// <summary>
+ /// The type cast operator, Vector2 to Size2D type.
+ /// </summary>
+ /// <param name="vector2">An object of the Vector2 type.</param>
+ /// <returns>return a Size2D instance</returns>
+ /// <since_tizen> 3 </since_tizen>
+ public static implicit operator Size2D(Vector2 vector2)
+ {
+ return new Size2D((int)vector2?.X, (int)vector2.Y);
+ }
+
+ /// <summary>
+ /// Implicit type cast operator, Size to Size2D
+ /// </summary>
+ /// <param name="size">The object of Size type.</param>
+ /// <since_tizen> none </since_tizen>
+ /// This will be public opened in tizen_next by ACR.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static implicit operator Size2D(Size size)
+ {
+ return new Size2D((int)size?.Width, (int)size.Height);
+ }
+
+
+ /// <summary>
/// The array subscript operator.
/// </summary>
/// <param name="index">The subscript index.</param>
}
/// <summary>
- /// Gets the size from the pointer.
+ /// Determines whether the specified object is equal to the current object.
/// </summary>
- /// <param name="cPtr">The pointer of the size.</param>
- /// <returns>Size</returns>
- internal static Size2D GetSize2DFromPtr(global::System.IntPtr cPtr)
+ /// <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)
{
- Size2D ret = new Size2D(cPtr, false);
- if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
- return ret;
+ Size2D size2D = obj as Size2D;
+ bool equal = false;
+ if (Width == size2D?.Width && Height == size2D?.Height)
+ {
+ equal = true;
+ }
+ return equal;
}
/// <summary>
- /// The constructor.
+ /// Gets the the hash code of this Size2D.
/// </summary>
- /// <since_tizen> 3 </since_tizen>
- public Size2D() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
+ /// <returns>The Hash Code.</returns>
+ /// <since_tizen> 6 </since_tizen>
+ public override int GetHashCode()
{
- if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ return swigCPtr.Handle.GetHashCode();
}
/// <summary>
- /// The constructor.
+ /// Checks equality.<br />
+ /// Utilizes appropriate machine epsilon values.<br />
/// </summary>
- /// <param name="x">The x (or width) component.</param>
- /// <param name="y">The y (or height) component.</param>
+ /// <param name="rhs">The size to test against.</param>
+ /// <returns>True if the sizes are equal.</returns>
/// <since_tizen> 3 </since_tizen>
- public Size2D(int x, int y) : this(NDalicPINVOKE.new_Vector2__SWIG_1((float)x, (float)y), true)
- {
- if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
- }
-
- private Size2D Add(Size2D rhs)
+ public bool EqualTo(Size2D rhs)
{
- Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Add(swigCPtr, Size2D.getCPtr(rhs)), true);
+ bool ret = Interop.Vector2.EqualTo(swigCPtr, Size2D.getCPtr(rhs));
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
- private Size2D Subtract(Size2D rhs)
+ /// <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> 3 </since_tizen>
+ public bool NotEqualTo(Size2D rhs)
{
- Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
+ bool ret = Interop.Vector2.NotEqualTo(swigCPtr, Size2D.getCPtr(rhs));
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
+ /// <inheritdoc/>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public object Clone() => new Size2D(Width, Height);
- private Size2D Multiply(Size2D rhs)
+ internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Size2D obj)
{
- Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
- if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
- return ret;
+ return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
}
- private Size2D Multiply(int rhs)
+ /// <summary>
+ /// Gets the size from the pointer.
+ /// </summary>
+ /// <param name="cPtr">The pointer of the size.</param>
+ /// <returns>Size</returns>
+ internal static Size2D GetSize2DFromPtr(global::System.IntPtr cPtr)
{
- Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, (float)rhs), true);
+ Size2D ret = new Size2D(cPtr, false);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
-
- private Size2D Divide(Size2D rhs)
+ internal Size2D(Size2DChangedCallback cb, int x, int y) : this(Interop.Vector2.NewVector2((float)x, (float)y), true)
{
- Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
+ callback = cb;
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
- return ret;
}
- private Size2D Divide(int rhs)
+ internal Size2D(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
{
- Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, (float)rhs), true);
- if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
- return ret;
}
- private Size2D Subtract()
+ /// This will not be public opened.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
{
- Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Subtract__SWIG_1(swigCPtr), true);
- if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
- return ret;
+ Interop.Vector2.DeleteVector2(swigCPtr);
}
- /// <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> 3 </since_tizen>
- public bool EqualTo(Size2D rhs)
+ private Size2D Add(Size2D rhs)
{
- bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, Size2D.getCPtr(rhs));
+ Size2D ret = new Size2D(Interop.Vector2.Add(swigCPtr, Size2D.getCPtr(rhs)), true);
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> 3 </since_tizen>
- public bool NotEqualTo(Size2D rhs)
+ private Size2D Subtract(Size2D rhs)
{
- bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, Size2D.getCPtr(rhs));
+ Size2D ret = new Size2D(Interop.Vector2.Subtract(swigCPtr, Size2D.getCPtr(rhs)), true);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
- private int ValueOfIndex(uint index)
+ private Size2D Multiply(Size2D rhs)
{
- int ret = (int)NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
+ Size2D ret = new Size2D(Interop.Vector2.Multiply(swigCPtr, Size2D.getCPtr(rhs)), true);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
- /// <summary>
- /// The property for the width component of a size.
- /// </summary>
- /// <since_tizen> 3 </since_tizen>
- public int Width
- {
- set
- {
- NDalicPINVOKE.Vector2_Width_set(swigCPtr, (float)value);
- if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
- }
- get
- {
- float ret = NDalicPINVOKE.Vector2_Width_get(swigCPtr);
- if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
- return (int)ret;
- }
- }
-
- /// <summary>
- /// The property for the height component of a size.
- /// </summary>
- /// <since_tizen> 3 </since_tizen>
- public int Height
+ private Size2D Multiply(int rhs)
{
- set
- {
- NDalicPINVOKE.Vector2_Height_set(swigCPtr, (float)value);
- if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
- }
- get
- {
- float ret = NDalicPINVOKE.Vector2_Height_get(swigCPtr);
- if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
- return (int)ret;
- }
+ Size2D ret = new Size2D(Interop.Vector2.Multiply(swigCPtr, (float)rhs), true);
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ return ret;
}
- /// <summary>
- /// The type cast operator, Size2D to Vector2.
- /// </summary>
- /// <param name="size">An object of the Size2D type.</param>
- /// <since_tizen> 3 </since_tizen>
- public static implicit operator Vector2(Size2D size)
+ private Size2D Divide(Size2D rhs)
{
- return new Vector2((float)size.Width, (float)size.Height);
+ Size2D ret = new Size2D(Interop.Vector2.Divide(swigCPtr, Size2D.getCPtr(rhs)), true);
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ return ret;
}
- /// <summary>
- /// The type cast operator, Vector2 to Size2D type.
- /// </summary>
- /// <param name="vec">An object of the Vector2 type.</param>
- /// <since_tizen> 3 </since_tizen>
- public static implicit operator Size2D(Vector2 vec)
+ private Size2D Divide(int rhs)
{
- return new Size2D((int)vec.X, (int)vec.Y);
+ Size2D ret = new Size2D(Interop.Vector2.Divide(swigCPtr, (float)rhs), true);
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ return ret;
}
- /// <summary>
- /// The type cast operator, Size2D to Uint16Pair.
- /// </summary>
- /// <param name="size2d">An object of the Size2D type.</param>
- /// <since_tizen> 4 </since_tizen>
- public static implicit operator Uint16Pair(Size2D size2d)
+ private Size2D Subtract()
{
- return new Uint16Pair((uint)size2d.Width, (uint)size2d.Height);
+ Size2D ret = new Size2D(Interop.Vector2.Subtract(swigCPtr), true);
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ return ret;
}
- /// <summary>
- /// The type cast operator, Uint16Pair to Size2D type.
- /// </summary>
- /// <param name="pair">An object of the Vector2 type.</param>
- /// <since_tizen> 4 </since_tizen>
- public static implicit operator Size2D(Uint16Pair pair)
+ private int ValueOfIndex(uint index)
{
- return new Size2D((int)pair.GetWidth(), (int)pair.GetWidth());
+ int ret = (int)Interop.Vector2.ValueOfIndex(swigCPtr, index);
+ if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ return ret;
}
-
-
}
-
}