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 //NUI Dispose Pattern written by Jinwoo Nam(jjw.nam)
42 //A Flag to check who called Dispose(). (By User or DisposeQueue)
43 private bool isDisposeQueued = false;
44 //A Flat to check if it is already disposed.
45 protected bool disposed = false;
51 isDisposeQueued = true;
52 DisposeQueue.Instance.Add(this);
61 //Throw excpetion if Dispose() is called in separate thread.
62 if (!Window.IsInstalled())
64 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
69 Dispose(DisposeTypes.Implicit);
73 Dispose(DisposeTypes.Explicit);
74 System.GC.SuppressFinalize(this);
78 protected virtual void Dispose(DisposeTypes type)
85 if(type == DisposeTypes.Explicit)
88 //Release your own managed resources here.
89 //You should release all of your own disposable objects here.
92 //Release your own unmanaged resources here.
93 //You should not access any managed member here except static instance.
94 //because the execution order of Finalizes is non-deterministic.
96 if (swigCPtr.Handle != global::System.IntPtr.Zero)
101 NDalicPINVOKE.delete_Vector2(swigCPtr);
103 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
109 /// Addition operator for A+B
111 /// <param name="arg1">Size, A</param>
112 /// <param name="arg2">Size to assign, B</param>
113 /// <returns>A Size containing the result of the addition</returns>
114 public static Size2D operator +(Size2D arg1, Size2D arg2)
116 return arg1.Add(arg2);
120 /// 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 public static Size2D operator -(Size2D arg1, Size2D arg2)
127 return arg1.Subtract(arg2);
131 /// Unary negation operator.
133 /// <param name="arg1">Size for unary negation</param>
134 /// <returns>A Size containg the negation</returns>
135 public static Size2D operator -(Size2D arg1)
137 return arg1.Subtract();
141 /// Multiplication operator.
143 /// <param name="arg1">Size for multiplication</param>
144 /// <param name="arg2">The Size to multipl</param>
145 /// <returns>A Size containing the result of the multiplication</returns>
146 public static Size2D operator *(Size2D arg1, Size2D arg2)
148 return arg1.Multiply(arg2);
152 /// Multiplication operator.
154 /// <param name="arg1">Size for multiplication</param>
155 /// <param name="arg2">The int value to scale the Size</param>
156 /// <returns>A Size containing the result of the scaling</returns>
158 public static Size2D operator *(Size2D arg1, int arg2)
160 return arg1.Multiply(arg2);
164 /// Division operator.
166 /// <param name="arg1">Size for division</param>
167 /// <param name="arg2">The Size to divide</param>
168 /// <returns>A Size containing the result of the division></returns>
169 public static Size2D operator /(Size2D arg1, Size2D arg2)
171 return arg1.Divide(arg2);
175 /// Division operator.
177 /// <param name="arg1">Size for division</param>
178 /// <param name="arg2">The int value to scale the Size by</param>
179 /// <returns>A Size containing the result of the scaling</returns>
180 public static Size2D operator /(Size2D arg1, int arg2)
182 return arg1.Divide(arg2);
186 /// Array subscript operator.
188 /// <param name="index">Subscript index</param>
189 /// <returns>The float at the given index</returns>
190 public float this[uint index]
194 return ValueOfIndex(index);
199 /// Get Size from pointer.
201 /// <param name="cPtr">Pointer of the Size</param>
202 /// <returns>Size</returns>
203 internal static Size2D GetSize2DFromPtr(global::System.IntPtr cPtr)
205 Size2D ret = new Size2D(cPtr, false);
206 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
213 public Size2D() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
215 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
221 /// <param name="x">x (or width) component</param>
222 /// <param name="y">y (or height) component</param>
223 public Size2D(int x, int y) : this(NDalicPINVOKE.new_Vector2__SWIG_1((float)x, (float)y), true)
225 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
228 private Size2D Add(Size2D rhs)
230 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Add(swigCPtr, Size2D.getCPtr(rhs)), true);
231 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
235 private Size2D Subtract(Size2D rhs)
237 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
238 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
243 private Size2D Multiply(Size2D rhs)
245 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
246 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
250 private Size2D Multiply(int rhs)
252 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, (float)rhs), true);
253 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
258 private Size2D Divide(Size2D rhs)
260 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
261 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
265 private Size2D Divide(int rhs)
267 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, (float)rhs), true);
268 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
272 private Size2D Subtract()
274 Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Subtract__SWIG_1(swigCPtr), true);
275 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
280 /// Check equality.<br>
281 /// Utilizes appropriate machine epsilon values.<br>
283 /// <param name="rhs">The Size to test against</param>
284 /// <returns>True if the Sizes are equal</returns>
285 public bool EqualTo(Size2D rhs)
287 bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, Size2D.getCPtr(rhs));
288 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
293 /// Check inequality.<br>
294 /// Utilizes appropriate machine epsilon values.<br>
296 /// <param name="rhs">The Size to test against</param>
297 /// <returns>True if the Sizes are not equal</returns>
298 public bool NotEqualTo(Size2D rhs)
300 bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, Size2D.getCPtr(rhs));
301 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
305 private int ValueOfIndex(uint index)
307 int ret = (int)NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
308 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
313 /// Property for width component of Size
319 NDalicPINVOKE.Vector2_Width_set(swigCPtr, (float)value);
320 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
324 float ret = NDalicPINVOKE.Vector2_Width_get(swigCPtr);
325 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
331 /// Property for height component of Size
337 NDalicPINVOKE.Vector2_Height_set(swigCPtr, (float)value);
338 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
342 float ret = NDalicPINVOKE.Vector2_Height_get(swigCPtr);
343 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
349 /// Type cast operator, Size2D to Vector2.
351 /// <param name="size">Object of Size2D type</param>
352 public static implicit operator Vector2(Size2D size)
354 return new Vector2((float)size.Width, (float)size.Height);
358 /// Type cast operator, Vector2 to Size2D type.
360 /// <param name="vec">Object of Vector2 type</param>
361 public static implicit operator Size2D(Vector2 vec)
363 return new Size2D((int)vec.X, (int)vec.Y);