2 * Copyright (c) 2019 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.
18 using System.ComponentModel;
19 using Tizen.NUI.Binding;
25 /// A two-dimensional size.
27 /// <since_tizen> 3 </since_tizen>
28 [Tizen.NUI.Binding.TypeConverter(typeof(Size2DTypeConverter))]
29 public class Size2D : Disposable, ICloneable
32 private Size2DChangedCallback callback = null;
38 /// Size2D and Size are implicitly converted to each other, so these are compatible and can be replaced without any type casting. <br />
39 /// For example, the followings are possible. <br />
40 /// view.Size2D = new Size(10.0f, 10.0f, 10.0f); // be aware that here the depth value(10.0f) will be lost. <br />
41 /// view.Size = new Size2D(10, 10); // be aware that here the depth value is 0.0f by default. <br />
42 /// view.MinimumSize = new Size(10, 10, 0); <br />
43 /// Size Tmp = view.MaximumSize; //here Tmp.Depth will be 0.0f. <br />
45 /// <since_tizen> 3 </since_tizen>
46 public Size2D() : this(Interop.Vector2.new_Vector2__SWIG_0(), true)
48 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
54 /// <param name="width">The width component.</param>
55 /// <param name="height">The height component.</param>
57 /// Size2D and Size are implicitly converted to each other, so these are compatible and can be replaced without any type casting. <br />
58 /// For example, the followings are possible. <br />
59 /// view.Size2D = new Size(10.0f, 10.0f, 10.0f); // be aware that here the depth value(10.0f) will be lost. <br />
60 /// view.Size = new Size2D(10, 10); // be aware that here the depth value is 0.0f by default. <br />
61 /// view.MinimumSize = new Size(10, 10, 0); <br />
62 /// Size Tmp = view.MaximumSize; //here Tmp.Depth will be 0.0f. <br />
64 /// <since_tizen> 3 </since_tizen>
65 public Size2D(int width, int height) : this(Interop.Vector2.new_Vector2__SWIG_1((float)width, (float)height), true)
67 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
70 internal delegate void Size2DChangedCallback(int? width, int? height);
73 /// The property for the width component of a size.
75 /// <since_tizen> 3 </since_tizen>
76 [Obsolete("Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Size2D(...) constructor")]
81 Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Size2D(...) constructor");
83 Interop.Vector2.Vector2_Width_set(swigCPtr, (float)value);
84 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
86 callback?.Invoke(value, null);
90 float ret = Interop.Vector2.Vector2_Width_get(swigCPtr);
91 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
97 /// The property for the height component of a size.
99 /// <since_tizen> 3 </since_tizen>
100 [Obsolete("Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Size2D(...) constructor")]
105 Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Size2D(...) constructor");
107 Interop.Vector2.Vector2_Height_set(swigCPtr, (float)value);
108 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
110 callback?.Invoke(null, value);
114 float ret = Interop.Vector2.Vector2_Height_get(swigCPtr);
115 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
121 /// The addition operator for A+B.
123 /// <param name="arg1">Size A.</param>
124 /// <param name="arg2">Size to assign B.</param>
125 /// <returns>A size containing the result of the addition.</returns>
126 /// <since_tizen> 3 </since_tizen>
127 public static Size2D operator +(Size2D arg1, Size2D arg2)
129 return arg1.Add(arg2);
133 /// The subtraction operator for A-B.
135 /// <param name="arg1">Size A.</param>
136 /// <param name="arg2">Size to subtract B.</param>
137 /// <returns>A size containing the result of the subtraction.</returns>
138 /// <since_tizen> 3 </since_tizen>
139 public static Size2D operator -(Size2D arg1, Size2D arg2)
141 return arg1.Subtract(arg2);
145 /// The unary negation operator.
147 /// <param name="arg1">Size for unary negation.</param>
148 /// <returns>A size containing the negation.</returns>
149 /// <since_tizen> 3 </since_tizen>
150 public static Size2D operator -(Size2D arg1)
152 return arg1.Subtract();
156 /// The multiplication operator.
158 /// <param name="arg1">Size for multiplication.</param>
159 /// <param name="arg2">Size to multiply.</param>
160 /// <returns>A size containing the result of the multiplication.</returns>
161 /// <since_tizen> 3 </since_tizen>
162 public static Size2D operator *(Size2D arg1, Size2D arg2)
164 return arg1.Multiply(arg2);
168 /// The multiplication operator.
170 /// <param name="arg1">Size for multiplication</param>
171 /// <param name="arg2">The integer value to scale the size.</param>
172 /// <returns>A size containing the result of the scaling.</returns>
174 /// <since_tizen> 3 </since_tizen>
175 public static Size2D operator *(Size2D arg1, int arg2)
177 return arg1.Multiply(arg2);
181 /// The division operator.
183 /// <param name="arg1">Size for division.</param>
184 /// <param name="arg2">Size to divide.</param>
185 /// <returns>A size containing the result of the division.</returns>
186 /// <since_tizen> 3 </since_tizen>
187 public static Size2D operator /(Size2D arg1, Size2D arg2)
189 return arg1.Divide(arg2);
193 /// The division operator.
195 /// <param name="arg1">Size for division.</param>
196 /// <param name="arg2">The integer value to scale the size by.</param>
197 /// <returns>A size containing the result of the scaling.</returns>
198 /// <since_tizen> 3 </since_tizen>
199 public static Size2D operator /(Size2D arg1, int arg2)
201 return arg1.Divide(arg2);
205 /// The type cast operator, Size2D to Vector2.
207 /// <param name="size">An object of the Size2D type.</param>
208 /// <returns>return a Vector2 instance</returns>
209 /// <since_tizen> 3 </since_tizen>
210 public static implicit operator Vector2(Size2D size)
212 return new Vector2((float)size.Width, (float)size.Height);
216 /// The type cast operator, Vector2 to Size2D type.
218 /// <param name="vector2">An object of the Vector2 type.</param>
219 /// <returns>return a Size2D instance</returns>
220 /// <since_tizen> 3 </since_tizen>
221 public static implicit operator Size2D(Vector2 vector2)
223 return new Size2D((int)vector2.X, (int)vector2.Y);
227 /// Implicit type cast operator, Size to Size2D
229 /// <param name="size">The object of Size type.</param>
230 /// <since_tizen> none </since_tizen>
231 /// This will be public opened in tizen_next by ACR.
232 [EditorBrowsable(EditorBrowsableState.Never)]
233 public static implicit operator Size2D(Size size)
235 return new Size2D((int)size.Width, (int)size.Height);
240 /// The array subscript operator.
242 /// <param name="index">The subscript index.</param>
243 /// <returns>The float at the given index.</returns>
244 /// <since_tizen> 3 </since_tizen>
245 public float this[uint index]
249 return ValueOfIndex(index);
254 /// Determines whether the specified object is equal to the current object.
256 /// <param name="obj">The object to compare with the current object.</param>
257 /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
258 public override bool Equals(System.Object obj)
260 Size2D size2D = obj as Size2D;
262 if (Width == size2D?.Width && Height == size2D?.Height)
270 /// Gets the the hash code of this Size2D.
272 /// <returns>The Hash Code.</returns>
273 /// <since_tizen> 6 </since_tizen>
274 public override int GetHashCode()
276 return swigCPtr.Handle.GetHashCode();
280 /// Checks 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 /// <since_tizen> 3 </since_tizen>
286 public bool EqualTo(Size2D rhs)
288 bool ret = Interop.Vector2.Vector2_EqualTo(swigCPtr, Size2D.getCPtr(rhs));
289 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
294 /// Checks inequality.<br />
295 /// Utilizes appropriate machine epsilon values.<br />
297 /// <param name="rhs">The size to test against.</param>
298 /// <returns>True if the sizes are not equal.</returns>
299 /// <since_tizen> 3 </since_tizen>
300 public bool NotEqualTo(Size2D rhs)
302 bool ret = Interop.Vector2.Vector2_NotEqualTo(swigCPtr, Size2D.getCPtr(rhs));
303 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
308 [EditorBrowsable(EditorBrowsableState.Never)]
309 public object Clone() => new Size2D(Width, Height);
311 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Size2D obj)
313 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
317 /// Gets the size from the pointer.
319 /// <param name="cPtr">The pointer of the size.</param>
320 /// <returns>Size</returns>
321 internal static Size2D GetSize2DFromPtr(global::System.IntPtr cPtr)
323 Size2D ret = new Size2D(cPtr, false);
324 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
328 internal Size2D(Size2DChangedCallback cb, int x, int y) : this(Interop.Vector2.new_Vector2__SWIG_1((float)x, (float)y), true)
331 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
334 internal Size2D(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
338 /// This will not be public opened.
339 [EditorBrowsable(EditorBrowsableState.Never)]
340 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
342 Interop.Vector2.delete_Vector2(swigCPtr);
345 private Size2D Add(Size2D rhs)
347 Size2D ret = new Size2D(Interop.Vector2.Vector2_Add(swigCPtr, Size2D.getCPtr(rhs)), true);
348 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
352 private Size2D Subtract(Size2D rhs)
354 Size2D ret = new Size2D(Interop.Vector2.Vector2_Subtract__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
355 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
359 private Size2D Multiply(Size2D rhs)
361 Size2D ret = new Size2D(Interop.Vector2.Vector2_Multiply__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
362 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
366 private Size2D Multiply(int rhs)
368 Size2D ret = new Size2D(Interop.Vector2.Vector2_Multiply__SWIG_1(swigCPtr, (float)rhs), true);
369 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
373 private Size2D Divide(Size2D rhs)
375 Size2D ret = new Size2D(Interop.Vector2.Vector2_Divide__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
376 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
380 private Size2D Divide(int rhs)
382 Size2D ret = new Size2D(Interop.Vector2.Vector2_Divide__SWIG_1(swigCPtr, (float)rhs), true);
383 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
387 private Size2D Subtract()
389 Size2D ret = new Size2D(Interop.Vector2.Vector2_Subtract__SWIG_1(swigCPtr), true);
390 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
394 private int ValueOfIndex(uint index)
396 int ret = (int)Interop.Vector2.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
397 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();