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.
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. Please use new Size(...) constructor.
101 /// // DO NOT use like the followings!
102 /// Size size = new Size();
103 /// size.Width = 0.1f;
104 /// // Please USE like this
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>
113 Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Size(...) constructor");
115 Interop.Vector3.WidthSet(swigCPtr, value);
116 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
118 callback?.Invoke(value, null, null);
122 float ret = Interop.Vector3.WidthGet(swigCPtr);
123 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
129 /// The Height property for the height component of size.
132 /// The setter is deprecated in API8 and will be removed in API10. Please use new Size(...) constructor.
135 /// // DO NOT use like the followings!
136 /// Size size = new Size();
137 /// size.Height = 0.5f;
138 /// // Please USE like this
139 /// float width = 0.1f, height = 0.5f, depth = 0.9f;
140 /// Size size = new Size(width, height, depth);
142 /// <since_tizen> 5 </since_tizen>
147 Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Size(...) constructor");
149 Interop.Vector3.HeightSet(swigCPtr, value);
150 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
152 callback?.Invoke(null, value, null);
156 float ret = Interop.Vector3.HeightGet(swigCPtr);
157 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
163 /// The Depth property for the depth component of size.
166 /// The setter is deprecated in API8 and will be removed in API10. Please use new Size(...) constructor.
169 /// // DO NOT use like the followings!
170 /// Size size = new Size();
171 /// size.Depth = 0.9f;
172 /// // Please USE like this
173 /// float width = 0.1f, height = 0.5f, depth = 0.9f;
174 /// Size size = new Size(width, height, depth);
176 /// <since_tizen> 5 </since_tizen>
181 Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Size(...) constructor");
183 Interop.Vector3.DepthSet(swigCPtr, value);
184 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
186 callback?.Invoke(null, null, value);
190 float ret = Interop.Vector3.DepthGet(swigCPtr);
191 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
197 /// The addition operator for A+B.
199 /// <param name="arg1">Size to assign A.</param>
200 /// <param name="arg2">Size to assign B.</param>
201 /// <returns>A size containing the result of the addition.</returns>
202 /// <since_tizen> 5 </since_tizen>
203 public static Size operator +(Size arg1, Size arg2)
205 return arg1?.Add(arg2);
209 /// The subtraction operator for A-B.
211 /// <param name="arg1">Size to subtract A.</param>
212 /// <param name="arg2">Size to subtract B.</param>
213 /// <returns>The size containing the result of the subtraction.</returns>
214 /// <since_tizen> 5 </since_tizen>
215 public static Size operator -(Size arg1, Size arg2)
217 return arg1?.Subtract(arg2);
221 /// The unary negation operator.
223 /// <param name="arg1">Size for unary negation.</param>
224 /// <returns>A size containing the negation.</returns>
225 /// <since_tizen> 5 </since_tizen>
226 public static Size operator -(Size arg1)
228 return arg1?.Subtract();
232 /// The multiplication operator.
234 /// <param name="arg1">Size for multiplication.</param>
235 /// <param name="arg2">The size to multiply.</param>
236 /// <returns>A size containing the result of the multiplication.</returns>
237 /// <since_tizen> 5 </since_tizen>
238 public static Size operator *(Size arg1, Size arg2)
240 return arg1?.Multiply(arg2);
244 /// The multiplication operator.
246 /// <param name="arg1">Size for multiplication.</param>
247 /// <param name="arg2">The float value to scale the size.</param>
248 /// <returns>A size containing the result of the scaling.</returns>
249 /// <since_tizen> 5 </since_tizen>
250 public static Size operator *(Size arg1, float arg2)
252 return arg1?.Multiply(arg2);
256 /// The division operator.
258 /// <param name="arg1">Size for division.</param>
259 /// <param name="arg2">The size to divide.</param>
260 /// <returns>A size containing the result of the division.</returns>
261 /// <since_tizen> 5 </since_tizen>
262 public static Size operator /(Size arg1, Size arg2)
264 return arg1?.Divide(arg2);
268 /// The division operator.
270 /// <param name="arg1">Size for division.</param>
271 /// <param name="arg2">The float value to scale the size by.</param>
272 /// <returns>A Size containing the result of the scaling.</returns>
273 /// <since_tizen> 5 </since_tizen>
274 public static Size operator /(Size arg1, float arg2)
276 return arg1?.Divide(arg2);
280 /// The array subscript operator.
282 /// <param name="index">Subscript index.</param>
283 /// <returns>The float at the given index.</returns>
284 /// <since_tizen> 5 </since_tizen>
285 public float this[uint index]
289 return ValueOfIndex(index);
294 /// Determines whether the specified object is equal to the current object.
296 /// <param name="obj">The object to compare with the current object.</param>
297 /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
298 public override bool Equals(System.Object obj)
300 Size size = obj as Size;
302 if (Width == size?.Width && Height == size?.Height && Depth == size?.Depth)
310 /// Gets the the hash code of this Size.
312 /// <returns>The Hash Code.</returns>
313 /// <since_tizen> 6 </since_tizen>
314 public override int GetHashCode()
316 return swigCPtr.Handle.GetHashCode();
320 /// Checks equality.<br />
321 /// Utilizes appropriate machine epsilon values.<br />
323 /// <param name="rhs">The size to test against.</param>
324 /// <returns>True if the sizes are equal.</returns>
325 /// <since_tizen> 5 </since_tizen>
326 public bool EqualTo(Size rhs)
328 bool ret = Interop.Vector3.EqualTo(swigCPtr, Size.getCPtr(rhs));
329 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
334 /// Checks inequality.<br />
335 /// Utilizes appropriate machine epsilon values.<br />
337 /// <param name="rhs">The size to test against.</param>
338 /// <returns>True if the sizes are not equal.</returns>
339 /// <since_tizen> 5 </since_tizen>
340 public bool NotEqualTo(Size rhs)
342 bool ret = Interop.Vector3.NotEqualTo(swigCPtr, Size.getCPtr(rhs));
343 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
348 [EditorBrowsable(EditorBrowsableState.Never)]
349 public object Clone() => new Size(Width, Height, Depth);
352 /// The type cast operator, Size to Vector3.
354 /// <param name="size">The object of size type.</param>
355 /// <since_tizen> 5 </since_tizen>
356 public static implicit operator Vector3(Size size)
358 return new Vector3((float)size?.Width, (float)size.Height, (float)size.Depth);
362 /// The type cast operator, Vector3 to Size type.
364 /// <param name="vec">The object of Vector3 type.</param>
365 /// <since_tizen> 5 </since_tizen>
366 public static implicit operator Size(Vector3 vec)
368 return new Size((int)vec?.Width, (int)vec.Height, (int)vec.Depth);
372 /// Implicit type cast operator, Size2D to Size
374 /// <param name="size2d">The object of Size2D type.</param>
375 /// <since_tizen> none </since_tizen>
376 /// This will be public opened in tizen_next by ACR.
377 [EditorBrowsable(EditorBrowsableState.Never)]
378 public static implicit operator Size(Size2D size2d)
380 return new Size((int)size2d?.Width, (int)size2d.Height, 0);
384 internal static Size GetSizeFromPtr(global::System.IntPtr cPtr)
386 Size ret = new Size(cPtr, false);
387 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
391 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Size obj)
393 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
396 internal Size(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
400 /// This will not be public opened.
401 [EditorBrowsable(EditorBrowsableState.Never)]
402 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
404 Interop.Vector3.DeleteVector3(swigCPtr);
407 private Size Add(Size rhs)
409 Size ret = new Size(Interop.Vector3.Add(swigCPtr, Size.getCPtr(rhs)), true);
410 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
414 private Size Subtract(Size rhs)
416 Size ret = new Size(Interop.Vector3.Subtract(swigCPtr, Size.getCPtr(rhs)), true);
417 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
421 private Size Multiply(Size rhs)
423 Size ret = new Size(Interop.Vector3.Multiply(swigCPtr, Size.getCPtr(rhs)), true);
424 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
428 private Size Multiply(float rhs)
430 Size ret = new Size(Interop.Vector3.Multiply(swigCPtr, rhs), true);
431 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
435 private Size Divide(Size rhs)
437 Size ret = new Size(Interop.Vector3.Divide(swigCPtr, Size.getCPtr(rhs)), true);
438 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
442 private Size Divide(float rhs)
444 Size ret = new Size(Interop.Vector3.Divide(swigCPtr, rhs), true);
445 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
449 private Size Subtract()
451 Size ret = new Size(Interop.Vector3.Subtract(swigCPtr), true);
452 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
456 private float ValueOfIndex(uint index)
458 float ret = Interop.Vector3.ValueOfIndex(swigCPtr, index);
459 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
463 internal delegate void SizeChangedCallback(float? width, float? height, float? depth);
465 internal Size(SizeChangedCallback cb, float w, float h, float d) : this(Interop.Vector3.NewVector3(w, h, d), true)
468 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
471 internal Size(SizeChangedCallback cb, Size other) : this(cb, other.Width, other.Height, other.Depth)
475 private SizeChangedCallback callback = null;