diff options
Diffstat (limited to 'include/cru')
-rw-r--r-- | include/cru/win/native/Window.hpp | 25 | ||||
-rw-r--r-- | include/cru/win/native/WindowRenderTarget.hpp | 3 |
2 files changed, 27 insertions, 1 deletions
diff --git a/include/cru/win/native/Window.hpp b/include/cru/win/native/Window.hpp index 3e0b11cd..37df0768 100644 --- a/include/cru/win/native/Window.hpp +++ b/include/cru/win/native/Window.hpp @@ -2,6 +2,7 @@ #include "Resource.hpp" #include "WindowNativeMessageEventArgs.hpp" +#include "cru/platform/GraphBase.hpp" #include "cru/platform/native/Window.hpp" #include <memory> @@ -89,6 +90,28 @@ class WinNativeWindow : public WinNativeResource, public virtual INativeWindow { return window_render_target_.get(); } + //*************** region: dpi *************** + float GetDpi() const { return dpi_; } + + inline int DipToPixel(const float dip) { + return static_cast<int>(dip * GetDpi() / 96.0f); + } + + inline POINT DipToPixel(const Point& dip_point) { + POINT result; + result.x = DipToPixel(dip_point.x); + result.y = DipToPixel(dip_point.y); + return result; + } + + inline float PixelToDip(const int pixel) { + return static_cast<float>(pixel) * 96.0f / GetDpi(); + } + + inline Point PixelToDip(const POINT& pi_point) { + return Point(PixelToDip(pi_point.x), PixelToDip(pi_point.y)); + } + private: // Get the client rect in pixel. RECT GetClientRectPixel(); @@ -129,6 +152,8 @@ class WinNativeWindow : public WinNativeResource, public virtual INativeWindow { HWND hwnd_; WinNativeWindow* parent_window_; + float dpi_; + bool has_focus_ = false; bool is_mouse_in_ = false; diff --git a/include/cru/win/native/WindowRenderTarget.hpp b/include/cru/win/native/WindowRenderTarget.hpp index 83ac1e03..786a90a6 100644 --- a/include/cru/win/native/WindowRenderTarget.hpp +++ b/include/cru/win/native/WindowRenderTarget.hpp @@ -10,7 +10,7 @@ namespace cru::platform::native::win { class WindowRenderTarget : public Object { public: WindowRenderTarget(graph::win::direct::DirectGraphFactory* factory, - HWND hwnd); + WinNativeWindow* window); CRU_DELETE_COPY(WindowRenderTarget) CRU_DELETE_MOVE(WindowRenderTarget) @@ -39,6 +39,7 @@ class WindowRenderTarget : public Object { void CreateTargetBitmap(); private: + WinNativeWindow* window_; graph::win::direct::DirectGraphFactory* factory_; Microsoft::WRL::ComPtr<ID2D1DeviceContext> d2d1_device_context_; Microsoft::WRL::ComPtr<IDXGISwapChain1> dxgi_swap_chain_; |