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 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.
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 pixel to dp.
18 /// 100.0f.ToDp() = 50.0f in 320dpi display.
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)
26 return GraphicsTypeManager.Instance.ConvertFromPixel(pixel);
30 /// Converter float dp to pixel.
31 /// 100.0f.ToPixel() = 200.0f in 320dpi display.
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)
39 return GraphicsTypeManager.Instance.ConvertToPixel(dp);
43 /// Converter int pixel to dp.
44 /// 100.ToDp() = 50 in 320dpi display.
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)
52 return (int)GraphicsTypeManager.Instance.ConvertFromPixel(pixel);
56 /// Converter int dp to pixel.
57 /// 100.ToPixel() = 200 in 320dpi display.
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)
65 return (int)GraphicsTypeManager.Instance.ConvertToPixel(dp);
69 /// Converter Size pixel to dp.
70 /// Size(100.0f, 100.0f).ToDp() = Size(50.0f, 50.0f) in 320dpi display.
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)
78 if (pixel == null) return null;
79 return new Size(GraphicsTypeManager.Instance.ConvertFromPixel(pixel.Width),
80 GraphicsTypeManager.Instance.ConvertFromPixel(pixel.Height));
84 /// Converter Size dp to pixel.
85 /// Size(100.0f, 100.0f).ToPixel() = Size(200.0f, 200.0f) in 320dpi display.
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)
93 if (dp == null) return null;
94 return new Size(GraphicsTypeManager.Instance.ConvertToPixel(dp.Width),
95 GraphicsTypeManager.Instance.ConvertToPixel(dp.Height));
99 /// Converter Size2D pixel to dp.
100 /// Size2D(100, 100).ToDp() = Size2D(50, 50) in 320dpi display.
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)
108 if (pixel == null) return null;
109 return new Size2D((int)GraphicsTypeManager.Instance.ConvertFromPixel(pixel.Width),
110 (int)GraphicsTypeManager.Instance.ConvertFromPixel(pixel.Height));
114 /// Converter Size2D dp to pixel.
115 /// Size2D(100, 100).ToPixel() = Size(200, 200) in 320dpi display.
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)
123 if (dp == null) return null;
124 return new Size2D((int)GraphicsTypeManager.Instance.ConvertToPixel(dp.Width),
125 (int)GraphicsTypeManager.Instance.ConvertToPixel(dp.Height));
129 /// Converter Position pixel to dp.
130 /// Position(100.0f, 100.0f).ToDp() = Position(50.0f, 50.0f) in 320dpi display.
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)
138 if (pixel == null) return null;
139 return new Position(GraphicsTypeManager.Instance.ConvertFromPixel(pixel.X),
140 GraphicsTypeManager.Instance.ConvertFromPixel(pixel.Y));
144 /// Converter Position dp to pixel.
145 /// Position(100.0f, 100.0f).ToPixel() = Position(200.0f, 200.0f) in 320dpi display.
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)
153 if (dp == null) return null;
154 return new Position(GraphicsTypeManager.Instance.ConvertToPixel(dp.X),
155 GraphicsTypeManager.Instance.ConvertToPixel(dp.Y));
159 /// Converter Position2D pixel to dp.
160 /// Position2D(100.0f, 100.0f).ToDp() = Position2D(50.0f, 50.0f) in 320dpi display.
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)
168 if (pixel == null) return null;
169 return new Position2D((int)GraphicsTypeManager.Instance.ConvertFromPixel(pixel.X),
170 (int)GraphicsTypeManager.Instance.ConvertFromPixel(pixel.Y));
174 /// Converter Position2D dp to pixel.
175 /// Position2D(100, 100).ToPixel() = Position2D(200, 200) in 320dpi display.
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)
183 if (dp == null) return null;
184 return new Position2D((int)GraphicsTypeManager.Instance.ConvertToPixel(dp.X),
185 (int)GraphicsTypeManager.Instance.ConvertToPixel(dp.Y));
189 /// Converter Rectangle pixel to dp.
190 /// Rectangle(100, 100, 100, 100).ToDp() = Rectangle(50, 50, 50, 50) in 320dpi display.
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)
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));
206 /// Converter Rectangle dp to pixel.
207 /// Rectangle(100, 100, 100, 100).ToPixel() = Rectangle(200, 200, 200, 200) in 320dpi display.
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)
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));
223 /// Converter Extents pixel to dp.
224 /// Extents(2, 2, 2, 2).ToDp() = Extents(1, 1, 1, 1) in 320dpi display.
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)
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));
240 /// Converter Extents dp to pixel.
241 /// Extents(2, 2, 2, 2).ToPixel() = Extents(4, 4, 4, 4) in 320dpi display.
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)
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));
257 /// Converter float font pixel size to point size.
258 /// 100.0f.PixelToPoint() = 50.0f in 144dpi display.
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)
266 return GraphicsTypeManager.Instance.ConvertFromPixel(pixel);
270 /// Converter float font point size to pixel size.
271 /// 100.0f.PointToPixel() = 200.0f in 144dpi display.
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)
279 return PointTypeConverter.Instance.ConvertToPixel(point);
283 /// Converter float font dp size to point size.
284 /// 16.0f.DpToPoint() = 7.2f.
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)
292 return PointTypeConverter.Instance.ConvertDpToPoint(dp);
296 /// Converter float font point size to dp size.
297 /// 7.2f.PointToDp() = 16.0f.
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)
305 return PointTypeConverter.Instance.ConvertPointToDp(point);