/*
* 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;
using System;
namespace Tizen.NUI
{
///
/// A two-dimensional size.
///
/// 3
[Tizen.NUI.Binding.TypeConverter(typeof(Size2DTypeConverter))]
public class Size2D : Disposable, ICloneable
{
private Size2DChangedCallback callback = null;
///
/// The constructor.
///
///
/// Size2D and Size 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.Size2D = new Size(10.0f, 10.0f, 10.0f); // be aware that here the depth value(10.0f) will be lost.
/// view.Size = new Size2D(10, 10); // be aware that here the depth value is 0.0f by default.
/// view.MinimumSize = new Size(10, 10, 0);
/// Size Tmp = view.MaximumSize; //here Tmp.Depth will be 0.0f.
///
/// 3
public Size2D() : this(Interop.Vector2.NewVector2(), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
///
/// The constructor.
///
/// The width component.
/// The height component.
///
/// Size2D and Size 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.Size2D = new Size(10.0f, 10.0f, 10.0f); // be aware that here the depth value(10.0f) will be lost.
/// view.Size = new Size2D(10, 10); // be aware that here the depth value is 0.0f by default.
/// view.MinimumSize = new Size(10, 10, 0);
/// Size Tmp = view.MaximumSize; //here Tmp.Depth will be 0.0f.
///
/// 3
public Size2D(int width, int height) : this(Interop.Vector2.NewVector2((float)width, (float)height), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
internal delegate void Size2DChangedCallback(int? width, int? height);
///
/// The property for the width component of a size.
///
///
/// The setter is deprecated in API8 and will be removed in API10. Please use new Size2D(...) constructor.
///
///
/// // 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);
///
/// 3
public int Width
{
set
{
Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Size2D(...) constructor");
Interop.Vector2.WidthSet(SwigCPtr, (float)value);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
callback?.Invoke(value, null);
}
get
{
float ret = Interop.Vector2.WidthGet(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
return (int)ret;
}
}
///
/// The property for the height component of a size.
///
///
/// The setter is deprecated in API8 and will be removed in API10. Please use new Size2D(...) constructor.
///
///
/// // 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);
///
/// 3
public int Height
{
set
{
Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Size2D(...) constructor");
Interop.Vector2.HeightSet(SwigCPtr, (float)value);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
callback?.Invoke(null, value);
}
get
{
float ret = Interop.Vector2.HeightGet(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
return (int)ret;
}
}
///
/// The addition operator for A+B.
///
/// Size A.
/// Size to assign B.
/// A size containing the result of the addition.
/// 3
public static Size2D operator +(Size2D arg1, Size2D arg2)
{
return arg1?.Add(arg2);
}
///
/// The subtraction operator for A-B.
///
/// Size A.
/// Size to subtract B.
/// A size containing the result of the subtraction.
/// 3
public static Size2D operator -(Size2D arg1, Size2D arg2)
{
return arg1?.Subtract(arg2);
}
///
/// The unary negation operator.
///
/// Size for unary negation.
/// A size containing the negation.
/// 3
public static Size2D operator -(Size2D arg1)
{
return arg1?.Subtract();
}
///
/// The multiplication operator.
///
/// Size for multiplication.
/// Size to multiply.
/// A size containing the result of the multiplication.
/// 3
public static Size2D operator *(Size2D arg1, Size2D arg2)
{
return arg1?.Multiply(arg2);
}
///
/// The multiplication operator.
///
/// Size for multiplication
/// The integer value to scale the size.
/// A size containing the result of the scaling.
/// 3
public static Size2D operator *(Size2D arg1, int arg2)
{
return arg1?.Multiply(arg2);
}
///
/// The division operator.
///
/// Size for division.
/// Size to divide.
/// A size containing the result of the division.
/// 3
public static Size2D operator /(Size2D arg1, Size2D arg2)
{
return arg1?.Divide(arg2);
}
///
/// The division operator.
///
/// Size for division.
/// The integer value to scale the size by.
/// A size containing the result of the scaling.
/// 3
public static Size2D operator /(Size2D arg1, int arg2)
{
return arg1?.Divide(arg2);
}
///
/// The type cast operator, Size2D to Vector2.
///
/// An object of the Size2D type.
/// return a Vector2 instance
/// 3
public static implicit operator Vector2(Size2D size)
{
return new Vector2((float)size?.Width, (float)size.Height);
}
///
/// The type cast operator, Vector2 to Size2D type.
///
/// An object of the Vector2 type.
/// return a Size2D instance
/// 3
public static implicit operator Size2D(Vector2 vector2)
{
return new Size2D((int)vector2?.X, (int)vector2.Y);
}
///
/// Implicit type cast operator, Size to Size2D
///
/// The object of Size type.
/// none
/// 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);
}
///
/// The array subscript operator.
///
/// The subscript index.
/// The float at the given index.
/// 3
public float this[uint index]
{
get
{
return ValueOfIndex(index);
}
}
///
/// 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)
{
Size2D size2D = obj as Size2D;
bool equal = false;
if (Width == size2D?.Width && Height == size2D?.Height)
{
equal = true;
}
return equal;
}
///
/// Gets the the hash code of this Size2D.
///
/// The Hash Code.
/// 6
public override int GetHashCode()
{
return SwigCPtr.Handle.GetHashCode();
}
///
/// Checks equality.
/// Utilizes appropriate machine epsilon values.
///
/// The size to test against.
/// True if the sizes are equal.
/// 3
public bool EqualTo(Size2D rhs)
{
bool ret = Interop.Vector2.EqualTo(SwigCPtr, Size2D.getCPtr(rhs));
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
///
/// Checks inequality.
/// Utilizes appropriate machine epsilon values.
///
/// The size to test against.
/// True if the sizes are not equal.
/// 3
public bool NotEqualTo(Size2D rhs)
{
bool ret = Interop.Vector2.NotEqualTo(SwigCPtr, Size2D.getCPtr(rhs));
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
///
[EditorBrowsable(EditorBrowsableState.Never)]
public object Clone() => new Size2D(Width, Height);
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Size2D obj)
{
return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
}
///
/// Gets the size from the pointer.
///
/// The pointer of the size.
/// Size
internal static Size2D GetSize2DFromPtr(global::System.IntPtr cPtr)
{
Size2D ret = new Size2D(cPtr, false);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal Size2D(Size2DChangedCallback 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 Size2D(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.Vector2.DeleteVector2(swigCPtr);
}
private Size2D Add(Size2D rhs)
{
Size2D ret = new Size2D(Interop.Vector2.Add(SwigCPtr, Size2D.getCPtr(rhs)), true);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
private Size2D Subtract(Size2D rhs)
{
Size2D ret = new Size2D(Interop.Vector2.Subtract(SwigCPtr, Size2D.getCPtr(rhs)), true);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
private Size2D Multiply(Size2D rhs)
{
Size2D ret = new Size2D(Interop.Vector2.Multiply(SwigCPtr, Size2D.getCPtr(rhs)), true);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
private Size2D Multiply(int rhs)
{
Size2D ret = new Size2D(Interop.Vector2.Multiply(SwigCPtr, (float)rhs), true);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
private Size2D Divide(Size2D rhs)
{
Size2D ret = new Size2D(Interop.Vector2.Divide(SwigCPtr, Size2D.getCPtr(rhs)), true);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
private Size2D Divide(int rhs)
{
Size2D ret = new Size2D(Interop.Vector2.Divide(SwigCPtr, (float)rhs), true);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
private Size2D Subtract()
{
Size2D ret = new Size2D(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;
}
}
}