2 * Copyright (c) 2021 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.
19 using System.ComponentModel;
20 using Tizen.NUI.Binding;
25 /// A three-dimensional size.
27 /// <since_tizen> 5 </since_tizen>
28 [Tizen.NUI.Binding.TypeConverter(typeof(SizeTypeConverter))]
29 public class Size : Disposable, ICloneable
36 /// Size2D and Size are implicitly converted to each other, so these are compatible and can be replaced without any type casting. <br />
37 /// For example, the followings are possible. <br />
38 /// view.Size2D = new Size(10.0f, 10.0f, 10.0f); // be aware that here the depth value(10.0f) will be lost. <br />
39 /// view.Size = new Size2D(10, 10); // be aware that here the depth value is 0.0f by default. <br />
40 /// view.MinimumSize = new Size(10, 10, 0); <br />
41 /// Size Tmp = view.MaximumSize; //here Tmp.Depth will be 0.0f. <br />
43 /// <since_tizen> 5 </since_tizen>
44 public Size() : this(Interop.Vector3.NewVector3(), true)
46 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
52 /// <param name="width">The width component.</param>
53 /// <param name="height">The height component.</param>
54 /// <param name="depth">The depth component(optional).</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> 5 </since_tizen>
64 public Size(float width, float height, float depth = 0.0f) : this(Interop.Vector3.NewVector3(width, height, depth), true)
66 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
72 /// <param name="size2d">Size2D with width and height.</param>
73 /// <since_tizen> 5 </since_tizen>
74 public Size(Size2D size2d) : this(Interop.Vector3.NewVector3WithVector2(Size2D.getCPtr(size2d)), true)
76 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
80 /// The Zero constant, (0.0f, 0.0f, 0.0f).
82 /// <since_tizen> 5 </since_tizen>
83 public static Size Zero
87 global::System.IntPtr cPtr = Interop.Vector3.ZeroGet();
88 Size ret = (cPtr == global::System.IntPtr.Zero) ? null : new Size(cPtr, false);
89 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
95 /// The Width property for the width component of size
98 /// The setter is deprecated in API8 and will be removed in API10. Use new Size(...) constructor.
101 /// // DO NOT use like the followings!
102 /// Size size = new Size();
103 /// size.Width = 0.1f;
105 /// float width = 0.1f, height = 0.5f, depth = 0.9f;
106 /// Size size = new Size(width, height, depth);
108 /// <since_tizen> 5 </since_tizen>
111 [Obsolete("Do not use this setter, that is deprecated in API8 and will be removed in API10. Use new Size(...) constructor")]
114 Interop.Vector3.WidthSet(SwigCPtr, value);
115 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
117 callback?.Invoke(value, null, null);
121 float ret = Interop.Vector3.WidthGet(SwigCPtr);
122 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
128 /// The Height property for the height component of size.
131 /// The setter is deprecated in API8 and will be removed in API10. Use new Size(...) constructor.
134 /// // DO NOT use like the followings!
135 /// Size size = new Size();
136 /// size.Height = 0.5f;
138 /// float width = 0.1f, height = 0.5f, depth = 0.9f;
139 /// Size size = new Size(width, height, depth);
141 /// <since_tizen> 5 </since_tizen>
144 [Obsolete("Do not use this setter, that is deprecated in API8 and will be removed in API10. Use new Size(...) constructor")]
147 Interop.Vector3.HeightSet(SwigCPtr, value);
148 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
150 callback?.Invoke(null, value, null);
154 float ret = Interop.Vector3.HeightGet(SwigCPtr);
155 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
161 /// The Depth property for the depth component of size.
164 /// The setter is deprecated in API8 and will be removed in API10. Use new Size(...) constructor.
167 /// // DO NOT use like the followings!
168 /// Size size = new Size();
169 /// size.Depth = 0.9f;
171 /// float width = 0.1f, height = 0.5f, depth = 0.9f;
172 /// Size size = new Size(width, height, depth);
174 /// <since_tizen> 5 </since_tizen>
177 [Obsolete("Do not use this setter, that is deprecated in API8 and will be removed in API10. Use new Size(...) constructor")]
180 Interop.Vector3.DepthSet(SwigCPtr, value);
181 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
183 callback?.Invoke(null, null, value);
187 float ret = Interop.Vector3.DepthGet(SwigCPtr);
188 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
194 /// The addition operator for A+B.
196 /// <param name="arg1">Size to assign A.</param>
197 /// <param name="arg2">Size to assign B.</param>
198 /// <returns>A size containing the result of the addition.</returns>
199 /// <since_tizen> 5 </since_tizen>
200 public static Size operator +(Size arg1, Size arg2)
202 return arg1?.Add(arg2);
206 /// The subtraction operator for A-B.
208 /// <param name="arg1">Size to subtract A.</param>
209 /// <param name="arg2">Size to subtract B.</param>
210 /// <returns>The size containing the result of the subtraction.</returns>
211 /// <since_tizen> 5 </since_tizen>
212 public static Size operator -(Size arg1, Size arg2)
214 return arg1?.Subtract(arg2);
218 /// The unary negation operator.
220 /// <param name="arg1">Size for unary negation.</param>
221 /// <returns>A size containing the negation.</returns>
222 /// <since_tizen> 5 </since_tizen>
223 public static Size operator -(Size arg1)
225 return arg1?.Subtract();
229 /// The multiplication operator.
231 /// <param name="arg1">Size for multiplication.</param>
232 /// <param name="arg2">The size to multiply.</param>
233 /// <returns>A size containing the result of the multiplication.</returns>
234 /// <since_tizen> 5 </since_tizen>
235 public static Size operator *(Size arg1, Size arg2)
237 return arg1?.Multiply(arg2);
241 /// The multiplication operator.
243 /// <param name="arg1">Size for multiplication.</param>
244 /// <param name="arg2">The float value to scale the size.</param>
245 /// <returns>A size containing the result of the scaling.</returns>
246 /// <since_tizen> 5 </since_tizen>
247 public static Size operator *(Size arg1, float arg2)
249 return arg1?.Multiply(arg2);
253 /// The division operator.
255 /// <param name="arg1">Size for division.</param>
256 /// <param name="arg2">The size to divide.</param>
257 /// <returns>A size containing the result of the division.</returns>
258 /// <since_tizen> 5 </since_tizen>
259 public static Size operator /(Size arg1, Size arg2)
261 return arg1?.Divide(arg2);
265 /// The division operator.
267 /// <param name="arg1">Size for division.</param>
268 /// <param name="arg2">The float value to scale the size by.</param>
269 /// <returns>A Size containing the result of the scaling.</returns>
270 /// <since_tizen> 5 </since_tizen>
271 public static Size operator /(Size arg1, float arg2)
273 return arg1?.Divide(arg2);
277 /// The array subscript operator.
279 /// <param name="index">Subscript index.</param>
280 /// <returns>The float at the given index.</returns>
281 /// <since_tizen> 5 </since_tizen>
282 public float this[uint index]
286 return ValueOfIndex(index);
291 /// Determines whether the specified object is equal to the current object.
293 /// <param name="obj">The object to compare with the current object.</param>
294 /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
295 public override bool Equals(System.Object obj)
297 Size size = obj as Size;
299 if (Width == size?.Width && Height == size?.Height && Depth == size?.Depth)
307 /// Gets the hash code of this Size.
309 /// <returns>The Hash Code.</returns>
310 /// <since_tizen> 6 </since_tizen>
311 public override int GetHashCode()
313 return SwigCPtr.Handle.GetHashCode();
317 /// Checks equality.<br />
318 /// Utilizes appropriate machine epsilon values.<br />
320 /// <param name="rhs">The size to test against.</param>
321 /// <returns>True if the sizes are equal.</returns>
322 /// <since_tizen> 5 </since_tizen>
323 public bool EqualTo(Size rhs)
325 bool ret = Interop.Vector3.EqualTo(SwigCPtr, Size.getCPtr(rhs));
326 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
331 /// Checks inequality.<br />
332 /// Utilizes appropriate machine epsilon values.<br />
334 /// <param name="rhs">The size to test against.</param>
335 /// <returns>True if the sizes are not equal.</returns>
336 /// <since_tizen> 5 </since_tizen>
337 public bool NotEqualTo(Size rhs)
339 bool ret = Interop.Vector3.NotEqualTo(SwigCPtr, Size.getCPtr(rhs));
340 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
345 [EditorBrowsable(EditorBrowsableState.Never)]
346 public object Clone() => new Size(Width, Height, Depth);
349 /// The type cast operator, Size to Vector3.
351 /// <param name="size">The object of size type.</param>
352 /// <since_tizen> 5 </since_tizen>
353 public static implicit operator Vector3(Size size)
359 return new Vector3(size.Width, size.Height, size.Depth);
363 /// The type cast operator, Vector3 to Size type.
365 /// <param name="vec">The object of Vector3 type.</param>
366 /// <since_tizen> 5 </since_tizen>
367 public static implicit operator Size(Vector3 vec)
373 return new Size(vec.Width, vec.Height, vec.Depth);
377 /// Implicit type cast operator, Size2D to Size
379 /// <param name="size2d">The object of Size2D type.</param>
380 /// <since_tizen> none </since_tizen>
381 /// This will be public opened in tizen_next by ACR.
382 [EditorBrowsable(EditorBrowsableState.Never)]
383 public static implicit operator Size(Size2D size2d)
389 return new Size(size2d.Width, size2d.Height);
393 internal static Size GetSizeFromPtr(global::System.IntPtr cPtr)
395 Size ret = new Size(cPtr, false);
396 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
400 internal Size(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
404 /// This will not be public opened.
405 [EditorBrowsable(EditorBrowsableState.Never)]
406 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
408 Interop.Vector3.DeleteVector3(swigCPtr);
411 private Size Add(Size rhs)
413 Size ret = new Size(Interop.Vector3.Add(SwigCPtr, Size.getCPtr(rhs)), true);
414 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
418 private Size Subtract(Size rhs)
420 Size ret = new Size(Interop.Vector3.Subtract(SwigCPtr, Size.getCPtr(rhs)), true);
421 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
425 private Size Multiply(Size rhs)
427 Size ret = new Size(Interop.Vector3.Multiply(SwigCPtr, Size.getCPtr(rhs)), true);
428 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
432 private Size Multiply(float rhs)
434 Size ret = new Size(Interop.Vector3.Multiply(SwigCPtr, rhs), true);
435 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
439 private Size Divide(Size rhs)
441 Size ret = new Size(Interop.Vector3.Divide(SwigCPtr, Size.getCPtr(rhs)), true);
442 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
446 private Size Divide(float rhs)
448 Size ret = new Size(Interop.Vector3.Divide(SwigCPtr, rhs), true);
449 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
453 private Size Subtract()
455 Size ret = new Size(Interop.Vector3.Subtract(SwigCPtr), true);
456 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
460 private float ValueOfIndex(uint index)
462 float ret = Interop.Vector3.ValueOfIndex(SwigCPtr, index);
463 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
467 internal delegate void SizeChangedCallback(float? width, float? height, float? depth);
469 internal Size(SizeChangedCallback cb, float w, float h, float d) : this(Interop.Vector3.NewVector3(w, h, d), true)
472 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
475 internal Size(SizeChangedCallback cb, Size other) : this(cb, other.Width, other.Height, other.Depth)
479 private SizeChangedCallback callback = null;