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 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
32 /// <summary>swigCMemOwn.</summary>
33 /// <since_tizen> 5 </since_tizen>
34 protected bool swigCMemOwn;
36 internal Size(global::System.IntPtr cPtr, bool cMemoryOwn)
38 swigCMemOwn = cMemoryOwn;
39 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
42 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Size obj)
44 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
47 //A Flag to check who called Dispose(). (By User or DisposeQueue)
48 private bool isDisposeQueued = false;
50 /// A Flat to check if it is already disposed.
52 /// <since_tizen> 5 </since_tizen>
53 protected bool disposed = false;
62 isDisposeQueued = true;
63 DisposeQueue.Instance.Add(this);
70 /// <since_tizen> 5 </since_tizen>
73 //Throw excpetion if Dispose() is called in separate thread.
74 if (!Window.IsInstalled())
76 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
81 Dispose(DisposeTypes.Implicit);
85 Dispose(DisposeTypes.Explicit);
86 System.GC.SuppressFinalize(this);
93 /// <since_tizen> 5 </since_tizen>
94 protected virtual void Dispose(DisposeTypes type)
101 if (type == DisposeTypes.Explicit)
104 //Release your own managed resources here.
105 //You should release all of your own disposable objects here.
109 //Release your own unmanaged resources here.
110 //You should not access any managed member here except static instance.
111 //because the execution order of Finalizes is non-deterministic.
113 if (swigCPtr.Handle != global::System.IntPtr.Zero)
118 NDalicPINVOKE.delete_Vector3(swigCPtr);
120 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
127 /// The addition operator for A+B.
129 /// <param name="arg1">Size to assign A.</param>
130 /// <param name="arg2">Size to assign B.</param>
131 /// <returns>A size containing the result of the addition.</returns>
132 /// <since_tizen> 5 </since_tizen>
133 public static Size operator +(Size arg1, Size arg2)
135 return arg1.Add(arg2);
139 /// The subtraction operator for A-B.
141 /// <param name="arg1">Size to subtract A.</param>
142 /// <param name="arg2">Size to subtract B.</param>
143 /// <returns>The size containing the result of the subtraction.</returns>
144 /// <since_tizen> 5 </since_tizen>
145 public static Size operator -(Size arg1, Size arg2)
147 return arg1.Subtract(arg2);
151 /// The unary negation operator.
153 /// <param name="arg1">Size for unary negation.</param>
154 /// <returns>A size containing the negation.</returns>
155 /// <since_tizen> 5 </since_tizen>
156 public static Size operator -(Size arg1)
158 return arg1.Subtract();
162 /// The multiplication operator.
164 /// <param name="arg1">Size for multiplication.</param>
165 /// <param name="arg2">The size to multiply.</param>
166 /// <returns>A size containing the result of the multiplication.</returns>
167 /// <since_tizen> 5 </since_tizen>
168 public static Size operator *(Size arg1, Size arg2)
170 return arg1.Multiply(arg2);
174 /// The multiplication operator.
176 /// <param name="arg1">Size for multiplication.</param>
177 /// <param name="arg2">The float value to scale the size.</param>
178 /// <returns>A size containing the result of the scaling.</returns>
179 /// <since_tizen> 5 </since_tizen>
180 public static Size operator *(Size arg1, float arg2)
182 return arg1.Multiply(arg2);
186 /// The division operator.
188 /// <param name="arg1">Size for division.</param>
189 /// <param name="arg2">The size to divide.</param>
190 /// <returns>A size containing the result of the division.</returns>
191 /// <since_tizen> 5 </since_tizen>
192 public static Size operator /(Size arg1, Size arg2)
194 return arg1.Divide(arg2);
198 /// The division operator.
200 /// <param name="arg1">Size for division.</param>
201 /// <param name="arg2">The float value to scale the size by.</param>
202 /// <returns>A Size containing the result of the scaling.</returns>
203 /// <since_tizen> 5 </since_tizen>
204 public static Size operator /(Size arg1, float arg2)
206 return arg1.Divide(arg2);
210 /// The array subscript operator.
212 /// <param name="index">Subscript index.</param>
213 /// <returns>The float at the given index.</returns>
214 /// <since_tizen> 5 </since_tizen>
215 public float this[uint index]
219 return ValueOfIndex(index);
223 internal static Size GetSizeFromPtr(global::System.IntPtr cPtr)
225 Size ret = new Size(cPtr, false);
226 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
233 /// <since_tizen> 5 </since_tizen>
234 public Size() : this(NDalicPINVOKE.new_Vector3__SWIG_0(), true)
236 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
242 /// <param name="x">The x (or width) component.</param>
243 /// <param name="y">The y (or height) component.</param>
244 /// <param name="z">The z (or depth) component.</param>
245 /// <since_tizen> 5 </since_tizen>
246 public Size(float x, float y, float z) : this(NDalicPINVOKE.new_Vector3__SWIG_1(x, y, z), true)
248 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
254 /// <param name="size2d">Size2D with x (width) and y (height).</param>
255 /// <since_tizen> 5 </since_tizen>
256 public Size(Size2D size2d) : this(NDalicPINVOKE.new_Vector3__SWIG_3(Size2D.getCPtr(size2d)), true)
258 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
262 /// The Zero constant, (0.0f, 0.0f, 0.0f).
264 /// <since_tizen> 5 </since_tizen>
265 public static Size Zero
269 global::System.IntPtr cPtr = NDalicPINVOKE.Vector3_ZERO_get();
270 Size ret = (cPtr == global::System.IntPtr.Zero) ? null : new Size(cPtr, false);
271 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
276 private Size Add(Size rhs)
278 Size ret = new Size(NDalicPINVOKE.Vector3_Add(swigCPtr, Size.getCPtr(rhs)), true);
279 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
283 private Size Subtract(Size rhs)
285 Size ret = new Size(NDalicPINVOKE.Vector3_Subtract__SWIG_0(swigCPtr, Size.getCPtr(rhs)), true);
286 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
290 private Size Multiply(Size rhs)
292 Size ret = new Size(NDalicPINVOKE.Vector3_Multiply__SWIG_0(swigCPtr, Size.getCPtr(rhs)), true);
293 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
297 private Size Multiply(float rhs)
299 Size ret = new Size(NDalicPINVOKE.Vector3_Multiply__SWIG_1(swigCPtr, rhs), true);
300 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
304 private Size Divide(Size rhs)
306 Size ret = new Size(NDalicPINVOKE.Vector3_Divide__SWIG_0(swigCPtr, Size.getCPtr(rhs)), true);
307 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
311 private Size Divide(float rhs)
313 Size ret = new Size(NDalicPINVOKE.Vector3_Divide__SWIG_1(swigCPtr, rhs), true);
314 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
318 private Size Subtract()
320 Size ret = new Size(NDalicPINVOKE.Vector3_Subtract__SWIG_1(swigCPtr), true);
321 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
325 private float ValueOfIndex(uint index)
327 float ret = NDalicPINVOKE.Vector3_ValueOfIndex__SWIG_0(swigCPtr, index);
328 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
333 /// Determines whether the specified object is equal to the current object.
335 /// <param name="obj">The object to compare with the current object.</param>
336 /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
337 public override bool Equals(System.Object obj)
339 Size size = obj as Size;
341 if (Width == size?.Width && Height == size?.Height && Depth == size?.Depth)
349 /// Gets the the hash code of this Size.
351 /// <returns>The Hash Code.</returns>
352 /// <since_tizen> 5 </since_tizen>
353 public override int GetHashCode()
355 return Zero.GetHashCode();
359 /// Checks equality.<br />
360 /// Utilizes appropriate machine epsilon values.<br />
362 /// <param name="rhs">The size to test against.</param>
363 /// <returns>True if the sizes are equal.</returns>
364 /// <since_tizen> 5 </since_tizen>
365 public bool EqualTo(Size rhs)
367 bool ret = NDalicPINVOKE.Vector3_EqualTo(swigCPtr, Size.getCPtr(rhs));
368 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
373 /// Checks inequality.<br />
374 /// Utilizes appropriate machine epsilon values.<br />
376 /// <param name="rhs">The size to test against.</param>
377 /// <returns>True if the sizes are not equal.</returns>
378 /// <since_tizen> 5 </since_tizen>
379 public bool NotEqualTo(Size rhs)
381 bool ret = NDalicPINVOKE.Vector3_NotEqualTo(swigCPtr, Size.getCPtr(rhs));
382 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
387 /// The Width property for the width component of size
389 /// <since_tizen> 5 </since_tizen>
394 NDalicPINVOKE.Vector3_Width_set(swigCPtr, value);
395 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
399 float ret = NDalicPINVOKE.Vector3_Width_get(swigCPtr);
400 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
406 /// The Height property for the height component of size.
408 /// <since_tizen> 5 </since_tizen>
413 NDalicPINVOKE.Vector3_Height_set(swigCPtr, value);
414 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
418 float ret = NDalicPINVOKE.Vector3_Height_get(swigCPtr);
419 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
425 /// The Depth property for the depth component of size.
427 /// <since_tizen> 5 </since_tizen>
432 NDalicPINVOKE.Vector3_Depth_set(swigCPtr, value);
433 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
437 float ret = NDalicPINVOKE.Vector3_Depth_get(swigCPtr);
438 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
444 /// The type cast operator, Size to Vector3.
446 /// <param name="size">The object of size type.</param>
447 /// <since_tizen> 5 </since_tizen>
448 public static implicit operator Vector3(Size size)
450 return new Vector3(size.Width, size.Height, size.Depth);
454 /// The type cast operator, Vector3 to Size type.
456 /// <param name="vec">The object of Vector3 type.</param>
457 /// <since_tizen> 5 </since_tizen>
458 public static implicit operator Size(Vector3 vec)
460 return new Size(vec.Width, vec.Height, vec.Depth);