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;
27 protected bool swigCMemOwn;
29 internal Size2D(global::System.IntPtr cPtr, bool cMemoryOwn)
31 swigCMemOwn = cMemoryOwn;
32 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
35 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Size2D obj)
37 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
40 //A Flag to check who called Dispose(). (By User or DisposeQueue)
41 private bool isDisposeQueued = false;
42 //A Flat to check if it is already disposed.
43 protected bool disposed = false;
49 isDisposeQueued = true;
50 DisposeQueue.Instance.Add(this);
57 /// <since_tizen> 3 </since_tizen>
60 //Throw excpetion if Dispose() is called in separate thread.
61 if (!Window.IsInstalled())
63 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
68 Dispose(DisposeTypes.Implicit);
72 Dispose(DisposeTypes.Explicit);
73 System.GC.SuppressFinalize(this);
77 protected virtual void Dispose(DisposeTypes type)
84 if(type == DisposeTypes.Explicit)
87 //Release your own managed resources here.
88 //You should release all of your own disposable objects here.
91 //Release your own unmanaged resources here.
92 //You should not access any managed member here except static instance.
93 //because the execution order of Finalizes is non-deterministic.
95 if (swigCPtr.Handle != global::System.IntPtr.Zero)
100 NDalicPINVOKE.delete_Vector2(swigCPtr);
102 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
108 /// The addition operator for A+B.
110 /// <param name="arg1">Size A.</param>
111 /// <param name="arg2">Size to assign B.</param>
112 /// <returns>A size containing the result of the addition.</returns>
113 /// <since_tizen> 3 </since_tizen>
114 public static Size2D operator +(Size2D arg1, Size2D arg2)
116 return arg1.Add(arg2);
120 /// The subtraction operator for A-B.
122 /// <param name="arg1">Size A.</param>
123 /// <param name="arg2">Size to subtract B.</param>
124 /// <returns>A size containing the result of the subtraction.</returns>
125 /// <since_tizen> 3 </since_tizen>
126 public static Size2D operator -(Size2D arg1, Size2D arg2)
128 return arg1.Subtract(arg2);
132 /// The unary negation operator.
134 /// <param name="arg1">Size for unary negation.</param>
135 /// <returns>A size containing the negation.</returns>
136 /// <since_tizen> 3 </since_tizen>
137 public static Size2D operator -(Size2D arg1)
139 return arg1.Subtract();
143 /// The multiplication operator.
145 /// <param name="arg1">Size for multiplication.</param>
146 /// <param name="arg2">Size to multiply.</param>
147 /// <returns>A size containing the result of the multiplication.</returns>
148 /// <since_tizen> 3 </since_tizen>
149 public static Size2D operator *(Size2D arg1, Size2D arg2)
151 return arg1.Multiply(arg2);
155 /// The multiplication operator.
157 /// <param name="arg1">Size for multiplication</param>
158 /// <param name="arg2">The integer value to scale the size.</param>
159 /// <returns>A size containing the result of the scaling.</returns>
161 /// <since_tizen> 3 </since_tizen>
162 public static Size2D operator *(Size2D arg1, int arg2)
164 return arg1.Multiply(arg2);
168 /// The division operator.
170 /// <param name="arg1">Size for division.</param>
171 /// <param name="arg2">Size to divide.</param>
172 /// <returns>A size containing the result of the division.</returns>
173 /// <since_tizen> 3 </since_tizen>
174 public static Size2D operator /(Size2D arg1, Size2D arg2)
176 return arg1.Divide(arg2);
180 /// The division operator.
182 /// <param name="arg1">Size for division.</param>
183 /// <param name="arg2">The integer value to scale the size by.</param>
184 /// <returns>A size containing the result of the scaling.</returns>
185 /// <since_tizen> 3 </since_tizen>
186 public static Size2D operator /(Size2D arg1, int arg2)
188 return arg1.Divide(arg2);
192 /// The array subscript operator.
194 /// <param name="index">The subscript index.</param>
195 /// <returns>The float at the given index.</returns>
196 /// <since_tizen> 3 </since_tizen>
197 public float this[uint index]
201 return ValueOfIndex(index);
206 /// Gets the size from the pointer.
208 /// <param name="cPtr">The pointer of the size.</param>
209 /// <returns>Size</returns>
210 internal static Size2D GetSize2DFromPtr(global::System.IntPtr cPtr)
212 Size2D ret = new Size2D(cPtr, false);
213 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
220 /// <since_tizen> 3 </since_tizen>
221 public Size2D() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
223 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
229 /// <param name="x">The x (or width) component.</param>
230 /// <param name="y">The y (or height) component.</param>
231 /// <since_tizen> 3 </since_tizen>
232 public Size2D(int x, int y) : this(NDalicPINVOKE.new_Vector2__SWIG_1((float)x, (float)y), true)
234 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
237 private Size2D Add(Size2D rhs)
239 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Add(swigCPtr, Size2D.getCPtr(rhs)), true);
240 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
244 private Size2D Subtract(Size2D rhs)
246 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
247 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
252 private Size2D Multiply(Size2D rhs)
254 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
255 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
259 private Size2D Multiply(int rhs)
261 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, (float)rhs), true);
262 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
267 private Size2D Divide(Size2D rhs)
269 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
270 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
274 private Size2D Divide(int rhs)
276 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, (float)rhs), true);
277 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
281 private Size2D Subtract()
283 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Subtract__SWIG_1(swigCPtr), true);
284 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
289 /// Checks equality.<br>
290 /// Utilizes appropriate machine epsilon values.<br>
292 /// <param name="rhs">The size to test against.</param>
293 /// <returns>True if the sizes are equal.</returns>
294 /// <since_tizen> 3 </since_tizen>
295 public bool EqualTo(Size2D rhs)
297 bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, Size2D.getCPtr(rhs));
298 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
303 /// Checks inequality.<br>
304 /// Utilizes appropriate machine epsilon values.<br>
306 /// <param name="rhs">The size to test against.</param>
307 /// <returns>True if the sizes are not equal.</returns>
308 /// <since_tizen> 3 </since_tizen>
309 public bool NotEqualTo(Size2D rhs)
311 bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, Size2D.getCPtr(rhs));
312 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
316 private int ValueOfIndex(uint index)
318 int ret = (int)NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
319 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
324 /// The property for the width component of a size.
326 /// <since_tizen> 3 </since_tizen>
331 NDalicPINVOKE.Vector2_Width_set(swigCPtr, (float)value);
332 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
336 float ret = NDalicPINVOKE.Vector2_Width_get(swigCPtr);
337 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
343 /// The property for the height component of a size.
345 /// <since_tizen> 3 </since_tizen>
350 NDalicPINVOKE.Vector2_Height_set(swigCPtr, (float)value);
351 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
355 float ret = NDalicPINVOKE.Vector2_Height_get(swigCPtr);
356 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
362 /// The type cast operator, Size2D to Vector2.
364 /// <param name="size">An object of the Size2D type.</param>
365 /// <since_tizen> 3 </since_tizen>
366 public static implicit operator Vector2(Size2D size)
368 return new Vector2((float)size.Width, (float)size.Height);
372 /// The type cast operator, Vector2 to Size2D type.
374 /// <param name="vec">An object of the Vector2 type.</param>
375 /// <since_tizen> 3 </since_tizen>
376 public static implicit operator Size2D(Vector2 vec)
378 return new Size2D((int)vec.X, (int)vec.Y);
382 /// The type cast operator, Size2D to Uint16Pair.
384 /// <param name="size2d">An object of the Size2D type.</param>
385 /// <since_tizen> 4 </since_tizen>
386 public static implicit operator Uint16Pair(Size2D size2d)
388 return new Uint16Pair((uint)size2d.Width, (uint)size2d.Height);
392 /// The type cast operator, Uint16Pair to Size2D type.
394 /// <param name="pair">An object of the Vector2 type.</param>
395 /// <since_tizen> 4 </since_tizen>
396 public static implicit operator Size2D(Uint16Pair pair)
398 return new Size2D((int)pair.GetWidth(), (int)pair.GetWidth());