blob: 92819e0f576f0939d8a7acaa2bc9ebbac6f5cafc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
#pragma once
// The dpi awareness needs to be implemented in the future. Currently we use 96
// as default.
namespace cru::platform {
inline Dpi GetDpi() { return Dpi{96.0f, 96.0f}; }
inline int DipToPixelInternal(const float dip, const float dpi) {
return static_cast<int>(dip * dpi / 96.0f);
}
inline int DipToPixelX(const float dip_x) {
return DipToPixelInternal(dip_x, GetDpi().x);
}
inline int DipToPixelY(const float dip_y) {
return DipToPixelInternal(dip_y, GetDpi().y);
}
inline float DipToPixelInternal(const int pixel, const float dpi) {
return static_cast<float>(pixel) * 96.0f / dpi;
}
inline float PixelToDipX(const int pixel_x) {
return DipToPixelInternal(pixel_x, GetDpi().x);
}
inline float PixelToDipY(const int pixel_y) {
return DipToPixelInternal(pixel_y, GetDpi().y);
}
} // namespace cru::platform
|