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;
23 /// A two-dimensional size.
25 /// <since_tizen> 3 </since_tizen>
26 [Tizen.NUI.Binding.TypeConverter(typeof(Size2DTypeConverter))]
27 public class Size2D : global::System.IDisposable
32 /// <since_tizen> 3 </since_tizen>
33 protected bool swigCMemOwn;
36 /// A Flat to check if it is already disposed.
38 /// <since_tizen> 3 </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;
46 private Size2DChangedCallback callback = null;
51 /// <since_tizen> 3 </since_tizen>
52 public Size2D() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
54 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
60 /// <param name="x">The x (or width) component.</param>
61 /// <param name="y">The y (or height) component.</param>
62 /// <since_tizen> 3 </since_tizen>
63 public Size2D(int x, int y) : this(NDalicPINVOKE.new_Vector2__SWIG_1((float)x, (float)y), true)
65 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
71 /// <since_tizen> 3 </since_tizen>
76 isDisposeQueued = true;
77 DisposeQueue.Instance.Add(this);
81 internal delegate void Size2DChangedCallback(int width, int height);
84 /// The property for the width component of a size.
86 /// <since_tizen> 3 </since_tizen>
91 NDalicPINVOKE.Vector2_Width_set(swigCPtr, (float)value);
92 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
94 callback?.Invoke(Width, Height);
98 float ret = NDalicPINVOKE.Vector2_Width_get(swigCPtr);
99 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
105 /// The property for the height component of a size.
107 /// <since_tizen> 3 </since_tizen>
112 NDalicPINVOKE.Vector2_Height_set(swigCPtr, (float)value);
113 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
115 callback?.Invoke(Width, Height);
119 float ret = NDalicPINVOKE.Vector2_Height_get(swigCPtr);
120 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
126 /// The addition operator for A+B.
128 /// <param name="arg1">Size A.</param>
129 /// <param name="arg2">Size to assign B.</param>
130 /// <returns>A size containing the result of the addition.</returns>
131 /// <since_tizen> 3 </since_tizen>
132 public static Size2D operator +(Size2D arg1, Size2D arg2)
134 return arg1.Add(arg2);
138 /// The subtraction operator for A-B.
140 /// <param name="arg1">Size A.</param>
141 /// <param name="arg2">Size to subtract B.</param>
142 /// <returns>A size containing the result of the subtraction.</returns>
143 /// <since_tizen> 3 </since_tizen>
144 public static Size2D operator -(Size2D arg1, Size2D arg2)
146 return arg1.Subtract(arg2);
150 /// The unary negation operator.
152 /// <param name="arg1">Size for unary negation.</param>
153 /// <returns>A size containing the negation.</returns>
154 /// <since_tizen> 3 </since_tizen>
155 public static Size2D operator -(Size2D arg1)
157 return arg1.Subtract();
161 /// The multiplication operator.
163 /// <param name="arg1">Size for multiplication.</param>
164 /// <param name="arg2">Size to multiply.</param>
165 /// <returns>A size containing the result of the multiplication.</returns>
166 /// <since_tizen> 3 </since_tizen>
167 public static Size2D operator *(Size2D arg1, Size2D arg2)
169 return arg1.Multiply(arg2);
173 /// The multiplication operator.
175 /// <param name="arg1">Size for multiplication</param>
176 /// <param name="arg2">The integer value to scale the size.</param>
177 /// <returns>A size containing the result of the scaling.</returns>
179 /// <since_tizen> 3 </since_tizen>
180 public static Size2D operator *(Size2D arg1, int arg2)
182 return arg1.Multiply(arg2);
186 /// The division operator.
188 /// <param name="arg1">Size for division.</param>
189 /// <param name="arg2">Size to divide.</param>
190 /// <returns>A size containing the result of the division.</returns>
191 /// <since_tizen> 3 </since_tizen>
192 public static Size2D operator /(Size2D arg1, Size2D arg2)
194 return arg1.Divide(arg2);
198 /// The division operator.
200 /// <param name="arg1">Size for division.</param>
201 /// <param name="arg2">The integer value to scale the size by.</param>
202 /// <returns>A size containing the result of the scaling.</returns>
203 /// <since_tizen> 3 </since_tizen>
204 public static Size2D operator /(Size2D arg1, int arg2)
206 return arg1.Divide(arg2);
210 /// The type cast operator, Size2D to Vector2.
212 /// <param name="size">An object of the Size2D type.</param>
213 /// <returns>return a Vector2 instance</returns>
214 /// <since_tizen> 3 </since_tizen>
215 public static implicit operator Vector2(Size2D size)
217 return new Vector2((float)size.Width, (float)size.Height);
221 /// The type cast operator, Vector2 to Size2D type.
223 /// <param name="vector2">An object of the Vector2 type.</param>
224 /// <returns>return a Size2D instance</returns>
225 /// <since_tizen> 3 </since_tizen>
226 public static implicit operator Size2D(Vector2 vector2)
228 return new Size2D((int)vector2.X, (int)vector2.Y);
232 /// The array subscript operator.
234 /// <param name="index">The subscript index.</param>
235 /// <returns>The float at the given index.</returns>
236 /// <since_tizen> 3 </since_tizen>
237 public float this[uint index]
241 return ValueOfIndex(index);
248 /// <since_tizen> 3 </since_tizen>
249 public void Dispose()
251 //Throw excpetion if Dispose() is called in separate thread.
252 if (!Window.IsInstalled())
254 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
259 Dispose(DisposeTypes.Implicit);
263 Dispose(DisposeTypes.Explicit);
264 System.GC.SuppressFinalize(this);
269 /// Determines whether the specified object is equal to the current object.
271 /// <param name="obj">The object to compare with the current object.</param>
272 /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
273 public override bool Equals(System.Object obj)
275 Size2D size2D = obj as Size2D;
277 if (Width == size2D?.Width && Height == size2D?.Height)
285 /// Gets the the hash code of this Size2D.
287 /// <returns>The Hash Code.</returns>
288 /// <since_tizen> 5 </since_tizen>
289 public override int GetHashCode()
291 return Width.GetHashCode();
295 /// Checks equality.<br />
296 /// Utilizes appropriate machine epsilon values.<br />
298 /// <param name="rhs">The size to test against.</param>
299 /// <returns>True if the sizes are equal.</returns>
300 /// <since_tizen> 3 </since_tizen>
301 public bool EqualTo(Size2D rhs)
303 bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, Size2D.getCPtr(rhs));
304 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
309 /// Checks inequality.<br />
310 /// Utilizes appropriate machine epsilon values.<br />
312 /// <param name="rhs">The size to test against.</param>
313 /// <returns>True if the sizes are not equal.</returns>
314 /// <since_tizen> 3 </since_tizen>
315 public bool NotEqualTo(Size2D rhs)
317 bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, Size2D.getCPtr(rhs));
318 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
322 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Size2D obj)
324 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
328 /// Gets the size from the pointer.
330 /// <param name="cPtr">The pointer of the size.</param>
331 /// <returns>Size</returns>
332 internal static Size2D GetSize2DFromPtr(global::System.IntPtr cPtr)
334 Size2D ret = new Size2D(cPtr, false);
335 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
339 internal Size2D(Size2DChangedCallback cb, int x, int y) : this(NDalicPINVOKE.new_Vector2__SWIG_1((float)x, (float)y), true)
342 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
345 internal Size2D(global::System.IntPtr cPtr, bool cMemoryOwn)
347 swigCMemOwn = cMemoryOwn;
348 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
354 /// <since_tizen> 3 </since_tizen>
355 protected virtual void Dispose(DisposeTypes type)
362 if (type == DisposeTypes.Explicit)
365 //Release your own managed resources here.
366 //You should release all of your own disposable objects here.
369 //Release your own unmanaged resources here.
370 //You should not access any managed member here except static instance.
371 //because the execution order of Finalizes is non-deterministic.
373 if (swigCPtr.Handle != global::System.IntPtr.Zero)
378 NDalicPINVOKE.delete_Vector2(swigCPtr);
380 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
385 private Size2D Add(Size2D rhs)
387 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Add(swigCPtr, Size2D.getCPtr(rhs)), true);
388 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
392 private Size2D Subtract(Size2D rhs)
394 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
395 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
399 private Size2D Multiply(Size2D rhs)
401 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
402 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
406 private Size2D Multiply(int rhs)
408 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, (float)rhs), true);
409 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
413 private Size2D Divide(Size2D rhs)
415 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
416 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
420 private Size2D Divide(int rhs)
422 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, (float)rhs), true);
423 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
427 private Size2D Subtract()
429 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Subtract__SWIG_1(swigCPtr), true);
430 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
434 private int ValueOfIndex(uint index)
436 int ret = (int)NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
437 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();