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 /// <since_tizen> 3 </since_tizen>
25 public class Size2D : global::System.IDisposable
27 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
31 /// <since_tizen> 3 </since_tizen>
32 protected bool swigCMemOwn;
34 internal Size2D(global::System.IntPtr cPtr, bool cMemoryOwn)
36 swigCMemOwn = cMemoryOwn;
37 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
40 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Size2D obj)
42 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
45 //A Flag to check who called Dispose(). (By User or DisposeQueue)
46 private bool isDisposeQueued = false;
48 /// A Flat to check if it is already disposed.
50 /// <since_tizen> 3 </since_tizen>
51 protected bool disposed = false;
56 /// <since_tizen> 3 </since_tizen>
61 isDisposeQueued = true;
62 DisposeQueue.Instance.Add(this);
69 /// <since_tizen> 3 </since_tizen>
72 //Throw excpetion if Dispose() is called in separate thread.
73 if (!Window.IsInstalled())
75 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
80 Dispose(DisposeTypes.Implicit);
84 Dispose(DisposeTypes.Explicit);
85 System.GC.SuppressFinalize(this);
92 /// <since_tizen> 3 </since_tizen>
93 protected virtual void Dispose(DisposeTypes type)
100 if(type == DisposeTypes.Explicit)
103 //Release your own managed resources here.
104 //You should release all of your own disposable objects here.
107 //Release your own unmanaged resources here.
108 //You should not access any managed member here except static instance.
109 //because the execution order of Finalizes is non-deterministic.
111 if (swigCPtr.Handle != global::System.IntPtr.Zero)
116 NDalicPINVOKE.delete_Vector2(swigCPtr);
118 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
124 /// The addition operator for A+B.
126 /// <param name="arg1">Size A.</param>
127 /// <param name="arg2">Size to assign B.</param>
128 /// <returns>A size containing the result of the addition.</returns>
129 /// <since_tizen> 3 </since_tizen>
130 public static Size2D operator +(Size2D arg1, Size2D arg2)
132 return arg1.Add(arg2);
136 /// The subtraction operator for A-B.
138 /// <param name="arg1">Size A.</param>
139 /// <param name="arg2">Size to subtract B.</param>
140 /// <returns>A size containing the result of the subtraction.</returns>
141 /// <since_tizen> 3 </since_tizen>
142 public static Size2D operator -(Size2D arg1, Size2D arg2)
144 return arg1.Subtract(arg2);
148 /// The unary negation operator.
150 /// <param name="arg1">Size for unary negation.</param>
151 /// <returns>A size containing the negation.</returns>
152 /// <since_tizen> 3 </since_tizen>
153 public static Size2D operator -(Size2D arg1)
155 return arg1.Subtract();
159 /// The multiplication operator.
161 /// <param name="arg1">Size for multiplication.</param>
162 /// <param name="arg2">Size to multiply.</param>
163 /// <returns>A size containing the result of the multiplication.</returns>
164 /// <since_tizen> 3 </since_tizen>
165 public static Size2D operator *(Size2D arg1, Size2D arg2)
167 return arg1.Multiply(arg2);
171 /// The multiplication operator.
173 /// <param name="arg1">Size for multiplication</param>
174 /// <param name="arg2">The integer value to scale the size.</param>
175 /// <returns>A size containing the result of the scaling.</returns>
177 /// <since_tizen> 3 </since_tizen>
178 public static Size2D operator *(Size2D arg1, int arg2)
180 return arg1.Multiply(arg2);
184 /// The division operator.
186 /// <param name="arg1">Size for division.</param>
187 /// <param name="arg2">Size to divide.</param>
188 /// <returns>A size containing the result of the division.</returns>
189 /// <since_tizen> 3 </since_tizen>
190 public static Size2D operator /(Size2D arg1, Size2D arg2)
192 return arg1.Divide(arg2);
196 /// The division operator.
198 /// <param name="arg1">Size for division.</param>
199 /// <param name="arg2">The integer value to scale the size by.</param>
200 /// <returns>A size containing the result of the scaling.</returns>
201 /// <since_tizen> 3 </since_tizen>
202 public static Size2D operator /(Size2D arg1, int arg2)
204 return arg1.Divide(arg2);
208 /// The array subscript operator.
210 /// <param name="index">The subscript index.</param>
211 /// <returns>The float at the given index.</returns>
212 /// <since_tizen> 3 </since_tizen>
213 public float this[uint index]
217 return ValueOfIndex(index);
222 /// Gets the size from the pointer.
224 /// <param name="cPtr">The pointer of the size.</param>
225 /// <returns>Size</returns>
226 internal static Size2D GetSize2DFromPtr(global::System.IntPtr cPtr)
228 Size2D ret = new Size2D(cPtr, false);
229 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
236 /// <since_tizen> 3 </since_tizen>
237 public Size2D() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
239 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
245 /// <param name="x">The x (or width) component.</param>
246 /// <param name="y">The y (or height) component.</param>
247 /// <since_tizen> 3 </since_tizen>
248 public Size2D(int x, int y) : this(NDalicPINVOKE.new_Vector2__SWIG_1((float)x, (float)y), true)
250 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
253 private Size2D Add(Size2D rhs)
255 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Add(swigCPtr, Size2D.getCPtr(rhs)), true);
256 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
260 private Size2D Subtract(Size2D rhs)
262 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
263 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
268 private Size2D Multiply(Size2D rhs)
270 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
271 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
275 private Size2D Multiply(int rhs)
277 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, (float)rhs), true);
278 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
283 private Size2D Divide(Size2D rhs)
285 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
286 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
290 private Size2D Divide(int rhs)
292 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, (float)rhs), true);
293 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
297 private Size2D Subtract()
299 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Subtract__SWIG_1(swigCPtr), true);
300 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
305 /// Checks equality.<br />
306 /// Utilizes appropriate machine epsilon values.<br />
308 /// <param name="rhs">The size to test against.</param>
309 /// <returns>True if the sizes are equal.</returns>
310 /// <since_tizen> 3 </since_tizen>
311 public bool EqualTo(Size2D rhs)
313 bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, Size2D.getCPtr(rhs));
314 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
319 /// Checks inequality.<br />
320 /// Utilizes appropriate machine epsilon values.<br />
322 /// <param name="rhs">The size to test against.</param>
323 /// <returns>True if the sizes are not equal.</returns>
324 /// <since_tizen> 3 </since_tizen>
325 public bool NotEqualTo(Size2D rhs)
327 bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, Size2D.getCPtr(rhs));
328 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
332 private int ValueOfIndex(uint index)
334 int ret = (int)NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
335 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
340 /// The property for the width component of a size.
342 /// <since_tizen> 3 </since_tizen>
347 NDalicPINVOKE.Vector2_Width_set(swigCPtr, (float)value);
348 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
352 float ret = NDalicPINVOKE.Vector2_Width_get(swigCPtr);
353 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
359 /// The property for the height component of a size.
361 /// <since_tizen> 3 </since_tizen>
366 NDalicPINVOKE.Vector2_Height_set(swigCPtr, (float)value);
367 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
371 float ret = NDalicPINVOKE.Vector2_Height_get(swigCPtr);
372 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
378 /// The type cast operator, Size2D to Vector2.
380 /// <param name="size">An object of the Size2D type.</param>
381 /// <returns>return a Vector2 instance</returns>
382 /// <since_tizen> 3 </since_tizen>
383 public static implicit operator Vector2(Size2D size)
385 return new Vector2((float)size.Width, (float)size.Height);
389 /// The type cast operator, Vector2 to Size2D type.
391 /// <param name="vector2">An object of the Vector2 type.</param>
392 /// <returns>return a Size2D instance</returns>
393 /// <since_tizen> 3 </since_tizen>
394 public static implicit operator Size2D(Vector2 vector2)
396 return new Size2D((int)vector2.X, (int)vector2.Y);