diff options
author | crupest <crupest@outlook.com> | 2019-04-01 15:28:07 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2019-04-01 15:28:07 +0800 |
commit | 3e89aa733587043645f5fda72596e4ff3cd21d2a (patch) | |
tree | 7daadddf1073f537bb580a0cdf77208cf26e6271 /src/platform_win/dpi_util.hpp | |
parent | 8ca0873597eb05a2f120d3ea107660abcff4533c (diff) | |
download | cru-3e89aa733587043645f5fda72596e4ff3cd21d2a.tar.gz cru-3e89aa733587043645f5fda72596e4ff3cd21d2a.tar.bz2 cru-3e89aa733587043645f5fda72596e4ff3cd21d2a.zip |
...
Diffstat (limited to 'src/platform_win/dpi_util.hpp')
-rw-r--r-- | src/platform_win/dpi_util.hpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/platform_win/dpi_util.hpp b/src/platform_win/dpi_util.hpp new file mode 100644 index 00000000..92819e0f --- /dev/null +++ b/src/platform_win/dpi_util.hpp @@ -0,0 +1,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 |