2 * Copyright (c) 2017 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 Tizen.NUI.Binding;
24 /// A two-dimensional size.
26 /// <since_tizen> 3 </since_tizen>
27 [Tizen.NUI.Binding.TypeConverter(typeof(Size2DTypeConverter))]
28 public class Size2D : global::System.IDisposable
30 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
34 /// <since_tizen> 3 </since_tizen>
35 protected bool swigCMemOwn;
37 internal Size2D(global::System.IntPtr cPtr, bool cMemoryOwn)
39 swigCMemOwn = cMemoryOwn;
40 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
43 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Size2D obj)
45 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
48 //A Flag to check who called Dispose(). (By User or DisposeQueue)
49 private bool isDisposeQueued = false;
51 /// A Flat to check if it is already disposed.
53 /// <since_tizen> 3 </since_tizen>
54 protected bool disposed = false;
59 /// <since_tizen> 3 </since_tizen>
64 isDisposeQueued = true;
65 DisposeQueue.Instance.Add(this);
72 /// <since_tizen> 3 </since_tizen>
75 //Throw excpetion if Dispose() is called in separate thread.
76 if (!Window.IsInstalled())
78 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
83 Dispose(DisposeTypes.Implicit);
87 Dispose(DisposeTypes.Explicit);
88 System.GC.SuppressFinalize(this);
95 /// <since_tizen> 3 </since_tizen>
96 protected virtual void Dispose(DisposeTypes type)
103 if(type == DisposeTypes.Explicit)
106 //Release your own managed resources here.
107 //You should release all of your own disposable objects here.
110 //Release your own unmanaged resources here.
111 //You should not access any managed member here except static instance.
112 //because the execution order of Finalizes is non-deterministic.
114 if (swigCPtr.Handle != global::System.IntPtr.Zero)
119 NDalicPINVOKE.delete_Vector2(swigCPtr);
121 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
127 /// The addition operator for A+B.
129 /// <param name="arg1">Size 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> 3 </since_tizen>
133 public static Size2D operator +(Size2D arg1, Size2D arg2)
135 return arg1.Add(arg2);
139 /// The subtraction operator for A-B.
141 /// <param name="arg1">Size A.</param>
142 /// <param name="arg2">Size to subtract B.</param>
143 /// <returns>A size containing the result of the subtraction.</returns>
144 /// <since_tizen> 3 </since_tizen>
145 public static Size2D operator -(Size2D arg1, Size2D 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> 3 </since_tizen>
156 public static Size2D operator -(Size2D arg1)
158 return arg1.Subtract();
162 /// The multiplication operator.
164 /// <param name="arg1">Size for multiplication.</param>
165 /// <param name="arg2">Size to multiply.</param>
166 /// <returns>A size containing the result of the multiplication.</returns>
167 /// <since_tizen> 3 </since_tizen>
168 public static Size2D operator *(Size2D arg1, Size2D arg2)
170 return arg1.Multiply(arg2);
174 /// The multiplication operator.
176 /// <param name="arg1">Size for multiplication</param>
177 /// <param name="arg2">The integer value to scale the size.</param>
178 /// <returns>A size containing the result of the scaling.</returns>
180 /// <since_tizen> 3 </since_tizen>
181 public static Size2D operator *(Size2D arg1, int arg2)
183 return arg1.Multiply(arg2);
187 /// The division operator.
189 /// <param name="arg1">Size for division.</param>
190 /// <param name="arg2">Size to divide.</param>
191 /// <returns>A size containing the result of the division.</returns>
192 /// <since_tizen> 3 </since_tizen>
193 public static Size2D operator /(Size2D arg1, Size2D arg2)
195 return arg1.Divide(arg2);
199 /// The division operator.
201 /// <param name="arg1">Size for division.</param>
202 /// <param name="arg2">The integer value to scale the size by.</param>
203 /// <returns>A size containing the result of the scaling.</returns>
204 /// <since_tizen> 3 </since_tizen>
205 public static Size2D operator /(Size2D arg1, int arg2)
207 return arg1.Divide(arg2);
211 /// The array subscript operator.
213 /// <param name="index">The subscript index.</param>
214 /// <returns>The float at the given index.</returns>
215 /// <since_tizen> 3 </since_tizen>
216 public float this[uint index]
220 return ValueOfIndex(index);
225 /// Gets the size from the pointer.
227 /// <param name="cPtr">The pointer of the size.</param>
228 /// <returns>Size</returns>
229 internal static Size2D GetSize2DFromPtr(global::System.IntPtr cPtr)
231 Size2D ret = new Size2D(cPtr, false);
232 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
239 /// <since_tizen> 3 </since_tizen>
240 public Size2D() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
242 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
248 /// <param name="x">The x (or width) component.</param>
249 /// <param name="y">The y (or height) component.</param>
250 /// <since_tizen> 3 </since_tizen>
251 public Size2D(int x, int y) : this(NDalicPINVOKE.new_Vector2__SWIG_1((float)x, (float)y), true)
253 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
256 private Size2D Add(Size2D rhs)
258 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Add(swigCPtr, Size2D.getCPtr(rhs)), true);
259 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
263 private Size2D Subtract(Size2D rhs)
265 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
266 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
271 private Size2D Multiply(Size2D rhs)
273 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
274 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
278 private Size2D Multiply(int rhs)
280 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, (float)rhs), true);
281 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
286 private Size2D Divide(Size2D rhs)
288 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
289 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
293 private Size2D Divide(int rhs)
295 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, (float)rhs), true);
296 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
300 private Size2D Subtract()
302 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Subtract__SWIG_1(swigCPtr), true);
303 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
308 /// Determines whether the specified object is equal to the current object.
310 /// <param name="obj">The object to compare with the current object.</param>
311 /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
312 public override bool Equals(System.Object obj)
314 Size2D size2D = obj as Size2D;
316 if (Width == size2D?.Width && Height == size2D?.Height)
324 /// Checks equality.<br />
325 /// Utilizes appropriate machine epsilon values.<br />
327 /// <param name="rhs">The size to test against.</param>
328 /// <returns>True if the sizes are equal.</returns>
329 /// <since_tizen> 3 </since_tizen>
330 public bool EqualTo(Size2D rhs)
332 bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, Size2D.getCPtr(rhs));
333 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
338 /// Checks inequality.<br />
339 /// Utilizes appropriate machine epsilon values.<br />
341 /// <param name="rhs">The size to test against.</param>
342 /// <returns>True if the sizes are not equal.</returns>
343 /// <since_tizen> 3 </since_tizen>
344 public bool NotEqualTo(Size2D rhs)
346 bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, Size2D.getCPtr(rhs));
347 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
351 private int ValueOfIndex(uint index)
353 int ret = (int)NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
354 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
359 /// The property for the width component of a size.
361 /// <since_tizen> 3 </since_tizen>
366 NDalicPINVOKE.Vector2_Width_set(swigCPtr, (float)value);
367 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
371 float ret = NDalicPINVOKE.Vector2_Width_get(swigCPtr);
372 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
378 /// The property for the height component of a size.
380 /// <since_tizen> 3 </since_tizen>
385 NDalicPINVOKE.Vector2_Height_set(swigCPtr, (float)value);
386 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
390 float ret = NDalicPINVOKE.Vector2_Height_get(swigCPtr);
391 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
397 /// The type cast operator, Size2D to Vector2.
399 /// <param name="size">An object of the Size2D type.</param>
400 /// <returns>return a Vector2 instance</returns>
401 /// <since_tizen> 3 </since_tizen>
402 public static implicit operator Vector2(Size2D size)
404 return new Vector2((float)size.Width, (float)size.Height);
408 /// The type cast operator, Vector2 to Size2D type.
410 /// <param name="vector2">An object of the Vector2 type.</param>
411 /// <returns>return a Size2D instance</returns>
412 /// <since_tizen> 3 </since_tizen>
413 public static implicit operator Size2D(Vector2 vector2)
415 return new Size2D((int)vector2.X, (int)vector2.Y);