1 using System.ComponentModel;
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 PxToDp(),
8 /// and you can get original pixel by PxToDp().
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.
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
17 /// Converter float dp to pixel.
19 /// <param name="dp">The float dp unit value to be converted pixel unit.</param>
20 /// <returns>The float pixel unit value.</returns>
21 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
22 [EditorBrowsable(EditorBrowsableState.Never)]
23 public static float DpToPx(this float dp)
25 return GraphicsTypeManager.Instance.Dp.ConvertToPixel(dp);
29 /// Converter float sp to pixel.
31 /// <param name="sp">The float sp unit value to be converted pixel unit.</param>
32 /// <returns>The float pixel unit value.</returns>
33 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
34 [EditorBrowsable(EditorBrowsableState.Never)]
35 public static float SpToPx(this float sp)
37 return GraphicsTypeManager.Instance.Sp.ConvertToPixel(sp);
41 /// Converter float pixel to dp.
43 /// <param name="pixel">The float pixel unit value to be converted dp unit.</param>
44 /// <returns>The float dp unit value.</returns>
45 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
46 [EditorBrowsable(EditorBrowsableState.Never)]
47 public static float PxToDp(this float pixel)
49 return GraphicsTypeManager.Instance.Dp.ConvertFromPixel(pixel);
53 /// Converter float pixel to sp.
55 /// <param name="pixel">The float pixel unit value to be converted sp unit.</param>
56 /// <returns>The float sp unit value.</returns>
57 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
58 [EditorBrowsable(EditorBrowsableState.Never)]
59 public static float PxToSp(this float pixel)
61 return GraphicsTypeManager.Instance.Sp.ConvertFromPixel(pixel);
65 /// Converter int dp to pixel.
67 /// <param name="dp">The int dp unit value to be converted pixel unit.</param>
68 /// <returns>The int pixel unit value.</returns>
69 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
70 [EditorBrowsable(EditorBrowsableState.Never)]
71 public static int DpToPx(this int dp)
73 return (int)GraphicsTypeManager.Instance.Dp.ConvertToPixel(dp);
77 /// Converter int dp to pixel.
79 /// <param name="sp">The int sp unit value to be converted pixel unit.</param>
80 /// <returns>The int pixel unit value.</returns>
81 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
82 [EditorBrowsable(EditorBrowsableState.Never)]
83 public static int SpToPx(this int sp)
85 return (int)GraphicsTypeManager.Instance.Sp.ConvertToPixel(sp);
89 /// Converter int pixel to dp.
91 /// <param name="pixel">The int pixel unit value to be converted dp unit.</param>
92 /// <returns>The int dp unit value.</returns>
93 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
94 [EditorBrowsable(EditorBrowsableState.Never)]
95 public static int PxToDp(this int pixel)
97 return (int)GraphicsTypeManager.Instance.Dp.ConvertFromPixel(pixel);
101 /// Converter int pixel to sp.
103 /// <param name="pixel">The int pixel unit value to be converted sp unit.</param>
104 /// <returns>The int sp unit value.</returns>
105 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
106 [EditorBrowsable(EditorBrowsableState.Never)]
107 public static int PxToSp(this int pixel)
109 return (int)GraphicsTypeManager.Instance.Sp.ConvertFromPixel(pixel);
114 /// Converter Size pixel to dp.
116 /// <param name="pixel">The Size pixel unit value to be converted dp unit.</param>
117 /// <returns>The Size dp unit value.</returns>
118 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
119 [EditorBrowsable(EditorBrowsableState.Never)]
120 public static Size PxToDp(this Size pixel)
122 if (pixel == null) return null;
123 return new Size(GraphicsTypeManager.Instance.Dp.ConvertFromPixel(pixel.Width),
124 GraphicsTypeManager.Instance.Dp.ConvertFromPixel(pixel.Height));
128 /// Converter Size pixel to sp.
130 /// <param name="pixel">The Size pixel unit value to be converted sp unit.</param>
131 /// <returns>The Size sp unit value.</returns>
132 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
133 [EditorBrowsable(EditorBrowsableState.Never)]
134 public static Size PxToSp(this Size pixel)
136 if (pixel == null) return null;
137 return new Size(GraphicsTypeManager.Instance.Sp.ConvertFromPixel(pixel.Width),
138 GraphicsTypeManager.Instance.Sp.ConvertFromPixel(pixel.Height));
142 /// Converter Size dp to pixel.
144 /// <param name="dp">The Size dp unit value to be converted pixel unit.</param>
145 /// <returns>The Size pixel unit value.</returns>
146 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
147 [EditorBrowsable(EditorBrowsableState.Never)]
148 public static Size DpToPx(this Size dp)
150 if (dp == null) return null;
151 return new Size(GraphicsTypeManager.Instance.Dp.ConvertToPixel(dp.Width),
152 GraphicsTypeManager.Instance.Dp.ConvertToPixel(dp.Height));
156 /// Converter Size sp to pixel.
158 /// <param name="sp">The Size sp unit value to be converted pixel unit.</param>
159 /// <returns>The Size pixel unit value.</returns>
160 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
161 [EditorBrowsable(EditorBrowsableState.Never)]
162 public static Size SpToPx(this Size sp)
164 if (sp == null) return null;
165 return new Size(GraphicsTypeManager.Instance.Sp.ConvertToPixel(sp.Width),
166 GraphicsTypeManager.Instance.Sp.ConvertToPixel(sp.Height));
170 /// Converter Size2D pixel to dp.
172 /// <param name="pixel">The Size2D pixel unit value to be converted dp unit.</param>
173 /// <returns>The Size2D dp unit value.</returns>
174 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
175 [EditorBrowsable(EditorBrowsableState.Never)]
176 public static Size2D PxToDp(this Size2D pixel)
178 if (pixel == null) return null;
179 return new Size2D((int)GraphicsTypeManager.Instance.Dp.ConvertFromPixel(pixel.Width),
180 (int)GraphicsTypeManager.Instance.Dp.ConvertFromPixel(pixel.Height));
184 /// Converter Size2D pixel to sp.
186 /// <param name="pixel">The Size2D pixel unit value to be converted sp unit.</param>
187 /// <returns>The Size2D sp unit value.</returns>
188 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
189 [EditorBrowsable(EditorBrowsableState.Never)]
190 public static Size2D PxToSp(this Size2D pixel)
192 if (pixel == null) return null;
193 return new Size2D((int)GraphicsTypeManager.Instance.Sp.ConvertFromPixel(pixel.Width),
194 (int)GraphicsTypeManager.Instance.Sp.ConvertFromPixel(pixel.Height));
198 /// Converter Size2D dp to pixel.
200 /// <param name="dp">The Size2D dp unit value to be converted pixel unit.</param>
201 /// <returns>The Size2D pixel unit value.</returns>
202 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
203 [EditorBrowsable(EditorBrowsableState.Never)]
204 public static Size2D DpToPx(this Size2D dp)
206 if (dp == null) return null;
207 return new Size2D((int)GraphicsTypeManager.Instance.Dp.ConvertToPixel(dp.Width),
208 (int)GraphicsTypeManager.Instance.Dp.ConvertToPixel(dp.Height));
212 /// Converter Size2D sp to pixel.
214 /// <param name="sp">The Size2D sp unit value to be converted pixel unit.</param>
215 /// <returns>The Size2D pixel unit value.</returns>
216 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
217 [EditorBrowsable(EditorBrowsableState.Never)]
218 public static Size2D SpToPx(this Size2D sp)
220 if (sp == null) return null;
221 return new Size2D((int)GraphicsTypeManager.Instance.Sp.ConvertToPixel(sp.Width),
222 (int)GraphicsTypeManager.Instance.Sp.ConvertToPixel(sp.Height));
226 /// Converter Position pixel to dp.
228 /// <param name="pixel">The Position pixel unit value to be converted dp unit.</param>
229 /// <returns>The Position dp unit value.</returns>
230 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
231 [EditorBrowsable(EditorBrowsableState.Never)]
232 public static Position PxToDp(this Position pixel)
234 if (pixel == null) return null;
235 return new Position(GraphicsTypeManager.Instance.Dp.ConvertFromPixel(pixel.X),
236 GraphicsTypeManager.Instance.Dp.ConvertFromPixel(pixel.Y));
240 /// Converter Position pixel to sp.
242 /// <param name="pixel">The Position pixel unit value to be converted sp unit.</param>
243 /// <returns>The Position sp unit value.</returns>
244 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
245 [EditorBrowsable(EditorBrowsableState.Never)]
246 public static Position PxToSp(this Position pixel)
248 if (pixel == null) return null;
249 return new Position(GraphicsTypeManager.Instance.Sp.ConvertFromPixel(pixel.X),
250 GraphicsTypeManager.Instance.Sp.ConvertFromPixel(pixel.Y));
254 /// Converter Position dp to pixel.
256 /// <param name="dp">The Position dp unit value to be converted pixel unit.</param>
257 /// <returns>The Position pixel unit value.</returns>
258 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
259 [EditorBrowsable(EditorBrowsableState.Never)]
260 public static Position DpToPx(this Position dp)
262 if (dp == null) return null;
263 return new Position(GraphicsTypeManager.Instance.Dp.ConvertToPixel(dp.X),
264 GraphicsTypeManager.Instance.Dp.ConvertToPixel(dp.Y));
268 /// Converter Position sp to pixel.
270 /// <param name="sp">The Position sp unit value to be converted pixel unit.</param>
271 /// <returns>The Position pixel unit value.</returns>
272 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
273 [EditorBrowsable(EditorBrowsableState.Never)]
274 public static Position SpToPx(this Position sp)
276 if (sp == null) return null;
277 return new Position(GraphicsTypeManager.Instance.Sp.ConvertToPixel(sp.X),
278 GraphicsTypeManager.Instance.Sp.ConvertToPixel(sp.Y));
282 /// Converter Position2D pixel to dp.
284 /// <param name="pixel">The Position2D pixel unit value to be converted dp unit.</param>
285 /// <returns>The Position2D dp unit value.</returns>
286 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
287 [EditorBrowsable(EditorBrowsableState.Never)]
288 public static Position2D PxToDp(this Position2D pixel)
290 if (pixel == null) return null;
291 return new Position2D((int)GraphicsTypeManager.Instance.Dp.ConvertFromPixel(pixel.X),
292 (int)GraphicsTypeManager.Instance.Dp.ConvertFromPixel(pixel.Y));
296 /// Converter Position2D pixel to sp.
298 /// <param name="pixel">The Position2D pixel unit value to be converted sp unit.</param>
299 /// <returns>The Position2D sp unit value.</returns>
300 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
301 [EditorBrowsable(EditorBrowsableState.Never)]
302 public static Position2D PxToSp(this Position2D pixel)
304 if (pixel == null) return null;
305 return new Position2D((int)GraphicsTypeManager.Instance.Sp.ConvertFromPixel(pixel.X),
306 (int)GraphicsTypeManager.Instance.Sp.ConvertFromPixel(pixel.Y));
310 /// Converter Position2D dp to pixel.
312 /// <param name="dp">The Position2D dp unit value to be converted pixel unit.</param>
313 /// <returns>The Position2D pixel unit value.</returns>
314 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
315 [EditorBrowsable(EditorBrowsableState.Never)]
316 public static Position2D DpToPx(this Position2D dp)
318 if (dp == null) return null;
319 return new Position2D((int)GraphicsTypeManager.Instance.Dp.ConvertToPixel(dp.X),
320 (int)GraphicsTypeManager.Instance.Dp.ConvertToPixel(dp.Y));
324 /// Converter Position2D sp to pixel.
326 /// <param name="sp">The Position2D sp unit value to be converted pixel unit.</param>
327 /// <returns>The Position2D pixel unit value.</returns>
328 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
329 [EditorBrowsable(EditorBrowsableState.Never)]
330 public static Position2D SpToPx(this Position2D sp)
332 if (sp == null) return null;
333 return new Position2D((int)GraphicsTypeManager.Instance.Sp.ConvertToPixel(sp.X),
334 (int)GraphicsTypeManager.Instance.Sp.ConvertToPixel(sp.Y));
338 /// Converter Rectangle pixel to dp.
340 /// <param name="pixel">The Rectangle pixel unit value to be converted dp unit.</param>
341 /// <returns>The Rectangle dp unit value.</returns>
342 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
343 [EditorBrowsable(EditorBrowsableState.Never)]
344 public static Rectangle PxToDp(this Rectangle pixel)
346 if (pixel == null) return null;
347 return new Rectangle((int)GraphicsTypeManager.Instance.Dp.ConvertFromPixel(pixel.X),
348 (int)GraphicsTypeManager.Instance.Dp.ConvertFromPixel(pixel.Y),
349 (int)GraphicsTypeManager.Instance.Dp.ConvertFromPixel(pixel.Width),
350 (int)GraphicsTypeManager.Instance.Dp.ConvertFromPixel(pixel.Height));
354 /// Converter Rectangle pixel to sp.
356 /// <param name="pixel">The Rectangle pixel unit value to be converted sp unit.</param>
357 /// <returns>The Rectangle sp unit value.</returns>
358 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
359 [EditorBrowsable(EditorBrowsableState.Never)]
360 public static Rectangle PxToSp(this Rectangle pixel)
362 if (pixel == null) return null;
363 return new Rectangle((int)GraphicsTypeManager.Instance.Sp.ConvertFromPixel(pixel.X),
364 (int)GraphicsTypeManager.Instance.Sp.ConvertFromPixel(pixel.Y),
365 (int)GraphicsTypeManager.Instance.Sp.ConvertFromPixel(pixel.Width),
366 (int)GraphicsTypeManager.Instance.Sp.ConvertFromPixel(pixel.Height));
370 /// Converter Rectangle dp to pixel.
372 /// <param name="dp">The Rectangle dp unit value to be converted pixel unit.</param>
373 /// <returns>The Rectangle pixel unit value.</returns>
374 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
375 [EditorBrowsable(EditorBrowsableState.Never)]
376 public static Rectangle DpToPx(this Rectangle dp)
378 if (dp == null) return null;
379 return new Rectangle((int)GraphicsTypeManager.Instance.Dp.ConvertToPixel(dp.X),
380 (int)GraphicsTypeManager.Instance.Dp.ConvertToPixel(dp.Y),
381 (int)GraphicsTypeManager.Instance.Dp.ConvertToPixel(dp.Width),
382 (int)GraphicsTypeManager.Instance.Dp.ConvertToPixel(dp.Height));
386 /// Converter Rectangle sp to pixel.
388 /// <param name="sp">The Rectangle sp unit value to be converted pixel unit.</param>
389 /// <returns>The Rectangle pixel unit value.</returns>
390 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
391 [EditorBrowsable(EditorBrowsableState.Never)]
392 public static Rectangle SpToPx(this Rectangle sp)
394 if (sp == null) return null;
395 return new Rectangle((int)GraphicsTypeManager.Instance.Sp.ConvertToPixel(sp.X),
396 (int)GraphicsTypeManager.Instance.Sp.ConvertToPixel(sp.Y),
397 (int)GraphicsTypeManager.Instance.Sp.ConvertToPixel(sp.Width),
398 (int)GraphicsTypeManager.Instance.Sp.ConvertToPixel(sp.Height));
402 /// Converter Extents pixel to dp.
404 /// <param name="pixel">The Extents pixel unit value to be converted dp unit.</param>
405 /// <returns>The Extents dp unit value.</returns>
406 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
407 [EditorBrowsable(EditorBrowsableState.Never)]
408 public static Extents PxToDp(this Extents pixel)
410 if (pixel == null) return null;
411 return new Extents((ushort)GraphicsTypeManager.Instance.Dp.ConvertFromPixel(pixel.Start),
412 (ushort)GraphicsTypeManager.Instance.Dp.ConvertFromPixel(pixel.End),
413 (ushort)GraphicsTypeManager.Instance.Dp.ConvertFromPixel(pixel.Top),
414 (ushort)GraphicsTypeManager.Instance.Dp.ConvertFromPixel(pixel.Bottom));
418 /// Converter Extents pixel to sp.
420 /// <param name="pixel">The Extents pixel unit value to be converted sp unit.</param>
421 /// <returns>The Extents sp unit value.</returns>
422 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
423 [EditorBrowsable(EditorBrowsableState.Never)]
424 public static Extents PxToSp(this Extents pixel)
426 if (pixel == null) return null;
427 return new Extents((ushort)GraphicsTypeManager.Instance.Sp.ConvertFromPixel(pixel.Start),
428 (ushort)GraphicsTypeManager.Instance.Sp.ConvertFromPixel(pixel.End),
429 (ushort)GraphicsTypeManager.Instance.Sp.ConvertFromPixel(pixel.Top),
430 (ushort)GraphicsTypeManager.Instance.Sp.ConvertFromPixel(pixel.Bottom));
434 /// Converter Extents dp to pixel.
436 /// <param name="dp">The Extents dp unit value to be converted pixel unit.</param>
437 /// <returns>The Extents pixel unit value.</returns>
438 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
439 [EditorBrowsable(EditorBrowsableState.Never)]
440 public static Extents DpToPx(this Extents dp)
442 if (dp == null) return null;
443 return new Extents((ushort)GraphicsTypeManager.Instance.Dp.ConvertToPixel(dp.Start),
444 (ushort)GraphicsTypeManager.Instance.Dp.ConvertToPixel(dp.End),
445 (ushort)GraphicsTypeManager.Instance.Dp.ConvertToPixel(dp.Top),
446 (ushort)GraphicsTypeManager.Instance.Dp.ConvertToPixel(dp.Bottom));
450 /// Converter Extents sp to pixel.
452 /// <param name="sp">The Extents sp unit value to be converted pixel unit.</param>
453 /// <returns>The Extents pixel unit value.</returns>
454 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
455 [EditorBrowsable(EditorBrowsableState.Never)]
456 public static Extents SpToPx(this Extents sp)
458 if (sp == null) return null;
459 return new Extents((ushort)GraphicsTypeManager.Instance.Sp.ConvertToPixel(sp.Start),
460 (ushort)GraphicsTypeManager.Instance.Sp.ConvertToPixel(sp.End),
461 (ushort)GraphicsTypeManager.Instance.Sp.ConvertToPixel(sp.Top),
462 (ushort)GraphicsTypeManager.Instance.Sp.ConvertToPixel(sp.Bottom));
466 /// Converter float font pixel size to point size.
468 /// <param name="pixel">The float pixel unit value to be converted point unit.</param>
469 /// <returns>The float point unit value.</returns>
470 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
471 [EditorBrowsable(EditorBrowsableState.Never)]
472 public static float PxToPt(this float pixel)
474 return GraphicsTypeManager.Instance.Point.ConvertFromPixel(pixel);
478 /// Converter float font point size to pixel size.
480 /// <param name="pt">The float point unit value to be converted pixel unit.</param>
481 /// <returns>The float pixel unit value.</returns>
482 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
483 [EditorBrowsable(EditorBrowsableState.Never)]
484 public static float PtToPixel(this float pt)
486 return GraphicsTypeManager.Instance.Point.ConvertToPixel(pt);
490 /// Converter float font dp size to point size.
491 /// 16.0f.DpToPt() = 7.2f.
493 /// <param name="dp">The float dp unit value to be converted point unit.</param>
494 /// <returns>The float point unit value.</returns>
495 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
496 [EditorBrowsable(EditorBrowsableState.Never)]
497 public static float DpToPt(this float dp)
499 return GraphicsTypeManager.Instance.Point.ConvertDpToPoint(dp);
503 /// Converter float font point size to dp size.
504 /// 7.2f.PtToDp() = 16.0f.
506 /// <param name="pt">The float point unit value to be converted dp unit.</param>
507 /// <returns>The float dp unit value.</returns>
508 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
509 [EditorBrowsable(EditorBrowsableState.Never)]
510 public static float PtToDp(this float pt)
512 return GraphicsTypeManager.Instance.Point.ConvertPointToDp(pt);