f2077e0c131fa107b0c23f94d5b008b67d853027
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Utility / GraphicsTypeExtensions.cs
1 using System.ComponentModel;
2
3 namespace Tizen.NUI
4 {
5     /// <summary>
6     /// The GraphicTypeExtensions class is graphics type converter for pixel based object.
7     /// Density independent pixel(dp) unit is our basic target type and you can get converted value by ToDp(),
8     /// and you can get original pixel by ToDp().
9     /// One dp is a virtual pixel unit that's roughly equal to one pixel on a medium-density(160dpi) screen.
10     /// See <see cref="Tizen.NUI.GraphicsTypeManager" /> and <see cref="Tizen.NUI.GraphicsTypeConverter" /> also.
11     /// </summary>
12     /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
13     [EditorBrowsable(EditorBrowsableState.Never)]
14     public static class GraphicsTypeExtensions
15     {
16         /// <summary>
17         /// Converter float pixel to dp.
18         /// 100.0f.ToDp() = 50.0f in 320dpi display.
19         /// </summary>
20         /// <param name="pixel">The float pixel unit value to be converted dp unit.</param>
21         /// <returns>The float dp unit value.</returns>
22         /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
23         [EditorBrowsable(EditorBrowsableState.Never)]
24         public static float ToDp(this float pixel)
25         {
26             return GraphicsTypeManager.Instance.ConvertFromPixel(pixel);
27         }
28
29         /// <summary>
30         /// Converter float dp to pixel.
31         /// 100.0f.ToPixel() = 200.0f in 320dpi display.
32         /// </summary>
33         /// <param name="dp">The float dp unit value to be converted pixel unit.</param>
34         /// <returns>The float pixel unit value.</returns>
35         /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
36         [EditorBrowsable(EditorBrowsableState.Never)]
37         public static float ToPixel(this float dp)
38         {
39             return GraphicsTypeManager.Instance.ConvertToPixel(dp);
40         }
41
42         /// <summary>
43         /// Converter int pixel to dp.
44         /// 100.ToDp() = 50 in 320dpi display.
45         /// </summary>
46         /// <param name="pixel">The int pixel unit value to be converted dp unit.</param>
47         /// <returns>The int dp unit value.</returns>
48         /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
49         [EditorBrowsable(EditorBrowsableState.Never)]
50         public static int ToDp(this int pixel)
51         {
52             return (int)GraphicsTypeManager.Instance.ConvertFromPixel(pixel);
53         }
54
55         /// <summary>
56         /// Converter int dp to pixel.
57         /// 100.ToPixel() = 200 in 320dpi display.
58         /// </summary>
59         /// <param name="dp">The int dp unit value to be converted pixel unit.</param>
60         /// <returns>The int pixel unit value.</returns>
61         /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
62         [EditorBrowsable(EditorBrowsableState.Never)]
63         public static int ToPixel(this int dp)
64         {
65             return (int)GraphicsTypeManager.Instance.ConvertToPixel(dp);
66         }
67
68         /// <summary>
69         /// Converter Size pixel to dp.
70         /// Size(100.0f, 100.0f).ToDp() = Size(50.0f, 50.0f) in 320dpi display.
71         /// </summary>
72         /// <param name="pixel">The Size pixel unit value to be converted dp unit.</param>
73         /// <returns>The Size dp unit value.</returns>
74         /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
75         [EditorBrowsable(EditorBrowsableState.Never)]
76         public static Size ToDp(this Size pixel)
77         {
78             if (pixel == null) return null;
79             return new Size(GraphicsTypeManager.Instance.ConvertFromPixel(pixel.Width),
80                             GraphicsTypeManager.Instance.ConvertFromPixel(pixel.Height));
81         }
82
83         /// <summary>
84         /// Converter Size dp to pixel.
85         /// Size(100.0f, 100.0f).ToPixel() = Size(200.0f, 200.0f) in 320dpi display.
86         /// </summary>
87         /// <param name="dp">The Size dp unit value to be converted pixel unit.</param>
88         /// <returns>The Size pixel unit value.</returns>
89         /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
90         [EditorBrowsable(EditorBrowsableState.Never)]
91         public static Size ToPixel(this Size dp)
92         {
93             if (dp == null) return null;
94             return new Size(GraphicsTypeManager.Instance.ConvertToPixel(dp.Width),
95                             GraphicsTypeManager.Instance.ConvertToPixel(dp.Height));
96         }
97
98         /// <summary>
99         /// Converter Size2D pixel to dp.
100         /// Size2D(100, 100).ToDp() = Size2D(50, 50) in 320dpi display.
101         /// </summary>
102         /// <param name="pixel">The Size2D pixel unit value to be converted dp unit.</param>
103         /// <returns>The Size2D dp unit value.</returns>
104         /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
105         [EditorBrowsable(EditorBrowsableState.Never)]
106         public static Size2D ToDp(this Size2D pixel)
107         {
108             if (pixel == null) return null;
109             return new Size2D((int)GraphicsTypeManager.Instance.ConvertFromPixel(pixel.Width),
110                               (int)GraphicsTypeManager.Instance.ConvertFromPixel(pixel.Height));
111         }
112
113         /// <summary>
114         /// Converter Size2D dp to pixel.
115         /// Size2D(100, 100).ToPixel() = Size(200, 200) in 320dpi display.
116         /// </summary>
117         /// <param name="dp">The Size2D dp unit value to be converted pixel unit.</param>
118         /// <returns>The Size2D pixel unit value.</returns>
119         /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
120         [EditorBrowsable(EditorBrowsableState.Never)]
121         public static Size2D ToPixel(this Size2D dp)
122         {
123             if (dp == null) return null;
124             return new Size2D((int)GraphicsTypeManager.Instance.ConvertToPixel(dp.Width),
125                               (int)GraphicsTypeManager.Instance.ConvertToPixel(dp.Height));
126         }
127
128         /// <summary>
129         /// Converter Position pixel to dp.
130         /// Position(100.0f, 100.0f).ToDp() = Position(50.0f, 50.0f) in 320dpi display.
131         /// </summary>
132         /// <param name="pixel">The Position pixel unit value to be converted dp unit.</param>
133         /// <returns>The Position dp unit value.</returns>
134         /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
135         [EditorBrowsable(EditorBrowsableState.Never)]
136         public static Position ToDp(this Position pixel)
137         {
138             if (pixel == null) return null;
139             return new Position(GraphicsTypeManager.Instance.ConvertFromPixel(pixel.X),
140                                 GraphicsTypeManager.Instance.ConvertFromPixel(pixel.Y));
141         }
142
143         /// <summary>
144         /// Converter Position dp to pixel.
145         /// Position(100.0f, 100.0f).ToPixel() = Position(200.0f, 200.0f) in 320dpi display.
146         /// </summary>
147         /// <param name="dp">The Position dp unit value to be converted pixel unit.</param>
148         /// <returns>The Position pixel unit value.</returns>
149         /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
150         [EditorBrowsable(EditorBrowsableState.Never)]
151         public static Position ToPixel(this Position dp)
152         {
153             if (dp == null) return null;
154             return new Position(GraphicsTypeManager.Instance.ConvertToPixel(dp.X),
155                                 GraphicsTypeManager.Instance.ConvertToPixel(dp.Y));
156         }
157
158         /// <summary>
159         /// Converter Position2D pixel to dp.
160         /// Position2D(100.0f, 100.0f).ToDp() = Position2D(50.0f, 50.0f) in 320dpi display.
161         /// </summary>
162         /// <param name="pixel">The Position2D pixel unit value to be converted dp unit.</param>
163         /// <returns>The Position2D dp unit value.</returns>
164         /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
165         [EditorBrowsable(EditorBrowsableState.Never)]
166         public static Position2D ToDp(this Position2D pixel)
167         {
168             if (pixel == null) return null;
169             return new Position2D((int)GraphicsTypeManager.Instance.ConvertFromPixel(pixel.X),
170                                   (int)GraphicsTypeManager.Instance.ConvertFromPixel(pixel.Y));
171         }
172
173         /// <summary>
174         /// Converter Position2D dp to pixel.
175         /// Position2D(100, 100).ToPixel() = Position2D(200, 200) in 320dpi display.
176         /// </summary>
177         /// <param name="dp">The Position2D dp unit value to be converted pixel unit.</param>
178         /// <returns>The Position2D pixel unit value.</returns>
179         /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
180         [EditorBrowsable(EditorBrowsableState.Never)]
181         public static Position2D ToPixel(this Position2D dp)
182         {
183             if (dp == null) return null;
184             return new Position2D((int)GraphicsTypeManager.Instance.ConvertToPixel(dp.X),
185                                   (int)GraphicsTypeManager.Instance.ConvertToPixel(dp.Y));
186         }
187
188         /// <summary>
189         /// Converter Rectangle pixel to dp.
190         /// Rectangle(100, 100, 100, 100).ToDp() = Rectangle(50, 50, 50, 50) in 320dpi display.
191         /// </summary>
192         /// <param name="pixel">The Rectangle pixel unit value to be converted dp unit.</param>
193         /// <returns>The Rectangle dp unit value.</returns>
194         /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
195         [EditorBrowsable(EditorBrowsableState.Never)]
196         public static Rectangle ToDp(this Rectangle pixel)
197         {
198             if (pixel == null) return null;
199             return new Rectangle((int)GraphicsTypeManager.Instance.ConvertFromPixel(pixel.X),
200                                  (int)GraphicsTypeManager.Instance.ConvertFromPixel(pixel.Y),
201                                  (int)GraphicsTypeManager.Instance.ConvertFromPixel(pixel.Width),
202                                  (int)GraphicsTypeManager.Instance.ConvertFromPixel(pixel.Height));
203         }
204
205         /// <summary>
206         /// Converter Rectangle dp to pixel.
207         /// Rectangle(100, 100, 100, 100).ToPixel() = Rectangle(200, 200, 200, 200) in 320dpi display.
208         /// </summary>
209         /// <param name="dp">The Rectangle dp unit value to be converted pixel unit.</param>
210         /// <returns>The Rectangle pixel unit value.</returns>
211         /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
212         [EditorBrowsable(EditorBrowsableState.Never)]
213         public static Rectangle ToPixel(this Rectangle dp)
214         {
215             if (dp == null) return null;
216             return new Rectangle((int)GraphicsTypeManager.Instance.ConvertToPixel(dp.X),
217                                  (int)GraphicsTypeManager.Instance.ConvertToPixel(dp.Y),
218                                  (int)GraphicsTypeManager.Instance.ConvertToPixel(dp.Width),
219                                  (int)GraphicsTypeManager.Instance.ConvertToPixel(dp.Height));
220         }
221
222         /// <summary>
223         /// Converter Extents pixel to dp.
224         /// Extents(2, 2, 2, 2).ToDp() = Extents(1, 1, 1, 1) in 320dpi display.
225         /// </summary>
226         /// <param name="pixel">The Extents pixel unit value to be converted dp unit.</param>
227         /// <returns>The Extents dp unit value.</returns>
228         /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
229         [EditorBrowsable(EditorBrowsableState.Never)]
230         public static Extents ToDp(this Extents pixel)
231         {
232             if (pixel == null) return null;
233             return new Extents((ushort)GraphicsTypeManager.Instance.ConvertFromPixel(pixel.Start),
234                                (ushort)GraphicsTypeManager.Instance.ConvertFromPixel(pixel.End),
235                                (ushort)GraphicsTypeManager.Instance.ConvertFromPixel(pixel.Top),
236                                (ushort)GraphicsTypeManager.Instance.ConvertFromPixel(pixel.Bottom));
237         }
238
239         /// <summary>
240         /// Converter Extents dp to pixel.
241         /// Extents(2, 2, 2, 2).ToPixel() = Extents(4, 4, 4, 4) in 320dpi display.
242         /// </summary>
243         /// <param name="dp">The Extents dp unit value to be converted pixel unit.</param>
244         /// <returns>The Extents pixel unit value.</returns>
245         /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
246         [EditorBrowsable(EditorBrowsableState.Never)]
247         public static Extents ToPixel(this Extents dp)
248         {
249             if (dp == null) return null;
250             return new Extents((ushort)GraphicsTypeManager.Instance.ConvertToPixel(dp.Start),
251                                (ushort)GraphicsTypeManager.Instance.ConvertToPixel(dp.End),
252                                (ushort)GraphicsTypeManager.Instance.ConvertToPixel(dp.Top),
253                                (ushort)GraphicsTypeManager.Instance.ConvertToPixel(dp.Bottom));
254         }
255
256         /// <summary>
257         /// Converter float font pixel size to point size.
258         /// 100.0f.PixelToPoint() = 50.0f in 144dpi display.
259         /// </summary>
260         /// <param name="pixel">The float pixel unit value to be converted point unit.</param>
261         /// <returns>The float point unit value.</returns>
262         /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
263         [EditorBrowsable(EditorBrowsableState.Never)]
264         public static float PixelToPoint(this float pixel)
265         {
266             return GraphicsTypeManager.Instance.ConvertFromPixel(pixel);
267         }
268
269         /// <summary>
270         /// Converter float font point size to pixel size.
271         /// 100.0f.PointToPixel() = 200.0f in 144dpi display.
272         /// </summary>
273         /// <param name="point">The float point unit value to be converted pixel unit.</param>
274         /// <returns>The float pixel unit value.</returns>
275         /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
276         [EditorBrowsable(EditorBrowsableState.Never)]
277         public static float PointToPixel(this float point)
278         {
279             return PointTypeConverter.Instance.ConvertToPixel(point);
280         }
281
282         /// <summary>
283         /// Converter float font dp size to point size.
284         /// 16.0f.DpToPoint() = 7.2f.
285         /// </summary>
286         /// <param name="dp">The float dp unit value to be converted point unit.</param>
287         /// <returns>The float point unit value.</returns>
288         /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
289         [EditorBrowsable(EditorBrowsableState.Never)]
290         public static float DpToPoint(this float dp)
291         {
292             return PointTypeConverter.Instance.ConvertDpToPoint(dp);
293         }
294
295         /// <summary>
296         /// Converter float font point size to dp size.
297         /// 7.2f.PointToDp() = 16.0f.
298         /// </summary>
299         /// <param name="point">The float point unit value to be converted dp unit.</param>
300         /// <returns>The float dp unit value.</returns>
301         /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
302         [EditorBrowsable(EditorBrowsableState.Never)]
303         public static float PointToDp(this float point)
304         {
305             return PointTypeConverter.Instance.ConvertPointToDp(point);
306         }
307     }
308 }