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.
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 internal delegate void Size2DChangedCallback(int width, int height);
257 private Size2DChangedCallback callback = null;
258 internal Size2D(Size2DChangedCallback cb, int x, int y) : this(NDalicPINVOKE.new_Vector2__SWIG_1((float)x, (float)y), true)
261 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
264 private Size2D Add(Size2D rhs)
266 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Add(swigCPtr, Size2D.getCPtr(rhs)), true);
267 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
271 private Size2D Subtract(Size2D rhs)
273 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
274 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
279 private Size2D Multiply(Size2D rhs)
281 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
282 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
286 private Size2D Multiply(int rhs)
288 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, (float)rhs), true);
289 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
294 private Size2D Divide(Size2D rhs)
296 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
297 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
301 private Size2D Divide(int rhs)
303 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, (float)rhs), true);
304 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
308 private Size2D Subtract()
310 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Subtract__SWIG_1(swigCPtr), true);
311 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
316 /// Determines whether the specified object is equal to the current object.
318 /// <param name="obj">The object to compare with the current object.</param>
319 /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
320 public override bool Equals(System.Object obj)
322 Size2D size2D = obj as Size2D;
324 if (Width == size2D?.Width && Height == size2D?.Height)
332 /// Checks equality.<br />
333 /// Utilizes appropriate machine epsilon values.<br />
335 /// <param name="rhs">The size to test against.</param>
336 /// <returns>True if the sizes are equal.</returns>
337 /// <since_tizen> 3 </since_tizen>
338 public bool EqualTo(Size2D rhs)
340 bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, Size2D.getCPtr(rhs));
341 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
346 /// Checks inequality.<br />
347 /// Utilizes appropriate machine epsilon values.<br />
349 /// <param name="rhs">The size to test against.</param>
350 /// <returns>True if the sizes are not equal.</returns>
351 /// <since_tizen> 3 </since_tizen>
352 public bool NotEqualTo(Size2D rhs)
354 bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, Size2D.getCPtr(rhs));
355 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
359 private int ValueOfIndex(uint index)
361 int ret = (int)NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
362 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
367 /// The property for the width component of a size.
369 /// <since_tizen> 3 </since_tizen>
374 NDalicPINVOKE.Vector2_Width_set(swigCPtr, (float)value);
375 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
377 callback?.Invoke(Width, Height);
381 float ret = NDalicPINVOKE.Vector2_Width_get(swigCPtr);
382 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
388 /// The property for the height component of a size.
390 /// <since_tizen> 3 </since_tizen>
395 NDalicPINVOKE.Vector2_Height_set(swigCPtr, (float)value);
396 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
398 callback?.Invoke(Width, Height);
402 float ret = NDalicPINVOKE.Vector2_Height_get(swigCPtr);
403 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
409 /// The type cast operator, Size2D to Vector2.
411 /// <param name="size">An object of the Size2D type.</param>
412 /// <returns>return a Vector2 instance</returns>
413 /// <since_tizen> 3 </since_tizen>
414 public static implicit operator Vector2(Size2D size)
416 return new Vector2((float)size.Width, (float)size.Height);
420 /// The type cast operator, Vector2 to Size2D type.
422 /// <param name="vector2">An object of the Vector2 type.</param>
423 /// <returns>return a Size2D instance</returns>
424 /// <since_tizen> 3 </since_tizen>
425 public static implicit operator Size2D(Vector2 vector2)
427 return new Size2D((int)vector2.X, (int)vector2.Y);