[NUI] Add ThemeManager (#2034)
[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;
18 using System.ComponentModel;
19 using Tizen.NUI.Binding;
20 using System;
21
22 namespace Tizen.NUI
23 {
24     /// <summary>
25     /// A two-dimensional size.
26     /// </summary>
27     /// <since_tizen> 3 </since_tizen>
28     [Tizen.NUI.Binding.TypeConverter(typeof(Size2DTypeConverter))]
29     public class Size2D : Disposable, ICloneable
30     {
31
32         private Size2DChangedCallback callback = null;
33
34         /// <summary>
35         /// The constructor.
36         /// </summary>
37         /// <remarks>
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 />
44         /// </remarks>
45         /// <since_tizen> 3 </since_tizen>
46         public Size2D() : this(Interop.Vector2.new_Vector2__SWIG_0(), true)
47         {
48             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
49         }
50
51         /// <summary>
52         /// The constructor.
53         /// </summary>
54         /// <param name="width">The width component.</param>
55         /// <param name="height">The height component.</param>
56         /// <remarks>
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 />
63         /// </remarks>
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)
66         {
67             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
68         }
69
70         internal delegate void Size2DChangedCallback(int? width, int? height);
71
72         /// <summary>
73         /// The property for the width component of a size.
74         /// </summary>
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")]
77         public int Width
78         {
79             set
80             {
81                 Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Size2D(...) constructor");
82
83                 Interop.Vector2.Vector2_Width_set(swigCPtr, (float)value);
84                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
85
86                 callback?.Invoke(value, null);
87             }
88             get
89             {
90                 float ret = Interop.Vector2.Vector2_Width_get(swigCPtr);
91                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
92                 return (int)ret;
93             }
94         }
95
96         /// <summary>
97         /// The property for the height component of a size.
98         /// </summary>
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")]
101         public int Height
102         {
103             set
104             {
105                 Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Size2D(...) constructor");
106
107                 Interop.Vector2.Vector2_Height_set(swigCPtr, (float)value);
108                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
109
110                 callback?.Invoke(null, value);
111             }
112             get
113             {
114                 float ret = Interop.Vector2.Vector2_Height_get(swigCPtr);
115                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
116                 return (int)ret;
117             }
118         }
119
120         /// <summary>
121         /// The addition operator for A+B.
122         /// </summary>
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)
128         {
129             return arg1.Add(arg2);
130         }
131
132         /// <summary>
133         /// The subtraction operator for A-B.
134         /// </summary>
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)
140         {
141             return arg1.Subtract(arg2);
142         }
143
144         /// <summary>
145         /// The unary negation operator.
146         /// </summary>
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)
151         {
152             return arg1.Subtract();
153         }
154
155         /// <summary>
156         /// The multiplication operator.
157         /// </summary>
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)
163         {
164             return arg1.Multiply(arg2);
165         }
166
167         /// <summary>
168         /// The multiplication operator.
169         /// </summary>
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>
173
174         /// <since_tizen> 3 </since_tizen>
175         public static Size2D operator *(Size2D arg1, int arg2)
176         {
177             return arg1.Multiply(arg2);
178         }
179
180         /// <summary>
181         /// The division operator.
182         /// </summary>
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)
188         {
189             return arg1.Divide(arg2);
190         }
191
192         /// <summary>
193         /// The division operator.
194         /// </summary>
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)
200         {
201             return arg1.Divide(arg2);
202         }
203
204         /// <summary>
205         /// The type cast operator, Size2D to Vector2.
206         /// </summary>
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)
211         {
212             return new Vector2((float)size.Width, (float)size.Height);
213         }
214
215         /// <summary>
216         /// The type cast operator, Vector2 to Size2D type.
217         /// </summary>
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)
222         {
223             return new Size2D((int)vector2.X, (int)vector2.Y);
224         }
225
226         /// <summary>
227         /// Implicit type cast operator, Size to Size2D
228         /// </summary>
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)
234         {
235             return new Size2D((int)size.Width, (int)size.Height);
236         }
237
238
239         /// <summary>
240         /// The array subscript operator.
241         /// </summary>
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]
246         {
247             get
248             {
249                 return ValueOfIndex(index);
250             }
251         }
252
253         /// <summary>
254         /// Determines whether the specified object is equal to the current object.
255         /// </summary>
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)
259         {
260             Size2D size2D = obj as Size2D;
261             bool equal = false;
262             if (Width == size2D?.Width && Height == size2D?.Height)
263             {
264                 equal = true;
265             }
266             return equal;
267         }
268
269         /// <summary>
270         /// Gets the the hash code of this Size2D.
271         /// </summary>
272         /// <returns>The Hash Code.</returns>
273         /// <since_tizen> 6 </since_tizen>
274         public override int GetHashCode()
275         {
276             return swigCPtr.Handle.GetHashCode();
277         }
278
279         /// <summary>
280         /// Checks equality.<br />
281         /// Utilizes appropriate machine epsilon values.<br />
282         /// </summary>
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)
287         {
288             bool ret = Interop.Vector2.Vector2_EqualTo(swigCPtr, Size2D.getCPtr(rhs));
289             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
290             return ret;
291         }
292
293         /// <summary>
294         /// Checks inequality.<br />
295         /// Utilizes appropriate machine epsilon values.<br />
296         /// </summary>
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)
301         {
302             bool ret = Interop.Vector2.Vector2_NotEqualTo(swigCPtr, Size2D.getCPtr(rhs));
303             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
304             return ret;
305         }
306
307         /// <inheritdoc/>
308         [EditorBrowsable(EditorBrowsableState.Never)]
309         public object Clone() => new Size2D(Width, Height);
310
311         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Size2D obj)
312         {
313             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
314         }
315
316         /// <summary>
317         /// Gets the size from the pointer.
318         /// </summary>
319         /// <param name="cPtr">The pointer of the size.</param>
320         /// <returns>Size</returns>
321         internal static Size2D GetSize2DFromPtr(global::System.IntPtr cPtr)
322         {
323             Size2D ret = new Size2D(cPtr, false);
324             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
325             return ret;
326         }
327
328         internal Size2D(Size2DChangedCallback cb, int x, int y) : this(Interop.Vector2.new_Vector2__SWIG_1((float)x, (float)y), true)
329         {
330             callback = cb;
331             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
332         }
333
334         internal Size2D(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
335         {
336         }
337
338         /// This will not be public opened.
339         [EditorBrowsable(EditorBrowsableState.Never)]
340         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
341         {
342             Interop.Vector2.delete_Vector2(swigCPtr);
343         }
344
345         private Size2D Add(Size2D rhs)
346         {
347             Size2D ret = new Size2D(Interop.Vector2.Vector2_Add(swigCPtr, Size2D.getCPtr(rhs)), true);
348             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
349             return ret;
350         }
351
352         private Size2D Subtract(Size2D rhs)
353         {
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();
356             return ret;
357         }
358
359         private Size2D Multiply(Size2D rhs)
360         {
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();
363             return ret;
364         }
365
366         private Size2D Multiply(int rhs)
367         {
368             Size2D ret = new Size2D(Interop.Vector2.Vector2_Multiply__SWIG_1(swigCPtr, (float)rhs), true);
369             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
370             return ret;
371         }
372
373         private Size2D Divide(Size2D rhs)
374         {
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();
377             return ret;
378         }
379
380         private Size2D Divide(int rhs)
381         {
382             Size2D ret = new Size2D(Interop.Vector2.Vector2_Divide__SWIG_1(swigCPtr, (float)rhs), true);
383             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
384             return ret;
385         }
386
387         private Size2D Subtract()
388         {
389             Size2D ret = new Size2D(Interop.Vector2.Vector2_Subtract__SWIG_1(swigCPtr), true);
390             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
391             return ret;
392         }
393
394         private int ValueOfIndex(uint index)
395         {
396             int ret = (int)Interop.Vector2.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
397             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
398             return ret;
399         }
400     }
401 }