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);
59 //Throw excpetion if Dispose() is called in separate thread.
60 if (!Window.IsInstalled())
62 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
67 Dispose(DisposeTypes.Implicit);
71 Dispose(DisposeTypes.Explicit);
72 System.GC.SuppressFinalize(this);
76 protected virtual void Dispose(DisposeTypes type)
83 if(type == DisposeTypes.Explicit)
86 //Release your own managed resources here.
87 //You should release all of your own disposable objects here.
90 //Release your own unmanaged resources here.
91 //You should not access any managed member here except static instance.
92 //because the execution order of Finalizes is non-deterministic.
94 if (swigCPtr.Handle != global::System.IntPtr.Zero)
99 NDalicPINVOKE.delete_Vector2(swigCPtr);
101 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
107 /// Addition operator for A+B
109 /// <param name="arg1">Size, A</param>
110 /// <param name="arg2">Size to assign, B</param>
111 /// <returns>A Size containing the result of the addition</returns>
112 public static Size2D operator +(Size2D arg1, Size2D arg2)
114 return arg1.Add(arg2);
118 /// Subtraction operator for A-B
120 /// <param name="arg1">Size, A</param>
121 /// <param name="arg2">Size to subtract, B</param>
122 /// <returns>A Size containing the result of the subtraction</returns>
123 public static Size2D operator -(Size2D arg1, Size2D arg2)
125 return arg1.Subtract(arg2);
129 /// Unary negation operator.
131 /// <param name="arg1">Size for unary negation</param>
132 /// <returns>A Size containg the negation</returns>
133 public static Size2D operator -(Size2D arg1)
135 return arg1.Subtract();
139 /// Multiplication operator.
141 /// <param name="arg1">Size for multiplication</param>
142 /// <param name="arg2">The Size to multipl</param>
143 /// <returns>A Size containing the result of the multiplication</returns>
144 public static Size2D operator *(Size2D arg1, Size2D arg2)
146 return arg1.Multiply(arg2);
150 /// Multiplication operator.
152 /// <param name="arg1">Size for multiplication</param>
153 /// <param name="arg2">The int value to scale the Size</param>
154 /// <returns>A Size containing the result of the scaling</returns>
156 public static Size2D operator *(Size2D arg1, int arg2)
158 return arg1.Multiply(arg2);
162 /// Division operator.
164 /// <param name="arg1">Size for division</param>
165 /// <param name="arg2">The Size to divide</param>
166 /// <returns>A Size containing the result of the division></returns>
167 public static Size2D operator /(Size2D arg1, Size2D arg2)
169 return arg1.Divide(arg2);
173 /// Division operator.
175 /// <param name="arg1">Size for division</param>
176 /// <param name="arg2">The int value to scale the Size by</param>
177 /// <returns>A Size containing the result of the scaling</returns>
178 public static Size2D operator /(Size2D arg1, int arg2)
180 return arg1.Divide(arg2);
184 /// Array subscript operator.
186 /// <param name="index">Subscript index</param>
187 /// <returns>The float at the given index</returns>
188 public float this[uint index]
192 return ValueOfIndex(index);
197 /// Get Size from pointer.
199 /// <param name="cPtr">Pointer of the Size</param>
200 /// <returns>Size</returns>
201 internal static Size2D GetSize2DFromPtr(global::System.IntPtr cPtr)
203 Size2D ret = new Size2D(cPtr, false);
204 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
211 public Size2D() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
213 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
219 /// <param name="x">x (or width) component</param>
220 /// <param name="y">y (or height) component</param>
221 public Size2D(int x, int y) : this(NDalicPINVOKE.new_Vector2__SWIG_1((float)x, (float)y), true)
223 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
226 private Size2D Add(Size2D rhs)
228 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Add(swigCPtr, Size2D.getCPtr(rhs)), true);
229 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
233 private Size2D Subtract(Size2D rhs)
235 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
236 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
241 private Size2D Multiply(Size2D rhs)
243 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
244 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
248 private Size2D Multiply(int rhs)
250 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, (float)rhs), true);
251 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
256 private Size2D Divide(Size2D rhs)
258 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
259 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
263 private Size2D Divide(int rhs)
265 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, (float)rhs), true);
266 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
270 private Size2D Subtract()
272 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Subtract__SWIG_1(swigCPtr), true);
273 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
278 /// Check equality.<br>
279 /// Utilizes appropriate machine epsilon values.<br>
281 /// <param name="rhs">The Size to test against</param>
282 /// <returns>True if the Sizes are equal</returns>
283 public bool EqualTo(Size2D rhs)
285 bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, Size2D.getCPtr(rhs));
286 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
291 /// Check inequality.<br>
292 /// Utilizes appropriate machine epsilon values.<br>
294 /// <param name="rhs">The Size to test against</param>
295 /// <returns>True if the Sizes are not equal</returns>
296 public bool NotEqualTo(Size2D rhs)
298 bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, Size2D.getCPtr(rhs));
299 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
303 private int ValueOfIndex(uint index)
305 int ret = (int)NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
306 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
311 /// Property for width component of Size
317 NDalicPINVOKE.Vector2_Width_set(swigCPtr, (float)value);
318 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
322 float ret = NDalicPINVOKE.Vector2_Width_get(swigCPtr);
323 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
329 /// Property for height component of Size
335 NDalicPINVOKE.Vector2_Height_set(swigCPtr, (float)value);
336 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
340 float ret = NDalicPINVOKE.Vector2_Height_get(swigCPtr);
341 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
347 /// Type cast operator, Size2D to Vector2.
349 /// <param name="size">Object of Size2D type</param>
350 public static implicit operator Vector2(Size2D size)
352 return new Vector2((float)size.Width, (float)size.Height);
356 /// Type cast operator, Vector2 to Size2D type.
358 /// <param name="vec">Object of Vector2 type</param>
359 public static implicit operator Size2D(Vector2 vec)
361 return new Size2D((int)vec.X, (int)vec.Y);
365 /// Type cast operator, Size2D to Uint16Pair.
367 /// <param name="size2d">Object of Size2D type</param>
368 public static implicit operator Uint16Pair(Size2D size2d)
370 return new Uint16Pair((uint)size2d.Width, (uint)size2d.Height);
374 /// Type cast operator, Uint16Pair to Size2D type.
376 /// <param name="pair">Object of Vector2 type</param>
377 public static implicit operator Size2D(Uint16Pair pair)
379 return new Size2D((int)pair.GetWidth(), (int)pair.GetWidth());