diff options
author | crupest <crupest@outlook.com> | 2018-09-10 23:58:34 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2018-09-10 23:58:34 +0800 |
commit | 9250f4d919bc800fe66a50a0874183458e6ebbbe (patch) | |
tree | 1d25285801a6d92cfa8bde6dd0d13433e05d4c04 /CruUI/graph/graph.h | |
parent | aa8ba64f4f580552ba14325dd3e04f38a3c9a1de (diff) | |
download | cru-9250f4d919bc800fe66a50a0874183458e6ebbbe.tar.gz cru-9250f4d919bc800fe66a50a0874183458e6ebbbe.tar.bz2 cru-9250f4d919bc800fe66a50a0874183458e6ebbbe.zip |
...
Diffstat (limited to 'CruUI/graph/graph.h')
-rw-r--r-- | CruUI/graph/graph.h | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/CruUI/graph/graph.h b/CruUI/graph/graph.h index bb1de716..4f0898d6 100644 --- a/CruUI/graph/graph.h +++ b/CruUI/graph/graph.h @@ -107,7 +107,7 @@ namespace cru std::shared_ptr<WindowRenderTarget> CreateWindowRenderTarget(HWND hwnd); //Get the desktop dpi. - Dpi GetDpi(); + Dpi GetDpi() const; //Reload system metrics including desktop dpi. void ReloadSystemMetrics(); @@ -129,10 +129,35 @@ namespace cru Microsoft::WRL::ComPtr<IDWriteFontCollection> dwrite_system_font_collection_; }; - int DipToPixelX(float dip_x); - int DipToPixelY(float dip_y); - float PixelToDipX(int pixel_x); - float PixelToDipY(int pixel_y); + 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, Application::GetInstance()->GetGraphManager()->GetDpi().x); + } + + inline int DipToPixelY(const float dip_y) + { + return DipToPixelInternal(dip_y, Application::GetInstance()->GetGraphManager()->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, Application::GetInstance()->GetGraphManager()->GetDpi().x); + } + + inline float PixelToDipY(const int pixel_y) + { + return DipToPixelInternal(pixel_y, Application::GetInstance()->GetGraphManager()->GetDpi().y); + } Microsoft::WRL::ComPtr<ID2D1DeviceContext> WindowRenderTarget::GetD2DDeviceContext() const { |