2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 using System.ComponentModel;
18 using Tizen.NUI.Binding;
19 using System.ComponentModel;
24 /// A two-dimensional size.
26 /// <since_tizen> 3 </since_tizen>
27 [Tizen.NUI.Binding.TypeConverter(typeof(Size2DTypeConverter))]
28 public class Size2D : Disposable
31 private Size2DChangedCallback callback = null;
37 /// Size2D and Size are implicitly converted to each other, so these are compatible and can be replaced without any type casting. <br />
38 /// For example, the followings are possible. <br />
39 /// view.Size2D = new Size(10.0f, 10.0f, 10.0f); // be aware that here the depth value(10.0f) will be lost. <br />
40 /// view.Size = new Size2D(10, 10); // be aware that here the depth value is 0.0f by default. <br />
41 /// view.MinimumSize = new Size(10, 10, 0); <br />
42 /// Size Tmp = view.MaximumSize; //here Tmp.Depth will be 0.0f. <br />
44 /// <since_tizen> 3 </since_tizen>
45 public Size2D() : this(Interop.Vector2.new_Vector2__SWIG_0(), true)
47 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
53 /// <param name="width">The width component.</param>
54 /// <param name="height">The height component.</param>
56 /// Size2D and Size are implicitly converted to each other, so these are compatible and can be replaced without any type casting. <br />
57 /// For example, the followings are possible. <br />
58 /// view.Size2D = new Size(10.0f, 10.0f, 10.0f); // be aware that here the depth value(10.0f) will be lost. <br />
59 /// view.Size = new Size2D(10, 10); // be aware that here the depth value is 0.0f by default. <br />
60 /// view.MinimumSize = new Size(10, 10, 0); <br />
61 /// Size Tmp = view.MaximumSize; //here Tmp.Depth will be 0.0f. <br />
63 /// <since_tizen> 3 </since_tizen>
64 public Size2D(int width, int height) : this(Interop.Vector2.new_Vector2__SWIG_1((float)width, (float)height), true)
66 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
69 internal delegate void Size2DChangedCallback(int? width, int? height);
72 /// The property for the width component of a size.
74 /// <since_tizen> 3 </since_tizen>
79 Interop.Vector2.Vector2_Width_set(swigCPtr, (float)value);
80 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
82 callback?.Invoke(value, null);
86 float ret = Interop.Vector2.Vector2_Width_get(swigCPtr);
87 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
93 /// The property for the height component of a size.
95 /// <since_tizen> 3 </since_tizen>
100 Interop.Vector2.Vector2_Height_set(swigCPtr, (float)value);
101 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
103 callback?.Invoke(null, value);
107 float ret = Interop.Vector2.Vector2_Height_get(swigCPtr);
108 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
114 /// The addition operator for A+B.
116 /// <param name="arg1">Size A.</param>
117 /// <param name="arg2">Size to assign B.</param>
118 /// <returns>A size containing the result of the addition.</returns>
119 /// <since_tizen> 3 </since_tizen>
120 public static Size2D operator +(Size2D arg1, Size2D arg2)
122 return arg1.Add(arg2);
126 /// The subtraction operator for A-B.
128 /// <param name="arg1">Size A.</param>
129 /// <param name="arg2">Size to subtract B.</param>
130 /// <returns>A size containing the result of the subtraction.</returns>
131 /// <since_tizen> 3 </since_tizen>
132 public static Size2D operator -(Size2D arg1, Size2D arg2)
134 return arg1.Subtract(arg2);
138 /// The unary negation operator.
140 /// <param name="arg1">Size for unary negation.</param>
141 /// <returns>A size containing the negation.</returns>
142 /// <since_tizen> 3 </since_tizen>
143 public static Size2D operator -(Size2D arg1)
145 return arg1.Subtract();
149 /// The multiplication operator.
151 /// <param name="arg1">Size for multiplication.</param>
152 /// <param name="arg2">Size to multiply.</param>
153 /// <returns>A size containing the result of the multiplication.</returns>
154 /// <since_tizen> 3 </since_tizen>
155 public static Size2D operator *(Size2D arg1, Size2D arg2)
157 return arg1.Multiply(arg2);
161 /// The multiplication operator.
163 /// <param name="arg1">Size for multiplication</param>
164 /// <param name="arg2">The integer value to scale the size.</param>
165 /// <returns>A size containing the result of the scaling.</returns>
167 /// <since_tizen> 3 </since_tizen>
168 public static Size2D operator *(Size2D arg1, int arg2)
170 return arg1.Multiply(arg2);
174 /// The division operator.
176 /// <param name="arg1">Size for division.</param>
177 /// <param name="arg2">Size to divide.</param>
178 /// <returns>A size containing the result of the division.</returns>
179 /// <since_tizen> 3 </since_tizen>
180 public static Size2D operator /(Size2D arg1, Size2D arg2)
182 return arg1.Divide(arg2);
186 /// The division operator.
188 /// <param name="arg1">Size for division.</param>
189 /// <param name="arg2">The integer value to scale the size by.</param>
190 /// <returns>A size containing the result of the scaling.</returns>
191 /// <since_tizen> 3 </since_tizen>
192 public static Size2D operator /(Size2D arg1, int arg2)
194 return arg1.Divide(arg2);
198 /// The type cast operator, Size2D to Vector2.
200 /// <param name="size">An object of the Size2D type.</param>
201 /// <returns>return a Vector2 instance</returns>
202 /// <since_tizen> 3 </since_tizen>
203 public static implicit operator Vector2(Size2D size)
205 return new Vector2((float)size.Width, (float)size.Height);
209 /// The type cast operator, Vector2 to Size2D type.
211 /// <param name="vector2">An object of the Vector2 type.</param>
212 /// <returns>return a Size2D instance</returns>
213 /// <since_tizen> 3 </since_tizen>
214 public static implicit operator Size2D(Vector2 vector2)
216 return new Size2D((int)vector2.X, (int)vector2.Y);
220 /// Implicit type cast operator, Size to Size2D
222 /// <param name="size">The object of Size type.</param>
223 /// <since_tizen> none </since_tizen>
224 /// This will be public opened in tizen_next by ACR.
225 [EditorBrowsable(EditorBrowsableState.Never)]
226 public static implicit operator Size2D(Size size)
228 return new Size2D((int)size.Width, (int)size.Height);
233 /// The array subscript operator.
235 /// <param name="index">The subscript index.</param>
236 /// <returns>The float at the given index.</returns>
237 /// <since_tizen> 3 </since_tizen>
238 public float this[uint index]
242 return ValueOfIndex(index);
247 /// Determines whether the specified object is equal to the current object.
249 /// <param name="obj">The object to compare with the current object.</param>
250 /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
251 public override bool Equals(System.Object obj)
253 Size2D size2D = obj as Size2D;
255 if (Width == size2D?.Width && Height == size2D?.Height)
263 /// Gets the the hash code of this Size2D.
265 /// <returns>The Hash Code.</returns>
266 /// <since_tizen> 6 </since_tizen>
267 public override int GetHashCode()
269 return swigCPtr.Handle.GetHashCode();
273 /// Checks equality.<br />
274 /// Utilizes appropriate machine epsilon values.<br />
276 /// <param name="rhs">The size to test against.</param>
277 /// <returns>True if the sizes are equal.</returns>
278 /// <since_tizen> 3 </since_tizen>
279 public bool EqualTo(Size2D rhs)
281 bool ret = Interop.Vector2.Vector2_EqualTo(swigCPtr, Size2D.getCPtr(rhs));
282 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
287 /// Checks inequality.<br />
288 /// Utilizes appropriate machine epsilon values.<br />
290 /// <param name="rhs">The size to test against.</param>
291 /// <returns>True if the sizes are not equal.</returns>
292 /// <since_tizen> 3 </since_tizen>
293 public bool NotEqualTo(Size2D rhs)
295 bool ret = Interop.Vector2.Vector2_NotEqualTo(swigCPtr, Size2D.getCPtr(rhs));
296 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
300 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Size2D obj)
302 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
306 /// Gets the size from the pointer.
308 /// <param name="cPtr">The pointer of the size.</param>
309 /// <returns>Size</returns>
310 internal static Size2D GetSize2DFromPtr(global::System.IntPtr cPtr)
312 Size2D ret = new Size2D(cPtr, false);
313 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
317 internal Size2D(Size2DChangedCallback cb, int x, int y) : this(Interop.Vector2.new_Vector2__SWIG_1((float)x, (float)y), true)
320 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
323 internal Size2D(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
327 /// This will not be public opened.
328 [EditorBrowsable(EditorBrowsableState.Never)]
329 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
331 Interop.Vector2.delete_Vector2(swigCPtr);
334 private Size2D Add(Size2D rhs)
336 Size2D ret = new Size2D(Interop.Vector2.Vector2_Add(swigCPtr, Size2D.getCPtr(rhs)), true);
337 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
341 private Size2D Subtract(Size2D rhs)
343 Size2D ret = new Size2D(Interop.Vector2.Vector2_Subtract__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
344 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
348 private Size2D Multiply(Size2D rhs)
350 Size2D ret = new Size2D(Interop.Vector2.Vector2_Multiply__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
351 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
355 private Size2D Multiply(int rhs)
357 Size2D ret = new Size2D(Interop.Vector2.Vector2_Multiply__SWIG_1(swigCPtr, (float)rhs), true);
358 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
362 private Size2D Divide(Size2D rhs)
364 Size2D ret = new Size2D(Interop.Vector2.Vector2_Divide__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
365 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
369 private Size2D Divide(int rhs)
371 Size2D ret = new Size2D(Interop.Vector2.Vector2_Divide__SWIG_1(swigCPtr, (float)rhs), true);
372 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
376 private Size2D Subtract()
378 Size2D ret = new Size2D(Interop.Vector2.Vector2_Subtract__SWIG_1(swigCPtr), true);
379 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
383 private int ValueOfIndex(uint index)
385 int ret = (int)Interop.Vector2.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
386 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();