2 * Copyright (c) 2018 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 : global::System.IDisposable
31 /// <summary>swigCMemOwn.</summary>
32 /// <since_tizen> 5 </since_tizen>
33 protected bool swigCMemOwn;
36 /// A Flat to check if it is already disposed.
38 /// <since_tizen> 5 </since_tizen>
39 protected bool disposed = false;
41 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
43 //A Flag to check who called Dispose(). (By User or DisposeQueue)
44 private bool isDisposeQueued = false;
49 /// <since_tizen> 5 </since_tizen>
50 public Size() : this(Interop.Vector3.new_Vector3__SWIG_0(), true)
52 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
58 /// <param name="x">The x (or width) component.</param>
59 /// <param name="y">The y (or height) component.</param>
60 /// <param name="z">The z (or depth) component.</param>
61 /// <since_tizen> 5 </since_tizen>
62 public Size(float x, float y, float z) : this(Interop.Vector3.new_Vector3__SWIG_1(x, y, z), true)
64 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
70 /// <param name="size2d">Size2D with x (width) and y (height).</param>
71 /// <since_tizen> 5 </since_tizen>
72 public Size(Size2D size2d) : this(Interop.Vector3.new_Vector3__SWIG_3(Size2D.getCPtr(size2d)), true)
74 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
84 isDisposeQueued = true;
85 DisposeQueue.Instance.Add(this);
90 /// The Zero constant, (0.0f, 0.0f, 0.0f).
92 /// <since_tizen> 5 </since_tizen>
93 public static Size Zero
97 global::System.IntPtr cPtr = Interop.Vector3.Vector3_ZERO_get();
98 Size ret = (cPtr == global::System.IntPtr.Zero) ? null : new Size(cPtr, false);
99 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
105 /// The Width property for the width component of size
107 /// <since_tizen> 5 </since_tizen>
112 Interop.Vector3.Vector3_Width_set(swigCPtr, value);
113 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
115 callback?.Invoke(Width, Height, Depth);
119 float ret = Interop.Vector3.Vector3_Width_get(swigCPtr);
120 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
126 /// The Height property for the height component of size.
128 /// <since_tizen> 5 </since_tizen>
133 Interop.Vector3.Vector3_Height_set(swigCPtr, value);
134 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
136 callback?.Invoke(Width, Height, Depth);
140 float ret = Interop.Vector3.Vector3_Height_get(swigCPtr);
141 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
147 /// The Depth property for the depth component of size.
149 /// <since_tizen> 5 </since_tizen>
154 Interop.Vector3.Vector3_Depth_set(swigCPtr, value);
155 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
157 callback?.Invoke(Width, Height, Depth);
161 float ret = Interop.Vector3.Vector3_Depth_get(swigCPtr);
162 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
168 /// The addition operator for A+B.
170 /// <param name="arg1">Size to assign A.</param>
171 /// <param name="arg2">Size to assign B.</param>
172 /// <returns>A size containing the result of the addition.</returns>
173 /// <since_tizen> 5 </since_tizen>
174 public static Size operator +(Size arg1, Size arg2)
176 return arg1.Add(arg2);
180 /// The subtraction operator for A-B.
182 /// <param name="arg1">Size to subtract A.</param>
183 /// <param name="arg2">Size to subtract B.</param>
184 /// <returns>The size containing the result of the subtraction.</returns>
185 /// <since_tizen> 5 </since_tizen>
186 public static Size operator -(Size arg1, Size arg2)
188 return arg1.Subtract(arg2);
192 /// The unary negation operator.
194 /// <param name="arg1">Size for unary negation.</param>
195 /// <returns>A size containing the negation.</returns>
196 /// <since_tizen> 5 </since_tizen>
197 public static Size operator -(Size arg1)
199 return arg1.Subtract();
203 /// The multiplication operator.
205 /// <param name="arg1">Size for multiplication.</param>
206 /// <param name="arg2">The size to multiply.</param>
207 /// <returns>A size containing the result of the multiplication.</returns>
208 /// <since_tizen> 5 </since_tizen>
209 public static Size operator *(Size arg1, Size arg2)
211 return arg1.Multiply(arg2);
215 /// The multiplication operator.
217 /// <param name="arg1">Size for multiplication.</param>
218 /// <param name="arg2">The float value to scale the size.</param>
219 /// <returns>A size containing the result of the scaling.</returns>
220 /// <since_tizen> 5 </since_tizen>
221 public static Size operator *(Size arg1, float arg2)
223 return arg1.Multiply(arg2);
227 /// The division operator.
229 /// <param name="arg1">Size for division.</param>
230 /// <param name="arg2">The size to divide.</param>
231 /// <returns>A size containing the result of the division.</returns>
232 /// <since_tizen> 5 </since_tizen>
233 public static Size operator /(Size arg1, Size arg2)
235 return arg1.Divide(arg2);
239 /// The division operator.
241 /// <param name="arg1">Size for division.</param>
242 /// <param name="arg2">The float value to scale the size by.</param>
243 /// <returns>A Size containing the result of the scaling.</returns>
244 /// <since_tizen> 5 </since_tizen>
245 public static Size operator /(Size arg1, float arg2)
247 return arg1.Divide(arg2);
251 /// The array subscript operator.
253 /// <param name="index">Subscript index.</param>
254 /// <returns>The float at the given index.</returns>
255 /// <since_tizen> 5 </since_tizen>
256 public float this[uint index]
260 return ValueOfIndex(index);
267 /// <since_tizen> 5 </since_tizen>
268 public void Dispose()
270 //Throw excpetion if Dispose() is called in separate thread.
271 if (!Window.IsInstalled())
273 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
278 Dispose(DisposeTypes.Implicit);
282 Dispose(DisposeTypes.Explicit);
283 System.GC.SuppressFinalize(this);
288 /// Determines whether the specified object is equal to the current object.
290 /// <param name="obj">The object to compare with the current object.</param>
291 /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
292 public override bool Equals(System.Object obj)
294 Size size = obj as Size;
296 if (Width == size?.Width && Height == size?.Height && Depth == size?.Depth)
304 /// Gets the the hash code of this Size.
306 /// <returns>The Hash Code.</returns>
307 /// <since_tizen> 6 </since_tizen>
308 public override int GetHashCode()
310 return swigCPtr.Handle.GetHashCode();
314 /// Checks equality.<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 equal.</returns>
319 /// <since_tizen> 5 </since_tizen>
320 public bool EqualTo(Size rhs)
322 bool ret = Interop.Vector3.Vector3_EqualTo(swigCPtr, Size.getCPtr(rhs));
323 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
328 /// Checks inequality.<br />
329 /// Utilizes appropriate machine epsilon values.<br />
331 /// <param name="rhs">The size to test against.</param>
332 /// <returns>True if the sizes are not equal.</returns>
333 /// <since_tizen> 5 </since_tizen>
334 public bool NotEqualTo(Size rhs)
336 bool ret = Interop.Vector3.Vector3_NotEqualTo(swigCPtr, Size.getCPtr(rhs));
337 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
344 /// The type cast operator, Size to Vector3.
346 /// <param name="size">The object of size type.</param>
347 /// <since_tizen> 5 </since_tizen>
348 public static implicit operator Vector3(Size size)
350 return new Vector3(size.Width, size.Height, size.Depth);
354 /// The type cast operator, Vector3 to Size type.
356 /// <param name="vec">The object of Vector3 type.</param>
357 /// <since_tizen> 5 </since_tizen>
358 public static implicit operator Size(Vector3 vec)
360 return new Size(vec.Width, vec.Height, vec.Depth);
363 internal static Size GetSizeFromPtr(global::System.IntPtr cPtr)
365 Size ret = new Size(cPtr, false);
366 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
370 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Size obj)
372 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
375 internal Size(global::System.IntPtr cPtr, bool cMemoryOwn)
377 swigCMemOwn = cMemoryOwn;
378 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
384 /// <since_tizen> 5 </since_tizen>
385 protected virtual void Dispose(DisposeTypes type)
392 if (type == DisposeTypes.Explicit)
395 //Release your own managed resources here.
396 //You should release all of your own disposable objects here.
400 //Release your own unmanaged resources here.
401 //You should not access any managed member here except static instance.
402 //because the execution order of Finalizes is non-deterministic.
404 if (swigCPtr.Handle != global::System.IntPtr.Zero)
409 Interop.Vector3.delete_Vector3(swigCPtr);
411 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
417 private Size Add(Size rhs)
419 Size ret = new Size(Interop.Vector3.Vector3_Add(swigCPtr, Size.getCPtr(rhs)), true);
420 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
424 private Size Subtract(Size rhs)
426 Size ret = new Size(Interop.Vector3.Vector3_Subtract__SWIG_0(swigCPtr, Size.getCPtr(rhs)), true);
427 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
431 private Size Multiply(Size rhs)
433 Size ret = new Size(Interop.Vector3.Vector3_Multiply__SWIG_0(swigCPtr, Size.getCPtr(rhs)), true);
434 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
438 private Size Multiply(float rhs)
440 Size ret = new Size(Interop.Vector3.Vector3_Multiply__SWIG_1(swigCPtr, rhs), true);
441 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
445 private Size Divide(Size rhs)
447 Size ret = new Size(Interop.Vector3.Vector3_Divide__SWIG_0(swigCPtr, Size.getCPtr(rhs)), true);
448 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
452 private Size Divide(float rhs)
454 Size ret = new Size(Interop.Vector3.Vector3_Divide__SWIG_1(swigCPtr, rhs), true);
455 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
459 private Size Subtract()
461 Size ret = new Size(Interop.Vector3.Vector3_Subtract__SWIG_1(swigCPtr), true);
462 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
466 private float ValueOfIndex(uint index)
468 float ret = Interop.Vector3.Vector3_ValueOfIndex__SWIG_0(swigCPtr, index);
469 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
473 internal delegate void SizeChangedCallback(float width, float height, float depth);
475 internal Size(SizeChangedCallback cb, float w, float h, float d) : this(Interop.Vector3.new_Vector3__SWIG_1(w, h, d), true)
478 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
481 private SizeChangedCallback callback = null;