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.
22 /// A two-dimensional size.
24 public class Size2D : global::System.IDisposable
26 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
30 /// <since_tizen> 3 </since_tizen>
31 protected bool swigCMemOwn;
33 internal Size2D(global::System.IntPtr cPtr, bool cMemoryOwn)
35 swigCMemOwn = cMemoryOwn;
36 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
39 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Size2D obj)
41 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
44 //A Flag to check who called Dispose(). (By User or DisposeQueue)
45 private bool isDisposeQueued = false;
47 /// A Flat to check if it is already disposed.
49 /// <since_tizen> 3 </since_tizen>
50 protected bool disposed = false;
55 /// <since_tizen> 3 </since_tizen>
60 isDisposeQueued = true;
61 DisposeQueue.Instance.Add(this);
68 /// <since_tizen> 3 </since_tizen>
71 //Throw excpetion if Dispose() is called in separate thread.
72 if (!Window.IsInstalled())
74 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
79 Dispose(DisposeTypes.Implicit);
83 Dispose(DisposeTypes.Explicit);
84 System.GC.SuppressFinalize(this);
91 /// <since_tizen> 3 </since_tizen>
92 protected virtual void Dispose(DisposeTypes type)
99 if(type == DisposeTypes.Explicit)
102 //Release your own managed resources here.
103 //You should release all of your own disposable objects here.
106 //Release your own unmanaged resources here.
107 //You should not access any managed member here except static instance.
108 //because the execution order of Finalizes is non-deterministic.
110 if (swigCPtr.Handle != global::System.IntPtr.Zero)
115 NDalicPINVOKE.delete_Vector2(swigCPtr);
117 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
123 /// The addition operator for A+B.
125 /// <param name="arg1">Size A.</param>
126 /// <param name="arg2">Size to assign B.</param>
127 /// <returns>A size containing the result of the addition.</returns>
128 /// <since_tizen> 3 </since_tizen>
129 public static Size2D operator +(Size2D arg1, Size2D arg2)
131 return arg1.Add(arg2);
135 /// The subtraction operator for A-B.
137 /// <param name="arg1">Size A.</param>
138 /// <param name="arg2">Size to subtract B.</param>
139 /// <returns>A size containing the result of the subtraction.</returns>
140 /// <since_tizen> 3 </since_tizen>
141 public static Size2D operator -(Size2D arg1, Size2D arg2)
143 return arg1.Subtract(arg2);
147 /// The unary negation operator.
149 /// <param name="arg1">Size for unary negation.</param>
150 /// <returns>A size containing the negation.</returns>
151 /// <since_tizen> 3 </since_tizen>
152 public static Size2D operator -(Size2D arg1)
154 return arg1.Subtract();
158 /// The multiplication operator.
160 /// <param name="arg1">Size for multiplication.</param>
161 /// <param name="arg2">Size to multiply.</param>
162 /// <returns>A size containing the result of the multiplication.</returns>
163 /// <since_tizen> 3 </since_tizen>
164 public static Size2D operator *(Size2D arg1, Size2D arg2)
166 return arg1.Multiply(arg2);
170 /// The multiplication operator.
172 /// <param name="arg1">Size for multiplication</param>
173 /// <param name="arg2">The integer value to scale the size.</param>
174 /// <returns>A size containing the result of the scaling.</returns>
176 /// <since_tizen> 3 </since_tizen>
177 public static Size2D operator *(Size2D arg1, int arg2)
179 return arg1.Multiply(arg2);
183 /// The division operator.
185 /// <param name="arg1">Size for division.</param>
186 /// <param name="arg2">Size to divide.</param>
187 /// <returns>A size containing the result of the division.</returns>
188 /// <since_tizen> 3 </since_tizen>
189 public static Size2D operator /(Size2D arg1, Size2D arg2)
191 return arg1.Divide(arg2);
195 /// The division operator.
197 /// <param name="arg1">Size for division.</param>
198 /// <param name="arg2">The integer value to scale the size by.</param>
199 /// <returns>A size containing the result of the scaling.</returns>
200 /// <since_tizen> 3 </since_tizen>
201 public static Size2D operator /(Size2D arg1, int arg2)
203 return arg1.Divide(arg2);
207 /// The array subscript operator.
209 /// <param name="index">The subscript index.</param>
210 /// <returns>The float at the given index.</returns>
211 /// <since_tizen> 3 </since_tizen>
212 public float this[uint index]
216 return ValueOfIndex(index);
221 /// Gets the size from the pointer.
223 /// <param name="cPtr">The pointer of the size.</param>
224 /// <returns>Size</returns>
225 internal static Size2D GetSize2DFromPtr(global::System.IntPtr cPtr)
227 Size2D ret = new Size2D(cPtr, false);
228 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
235 /// <since_tizen> 3 </since_tizen>
236 public Size2D() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
238 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
244 /// <param name="x">The x (or width) component.</param>
245 /// <param name="y">The y (or height) component.</param>
246 /// <since_tizen> 3 </since_tizen>
247 public Size2D(int x, int y) : this(NDalicPINVOKE.new_Vector2__SWIG_1((float)x, (float)y), true)
249 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
252 private Size2D Add(Size2D rhs)
254 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Add(swigCPtr, Size2D.getCPtr(rhs)), true);
255 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
259 private Size2D Subtract(Size2D rhs)
261 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
262 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
267 private Size2D Multiply(Size2D rhs)
269 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
270 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
274 private Size2D Multiply(int rhs)
276 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, (float)rhs), true);
277 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
282 private Size2D Divide(Size2D rhs)
284 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
285 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
289 private Size2D Divide(int rhs)
291 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, (float)rhs), true);
292 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
296 private Size2D Subtract()
298 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Subtract__SWIG_1(swigCPtr), true);
299 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
304 /// Checks equality.<br />
305 /// Utilizes appropriate machine epsilon values.<br />
307 /// <param name="rhs">The size to test against.</param>
308 /// <returns>True if the sizes are equal.</returns>
309 /// <since_tizen> 3 </since_tizen>
310 public bool EqualTo(Size2D rhs)
312 bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, Size2D.getCPtr(rhs));
313 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
318 /// Checks inequality.<br />
319 /// Utilizes appropriate machine epsilon values.<br />
321 /// <param name="rhs">The size to test against.</param>
322 /// <returns>True if the sizes are not equal.</returns>
323 /// <since_tizen> 3 </since_tizen>
324 public bool NotEqualTo(Size2D rhs)
326 bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, Size2D.getCPtr(rhs));
327 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
331 private int ValueOfIndex(uint index)
333 int ret = (int)NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
334 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
339 /// The property for the width component of a size.
341 /// <since_tizen> 3 </since_tizen>
346 NDalicPINVOKE.Vector2_Width_set(swigCPtr, (float)value);
347 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
351 float ret = NDalicPINVOKE.Vector2_Width_get(swigCPtr);
352 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
358 /// The property for the height component of a size.
360 /// <since_tizen> 3 </since_tizen>
365 NDalicPINVOKE.Vector2_Height_set(swigCPtr, (float)value);
366 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
370 float ret = NDalicPINVOKE.Vector2_Height_get(swigCPtr);
371 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
377 /// The type cast operator, Size2D to Vector2.
379 /// <param name="size">An object of the Size2D type.</param>
380 /// <since_tizen> 3 </since_tizen>
381 public static implicit operator Vector2(Size2D size)
383 return new Vector2((float)size.Width, (float)size.Height);
387 /// The type cast operator, Vector2 to Size2D type.
389 /// <param name="vec">An object of the Vector2 type.</param>
390 /// <since_tizen> 3 </since_tizen>
391 public static implicit operator Size2D(Vector2 vec)
393 return new Size2D((int)vec.X, (int)vec.Y);
397 /// The type cast operator, Size2D to Uint16Pair.
399 /// <param name="size2d">An object of the Size2D type.</param>
400 /// <since_tizen> 4 </since_tizen>
401 public static implicit operator Uint16Pair(Size2D size2d)
403 return new Uint16Pair((uint)size2d.Width, (uint)size2d.Height);
407 /// The type cast operator, Uint16Pair to Size2D type.
409 /// <param name="pair">An object of the Vector2 type.</param>
410 /// <since_tizen> 4 </since_tizen>
411 public static implicit operator Size2D(Uint16Pair pair)
413 return new Size2D((int)pair.GetWidth(), (int)pair.GetWidth());