/*
* Copyright (c) 2021 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
{
///
/// A three-dimensional size.
///
/// 5
[Tizen.NUI.Binding.TypeConverter(typeof(SizeTypeConverter))]
public class Size : Disposable, ICloneable
{
///
/// 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.
///
/// 5
public Size() : this(Interop.Vector3.NewVector3(), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
///
/// The constructor.
///
/// The width component.
/// The height component.
/// The depth component(optional).
///
/// 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.
///
/// 5
public Size(float width, float height, float depth = 0.0f) : this(Interop.Vector3.NewVector3(width, height, depth), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
///
/// The constructor.
///
/// Size2D with width and height.
/// 5
public Size(Size2D size2d) : this(Interop.Vector3.NewVector3WithVector2(Size2D.getCPtr(size2d)), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
///
/// The Zero constant, (0.0f, 0.0f, 0.0f).
///
/// 5
public static Size Zero
{
get
{
global::System.IntPtr cPtr = Interop.Vector3.ZeroGet();
Size ret = (cPtr == global::System.IntPtr.Zero) ? null : new Size(cPtr, false);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
return ret;
}
}
///
/// The Width property for the width component of size
///
///
/// The setter is deprecated in API8 and will be removed in API10. Use new Size(...) constructor.
///
///
/// // DO NOT use like the followings!
/// Size size = new Size();
/// size.Width = 0.1f;
/// // USE like this
/// float width = 0.1f, height = 0.5f, depth = 0.9f;
/// Size size = new Size(width, height, depth);
///
/// 5
public float Width
{
[Obsolete("Do not use this setter, that is deprecated in API8 and will be removed in API10. Use new Size(...) constructor")]
set
{
Interop.Vector3.WidthSet(SwigCPtr, value);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
callback?.Invoke(value, null, null);
}
get
{
float ret = Interop.Vector3.WidthGet(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
return ret;
}
}
///
/// The Height property for the height component of size.
///
///
/// The setter is deprecated in API8 and will be removed in API10. Use new Size(...) constructor.
///
///
/// // DO NOT use like the followings!
/// Size size = new Size();
/// size.Height = 0.5f;
/// // USE like this
/// float width = 0.1f, height = 0.5f, depth = 0.9f;
/// Size size = new Size(width, height, depth);
///
/// 5
public float Height
{
[Obsolete("Do not use this setter, that is deprecated in API8 and will be removed in API10. Use new Size(...) constructor")]
set
{
Interop.Vector3.HeightSet(SwigCPtr, value);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
callback?.Invoke(null, value, null);
}
get
{
float ret = Interop.Vector3.HeightGet(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
return ret;
}
}
///
/// The Depth property for the depth component of size.
///
///
/// The setter is deprecated in API8 and will be removed in API10. Use new Size(...) constructor.
///
///
/// // DO NOT use like the followings!
/// Size size = new Size();
/// size.Depth = 0.9f;
/// // USE like this
/// float width = 0.1f, height = 0.5f, depth = 0.9f;
/// Size size = new Size(width, height, depth);
///
/// 5
public float Depth
{
[Obsolete("Do not use this setter, that is deprecated in API8 and will be removed in API10. Use new Size(...) constructor")]
set
{
Interop.Vector3.DepthSet(SwigCPtr, value);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
callback?.Invoke(null, null, value);
}
get
{
float ret = Interop.Vector3.DepthGet(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
return ret;
}
}
///
/// The addition operator for A+B.
///
/// Size to assign A.
/// Size to assign B.
/// A size containing the result of the addition.
/// 5
public static Size operator +(Size arg1, Size arg2)
{
return arg1?.Add(arg2);
}
///
/// The subtraction operator for A-B.
///
/// Size to subtract A.
/// Size to subtract B.
/// The size containing the result of the subtraction.
/// 5
public static Size operator -(Size arg1, Size arg2)
{
return arg1?.Subtract(arg2);
}
///
/// The unary negation operator.
///
/// Size for unary negation.
/// A size containing the negation.
/// 5
public static Size operator -(Size arg1)
{
return arg1?.Subtract();
}
///
/// The multiplication operator.
///
/// Size for multiplication.
/// The size to multiply.
/// A size containing the result of the multiplication.
/// 5
public static Size operator *(Size arg1, Size arg2)
{
return arg1?.Multiply(arg2);
}
///
/// The multiplication operator.
///
/// Size for multiplication.
/// The float value to scale the size.
/// A size containing the result of the scaling.
/// 5
public static Size operator *(Size arg1, float arg2)
{
return arg1?.Multiply(arg2);
}
///
/// The division operator.
///
/// Size for division.
/// The size to divide.
/// A size containing the result of the division.
/// 5
public static Size operator /(Size arg1, Size arg2)
{
return arg1?.Divide(arg2);
}
///
/// The division operator.
///
/// Size for division.
/// The float value to scale the size by.
/// A Size containing the result of the scaling.
/// 5
public static Size operator /(Size arg1, float arg2)
{
return arg1?.Divide(arg2);
}
///
/// The array subscript operator.
///
/// Subscript index.
/// The float at the given index.
/// 5
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)
{
Size size = obj as Size;
bool equal = false;
if (Width == size?.Width && Height == size?.Height && Depth == size?.Depth)
{
equal = true;
}
return equal;
}
///
/// Gets the hash code of this Size.
///
/// 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.
/// 5
public bool EqualTo(Size rhs)
{
bool ret = Interop.Vector3.EqualTo(SwigCPtr, Size.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.
/// 5
public bool NotEqualTo(Size rhs)
{
bool ret = Interop.Vector3.NotEqualTo(SwigCPtr, Size.getCPtr(rhs));
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
///
[EditorBrowsable(EditorBrowsableState.Never)]
public object Clone() => new Size(Width, Height, Depth);
///
/// The type cast operator, Size to Vector3.
///
/// The object of size type.
/// 5
public static implicit operator Vector3(Size size)
{
if (size == null)
{
return null;
}
return new Vector3(size.Width, size.Height, size.Depth);
}
///
/// The type cast operator, Vector3 to Size type.
///
/// The object of Vector3 type.
/// 5
public static implicit operator Size(Vector3 vec)
{
if (vec == null)
{
return null;
}
return new Size(vec.Width, vec.Height, vec.Depth);
}
///
/// Implicit type cast operator, Size2D to Size
///
/// The object of Size2D type.
/// none
/// This will be public opened in tizen_next by ACR.
[EditorBrowsable(EditorBrowsableState.Never)]
public static implicit operator Size(Size2D size2d)
{
if (size2d == null)
{
return null;
}
return new Size(size2d.Width, size2d.Height);
}
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 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.DeleteVector3(swigCPtr);
}
private Size Add(Size rhs)
{
Size ret = new Size(Interop.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.Subtract(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.Multiply(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.Multiply(SwigCPtr, rhs), true);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
private Size Divide(Size rhs)
{
Size ret = new Size(Interop.Vector3.Divide(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.Divide(SwigCPtr, rhs), true);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
private Size Subtract()
{
Size ret = new Size(Interop.Vector3.Subtract(SwigCPtr), true);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
private float ValueOfIndex(uint index)
{
float ret = Interop.Vector3.ValueOfIndex(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.NewVector3(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;
}
}