Revert "[NUI] Refactoring Theme and StyleManager (#1981)" (#2013)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Size2D.cs
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 using System.ComponentModel;
18 using Tizen.NUI.Binding;
19 using System.ComponentModel;
20
21 namespace Tizen.NUI
22 {
23     /// <summary>
24     /// A two-dimensional size.
25     /// </summary>
26     /// <since_tizen> 3 </since_tizen>
27     [Tizen.NUI.Binding.TypeConverter(typeof(Size2DTypeConverter))]
28     public class Size2D : Disposable
29     {
30
31         private Size2DChangedCallback callback = null;
32
33         /// <summary>
34         /// The constructor.
35         /// </summary>
36         /// <remarks>
37         /// Size2D and Size are implicitly converted to each other, so these are compatible and can be replaced without any type casting. <br />
38         /// For example, the followings are possible. <br />
39         /// view.Size2D = new Size(10.0f, 10.0f, 10.0f); // be aware that here the depth value(10.0f) will be lost. <br />
40         /// view.Size = new Size2D(10, 10); // be aware that here the depth value is 0.0f by default. <br />
41         /// view.MinimumSize = new Size(10, 10, 0); <br />
42         /// Size Tmp = view.MaximumSize; //here Tmp.Depth will be 0.0f. <br />
43         /// </remarks>
44         /// <since_tizen> 3 </since_tizen>
45         public Size2D() : this(Interop.Vector2.new_Vector2__SWIG_0(), true)
46         {
47             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
48         }
49
50         /// <summary>
51         /// The constructor.
52         /// </summary>
53         /// <param name="width">The width component.</param>
54         /// <param name="height">The height component.</param>
55         /// <remarks>
56         /// Size2D and Size are implicitly converted to each other, so these are compatible and can be replaced without any type casting. <br />
57         /// For example, the followings are possible. <br />
58         /// view.Size2D = new Size(10.0f, 10.0f, 10.0f); // be aware that here the depth value(10.0f) will be lost. <br />
59         /// view.Size = new Size2D(10, 10); // be aware that here the depth value is 0.0f by default. <br />
60         /// view.MinimumSize = new Size(10, 10, 0); <br />
61         /// Size Tmp = view.MaximumSize; //here Tmp.Depth will be 0.0f. <br />
62         /// </remarks>
63         /// <since_tizen> 3 </since_tizen>
64         public Size2D(int width, int height) : this(Interop.Vector2.new_Vector2__SWIG_1((float)width, (float)height), true)
65         {
66             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
67         }
68
69         internal delegate void Size2DChangedCallback(int? width, int? height);
70
71         /// <summary>
72         /// The property for the width component of a size.
73         /// </summary>
74         /// <since_tizen> 3 </since_tizen>
75         public int Width
76         {
77             set
78             {
79                 Interop.Vector2.Vector2_Width_set(swigCPtr, (float)value);
80                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
81
82                 callback?.Invoke(value, null);
83             }
84             get
85             {
86                 float ret = Interop.Vector2.Vector2_Width_get(swigCPtr);
87                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
88                 return (int)ret;
89             }
90         }
91
92         /// <summary>
93         /// The property for the height component of a size.
94         /// </summary>
95         /// <since_tizen> 3 </since_tizen>
96         public int Height
97         {
98             set
99             {
100                 Interop.Vector2.Vector2_Height_set(swigCPtr, (float)value);
101                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
102
103                 callback?.Invoke(null, value);
104             }
105             get
106             {
107                 float ret = Interop.Vector2.Vector2_Height_get(swigCPtr);
108                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
109                 return (int)ret;
110             }
111         }
112
113         /// <summary>
114         /// The addition operator for A+B.
115         /// </summary>
116         /// <param name="arg1">Size A.</param>
117         /// <param name="arg2">Size to assign B.</param>
118         /// <returns>A size containing the result of the addition.</returns>
119         /// <since_tizen> 3 </since_tizen>
120         public static Size2D operator +(Size2D arg1, Size2D arg2)
121         {
122             return arg1.Add(arg2);
123         }
124
125         /// <summary>
126         /// The subtraction operator for A-B.
127         /// </summary>
128         /// <param name="arg1">Size A.</param>
129         /// <param name="arg2">Size to subtract B.</param>
130         /// <returns>A size containing the result of the subtraction.</returns>
131         /// <since_tizen> 3 </since_tizen>
132         public static Size2D operator -(Size2D arg1, Size2D arg2)
133         {
134             return arg1.Subtract(arg2);
135         }
136
137         /// <summary>
138         /// The unary negation operator.
139         /// </summary>
140         /// <param name="arg1">Size for unary negation.</param>
141         /// <returns>A size containing the negation.</returns>
142         /// <since_tizen> 3 </since_tizen>
143         public static Size2D operator -(Size2D arg1)
144         {
145             return arg1.Subtract();
146         }
147
148         /// <summary>
149         /// The multiplication operator.
150         /// </summary>
151         /// <param name="arg1">Size for multiplication.</param>
152         /// <param name="arg2">Size to multiply.</param>
153         /// <returns>A size containing the result of the multiplication.</returns>
154         /// <since_tizen> 3 </since_tizen>
155         public static Size2D operator *(Size2D arg1, Size2D arg2)
156         {
157             return arg1.Multiply(arg2);
158         }
159
160         /// <summary>
161         /// The multiplication operator.
162         /// </summary>
163         /// <param name="arg1">Size for multiplication</param>
164         /// <param name="arg2">The integer value to scale the size.</param>
165         /// <returns>A size containing the result of the scaling.</returns>
166
167         /// <since_tizen> 3 </since_tizen>
168         public static Size2D operator *(Size2D arg1, int arg2)
169         {
170             return arg1.Multiply(arg2);
171         }
172
173         /// <summary>
174         /// The division operator.
175         /// </summary>
176         /// <param name="arg1">Size for division.</param>
177         /// <param name="arg2">Size to divide.</param>
178         /// <returns>A size containing the result of the division.</returns>
179         /// <since_tizen> 3 </since_tizen>
180         public static Size2D operator /(Size2D arg1, Size2D arg2)
181         {
182             return arg1.Divide(arg2);
183         }
184
185         /// <summary>
186         /// The division operator.
187         /// </summary>
188         /// <param name="arg1">Size for division.</param>
189         /// <param name="arg2">The integer value to scale the size by.</param>
190         /// <returns>A size containing the result of the scaling.</returns>
191         /// <since_tizen> 3 </since_tizen>
192         public static Size2D operator /(Size2D arg1, int arg2)
193         {
194             return arg1.Divide(arg2);
195         }
196
197         /// <summary>
198         /// The type cast operator, Size2D to Vector2.
199         /// </summary>
200         /// <param name="size">An object of the Size2D type.</param>
201         /// <returns>return a Vector2 instance</returns>
202         /// <since_tizen> 3 </since_tizen>
203         public static implicit operator Vector2(Size2D size)
204         {
205             return new Vector2((float)size.Width, (float)size.Height);
206         }
207
208         /// <summary>
209         /// The type cast operator, Vector2 to Size2D type.
210         /// </summary>
211         /// <param name="vector2">An object of the Vector2 type.</param>
212         /// <returns>return a Size2D instance</returns>
213         /// <since_tizen> 3 </since_tizen>
214         public static implicit operator Size2D(Vector2 vector2)
215         {
216             return new Size2D((int)vector2.X, (int)vector2.Y);
217         }
218
219         /// <summary>
220         /// Implicit type cast operator, Size to Size2D
221         /// </summary>
222         /// <param name="size">The object of Size type.</param>
223         /// <since_tizen> none </since_tizen>
224         /// This will be public opened in tizen_next by ACR.
225         [EditorBrowsable(EditorBrowsableState.Never)]
226         public static implicit operator Size2D(Size size)
227         {
228             return new Size2D((int)size.Width, (int)size.Height);
229         }
230
231
232         /// <summary>
233         /// The array subscript operator.
234         /// </summary>
235         /// <param name="index">The subscript index.</param>
236         /// <returns>The float at the given index.</returns>
237         /// <since_tizen> 3 </since_tizen>
238         public float this[uint index]
239         {
240             get
241             {
242                 return ValueOfIndex(index);
243             }
244         }
245
246         /// <summary>
247         /// Determines whether the specified object is equal to the current object.
248         /// </summary>
249         /// <param name="obj">The object to compare with the current object.</param>
250         /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
251         public override bool Equals(System.Object obj)
252         {
253             Size2D size2D = obj as Size2D;
254             bool equal = false;
255             if (Width == size2D?.Width && Height == size2D?.Height)
256             {
257                 equal = true;
258             }
259             return equal;
260         }
261
262         /// <summary>
263         /// Gets the the hash code of this Size2D.
264         /// </summary>
265         /// <returns>The Hash Code.</returns>
266         /// <since_tizen> 6 </since_tizen>
267         public override int GetHashCode()
268         {
269             return swigCPtr.Handle.GetHashCode();
270         }
271
272         /// <summary>
273         /// Checks equality.<br />
274         /// Utilizes appropriate machine epsilon values.<br />
275         /// </summary>
276         /// <param name="rhs">The size to test against.</param>
277         /// <returns>True if the sizes are equal.</returns>
278         /// <since_tizen> 3 </since_tizen>
279         public bool EqualTo(Size2D rhs)
280         {
281             bool ret = Interop.Vector2.Vector2_EqualTo(swigCPtr, Size2D.getCPtr(rhs));
282             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
283             return ret;
284         }
285
286         /// <summary>
287         /// Checks inequality.<br />
288         /// Utilizes appropriate machine epsilon values.<br />
289         /// </summary>
290         /// <param name="rhs">The size to test against.</param>
291         /// <returns>True if the sizes are not equal.</returns>
292         /// <since_tizen> 3 </since_tizen>
293         public bool NotEqualTo(Size2D rhs)
294         {
295             bool ret = Interop.Vector2.Vector2_NotEqualTo(swigCPtr, Size2D.getCPtr(rhs));
296             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
297             return ret;
298         }
299
300         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Size2D obj)
301         {
302             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
303         }
304
305         /// <summary>
306         /// Gets the size from the pointer.
307         /// </summary>
308         /// <param name="cPtr">The pointer of the size.</param>
309         /// <returns>Size</returns>
310         internal static Size2D GetSize2DFromPtr(global::System.IntPtr cPtr)
311         {
312             Size2D ret = new Size2D(cPtr, false);
313             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
314             return ret;
315         }
316
317         internal Size2D(Size2DChangedCallback cb, int x, int y) : this(Interop.Vector2.new_Vector2__SWIG_1((float)x, (float)y), true)
318         {
319             callback = cb;
320             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
321         }
322
323         internal Size2D(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
324         {
325         }
326
327         /// This will not be public opened.
328         [EditorBrowsable(EditorBrowsableState.Never)]
329         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
330         {
331             Interop.Vector2.delete_Vector2(swigCPtr);
332         }
333
334         private Size2D Add(Size2D rhs)
335         {
336             Size2D ret = new Size2D(Interop.Vector2.Vector2_Add(swigCPtr, Size2D.getCPtr(rhs)), true);
337             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
338             return ret;
339         }
340
341         private Size2D Subtract(Size2D rhs)
342         {
343             Size2D ret = new Size2D(Interop.Vector2.Vector2_Subtract__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
344             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
345             return ret;
346         }
347
348         private Size2D Multiply(Size2D rhs)
349         {
350             Size2D ret = new Size2D(Interop.Vector2.Vector2_Multiply__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
351             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
352             return ret;
353         }
354
355         private Size2D Multiply(int rhs)
356         {
357             Size2D ret = new Size2D(Interop.Vector2.Vector2_Multiply__SWIG_1(swigCPtr, (float)rhs), true);
358             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
359             return ret;
360         }
361
362         private Size2D Divide(Size2D rhs)
363         {
364             Size2D ret = new Size2D(Interop.Vector2.Vector2_Divide__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
365             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
366             return ret;
367         }
368
369         private Size2D Divide(int rhs)
370         {
371             Size2D ret = new Size2D(Interop.Vector2.Vector2_Divide__SWIG_1(swigCPtr, (float)rhs), true);
372             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
373             return ret;
374         }
375
376         private Size2D Subtract()
377         {
378             Size2D ret = new Size2D(Interop.Vector2.Vector2_Subtract__SWIG_1(swigCPtr), true);
379             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
380             return ret;
381         }
382
383         private int ValueOfIndex(uint index)
384         {
385             int ret = (int)Interop.Vector2.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
386             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
387             return ret;
388         }
389     }
390 }