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.
18 using System.ComponentModel;
19 using Tizen.NUI.Binding;
25 /// A two-dimensional size.
27 /// <since_tizen> 3 </since_tizen>
28 [Tizen.NUI.Binding.TypeConverter(typeof(Size2DTypeConverter))]
29 public class Size2D : Disposable, ICloneable
32 private Size2DChangedCallback callback = null;
38 /// Size2D and Size are implicitly converted to each other, so these are compatible and can be replaced without any type casting. <br />
39 /// For example, the followings are possible. <br />
40 /// view.Size2D = new Size(10.0f, 10.0f, 10.0f); // be aware that here the depth value(10.0f) will be lost. <br />
41 /// view.Size = new Size2D(10, 10); // be aware that here the depth value is 0.0f by default. <br />
42 /// view.MinimumSize = new Size(10, 10, 0); <br />
43 /// Size Tmp = view.MaximumSize; //here Tmp.Depth will be 0.0f. <br />
45 /// <since_tizen> 3 </since_tizen>
46 public Size2D() : this(Interop.Vector2.new_Vector2__SWIG_0(), true)
48 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
54 /// <param name="width">The width component.</param>
55 /// <param name="height">The height component.</param>
57 /// Size2D and Size are implicitly converted to each other, so these are compatible and can be replaced without any type casting. <br />
58 /// For example, the followings are possible. <br />
59 /// view.Size2D = new Size(10.0f, 10.0f, 10.0f); // be aware that here the depth value(10.0f) will be lost. <br />
60 /// view.Size = new Size2D(10, 10); // be aware that here the depth value is 0.0f by default. <br />
61 /// view.MinimumSize = new Size(10, 10, 0); <br />
62 /// Size Tmp = view.MaximumSize; //here Tmp.Depth will be 0.0f. <br />
64 /// <since_tizen> 3 </since_tizen>
65 public Size2D(int width, int height) : this(Interop.Vector2.new_Vector2__SWIG_1((float)width, (float)height), true)
67 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
70 internal delegate void Size2DChangedCallback(int? width, int? height);
73 /// The property for the width component of a size.
76 /// The setter is deprecated in API8 and will be removed in API10. Please use new Size2D(...) constructor.
79 /// // DO NOT use like the followings!
80 /// Size2D size2d = new Size2D();
82 /// // Please USE like this
83 /// int width = 1, height = 2;
84 /// Size2D size2d = new Size2D(width, height);
86 /// <since_tizen> 3 </since_tizen>
91 Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Size2D(...) constructor");
93 Interop.Vector2.Vector2_Width_set(swigCPtr, (float)value);
94 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
96 callback?.Invoke(value, null);
100 float ret = Interop.Vector2.Vector2_Width_get(swigCPtr);
101 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
107 /// The property for the height component of a size.
110 /// The setter is deprecated in API8 and will be removed in API10. Please use new Size2D(...) constructor.
113 /// // DO NOT use like the followings!
114 /// Size2D size2d = new Size2D();
115 /// size2d.Height = 2;
116 /// // Please USE like this
117 /// int width = 1, height = 2;
118 /// Size2D size2d = new Size2D(width, height);
120 /// <since_tizen> 3 </since_tizen>
125 Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Size2D(...) constructor");
127 Interop.Vector2.Vector2_Height_set(swigCPtr, (float)value);
128 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
130 callback?.Invoke(null, value);
134 float ret = Interop.Vector2.Vector2_Height_get(swigCPtr);
135 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
141 /// The addition operator for A+B.
143 /// <param name="arg1">Size A.</param>
144 /// <param name="arg2">Size to assign B.</param>
145 /// <returns>A size containing the result of the addition.</returns>
146 /// <since_tizen> 3 </since_tizen>
147 public static Size2D operator +(Size2D arg1, Size2D arg2)
149 return arg1?.Add(arg2);
153 /// The subtraction operator for A-B.
155 /// <param name="arg1">Size A.</param>
156 /// <param name="arg2">Size to subtract B.</param>
157 /// <returns>A size containing the result of the subtraction.</returns>
158 /// <since_tizen> 3 </since_tizen>
159 public static Size2D operator -(Size2D arg1, Size2D arg2)
161 return arg1?.Subtract(arg2);
165 /// The unary negation operator.
167 /// <param name="arg1">Size for unary negation.</param>
168 /// <returns>A size containing the negation.</returns>
169 /// <since_tizen> 3 </since_tizen>
170 public static Size2D operator -(Size2D arg1)
172 return arg1?.Subtract();
176 /// The multiplication operator.
178 /// <param name="arg1">Size for multiplication.</param>
179 /// <param name="arg2">Size to multiply.</param>
180 /// <returns>A size containing the result of the multiplication.</returns>
181 /// <since_tizen> 3 </since_tizen>
182 public static Size2D operator *(Size2D arg1, Size2D arg2)
184 return arg1?.Multiply(arg2);
188 /// The multiplication operator.
190 /// <param name="arg1">Size for multiplication</param>
191 /// <param name="arg2">The integer value to scale the size.</param>
192 /// <returns>A size containing the result of the scaling.</returns>
194 /// <since_tizen> 3 </since_tizen>
195 public static Size2D operator *(Size2D arg1, int arg2)
197 return arg1?.Multiply(arg2);
201 /// The division operator.
203 /// <param name="arg1">Size for division.</param>
204 /// <param name="arg2">Size to divide.</param>
205 /// <returns>A size containing the result of the division.</returns>
206 /// <since_tizen> 3 </since_tizen>
207 public static Size2D operator /(Size2D arg1, Size2D arg2)
209 return arg1?.Divide(arg2);
213 /// The division operator.
215 /// <param name="arg1">Size for division.</param>
216 /// <param name="arg2">The integer value to scale the size by.</param>
217 /// <returns>A size containing the result of the scaling.</returns>
218 /// <since_tizen> 3 </since_tizen>
219 public static Size2D operator /(Size2D arg1, int arg2)
221 return arg1?.Divide(arg2);
225 /// The type cast operator, Size2D to Vector2.
227 /// <param name="size">An object of the Size2D type.</param>
228 /// <returns>return a Vector2 instance</returns>
229 /// <since_tizen> 3 </since_tizen>
230 public static implicit operator Vector2(Size2D size)
232 return new Vector2((float)size?.Width, (float)size.Height);
236 /// The type cast operator, Vector2 to Size2D type.
238 /// <param name="vector2">An object of the Vector2 type.</param>
239 /// <returns>return a Size2D instance</returns>
240 /// <since_tizen> 3 </since_tizen>
241 public static implicit operator Size2D(Vector2 vector2)
243 return new Size2D((int)vector2?.X, (int)vector2.Y);
247 /// Implicit type cast operator, Size to Size2D
249 /// <param name="size">The object of Size type.</param>
250 /// <since_tizen> none </since_tizen>
251 /// This will be public opened in tizen_next by ACR.
252 [EditorBrowsable(EditorBrowsableState.Never)]
253 public static implicit operator Size2D(Size size)
255 return new Size2D((int)size?.Width, (int)size.Height);
260 /// The array subscript operator.
262 /// <param name="index">The subscript index.</param>
263 /// <returns>The float at the given index.</returns>
264 /// <since_tizen> 3 </since_tizen>
265 public float this[uint index]
269 return ValueOfIndex(index);
274 /// Determines whether the specified object is equal to the current object.
276 /// <param name="obj">The object to compare with the current object.</param>
277 /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
278 public override bool Equals(System.Object obj)
280 Size2D size2D = obj as Size2D;
282 if (Width == size2D?.Width && Height == size2D?.Height)
290 /// Gets the the hash code of this Size2D.
292 /// <returns>The Hash Code.</returns>
293 /// <since_tizen> 6 </since_tizen>
294 public override int GetHashCode()
296 return swigCPtr.Handle.GetHashCode();
300 /// Checks equality.<br />
301 /// Utilizes appropriate machine epsilon values.<br />
303 /// <param name="rhs">The size to test against.</param>
304 /// <returns>True if the sizes are equal.</returns>
305 /// <since_tizen> 3 </since_tizen>
306 public bool EqualTo(Size2D rhs)
308 bool ret = Interop.Vector2.Vector2_EqualTo(swigCPtr, Size2D.getCPtr(rhs));
309 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
314 /// Checks inequality.<br />
315 /// Utilizes appropriate machine epsilon values.<br />
317 /// <param name="rhs">The size to test against.</param>
318 /// <returns>True if the sizes are not equal.</returns>
319 /// <since_tizen> 3 </since_tizen>
320 public bool NotEqualTo(Size2D rhs)
322 bool ret = Interop.Vector2.Vector2_NotEqualTo(swigCPtr, Size2D.getCPtr(rhs));
323 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
328 [EditorBrowsable(EditorBrowsableState.Never)]
329 public object Clone() => new Size2D(Width, Height);
331 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Size2D obj)
333 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
337 /// Gets the size from the pointer.
339 /// <param name="cPtr">The pointer of the size.</param>
340 /// <returns>Size</returns>
341 internal static Size2D GetSize2DFromPtr(global::System.IntPtr cPtr)
343 Size2D ret = new Size2D(cPtr, false);
344 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
348 internal Size2D(Size2DChangedCallback cb, int x, int y) : this(Interop.Vector2.new_Vector2__SWIG_1((float)x, (float)y), true)
351 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
354 internal Size2D(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
358 /// This will not be public opened.
359 [EditorBrowsable(EditorBrowsableState.Never)]
360 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
362 Interop.Vector2.delete_Vector2(swigCPtr);
365 private Size2D Add(Size2D rhs)
367 Size2D ret = new Size2D(Interop.Vector2.Vector2_Add(swigCPtr, Size2D.getCPtr(rhs)), true);
368 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
372 private Size2D Subtract(Size2D rhs)
374 Size2D ret = new Size2D(Interop.Vector2.Vector2_Subtract__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
375 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
379 private Size2D Multiply(Size2D rhs)
381 Size2D ret = new Size2D(Interop.Vector2.Vector2_Multiply__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
382 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
386 private Size2D Multiply(int rhs)
388 Size2D ret = new Size2D(Interop.Vector2.Vector2_Multiply__SWIG_1(swigCPtr, (float)rhs), true);
389 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
393 private Size2D Divide(Size2D rhs)
395 Size2D ret = new Size2D(Interop.Vector2.Vector2_Divide__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
396 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
400 private Size2D Divide(int rhs)
402 Size2D ret = new Size2D(Interop.Vector2.Vector2_Divide__SWIG_1(swigCPtr, (float)rhs), true);
403 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
407 private Size2D Subtract()
409 Size2D ret = new Size2D(Interop.Vector2.Vector2_Subtract__SWIG_1(swigCPtr), true);
410 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
414 private int ValueOfIndex(uint index)
416 int ret = (int)Interop.Vector2.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
417 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();