aboutsummaryrefslogtreecommitdiff
path: root/include/cru
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-10-28 20:36:47 +0800
committercrupest <crupest@outlook.com>2020-10-28 20:36:47 +0800
commitcf07d193b97168048a72793c59f096504acf78a5 (patch)
tree8d14f6eba4140265931efc877d6371e8cf5cbf96 /include/cru
parenta09a9645d3c823e3559659dc1ddd213510755820 (diff)
downloadcru-cf07d193b97168048a72793c59f096504acf78a5.tar.gz
cru-cf07d193b97168048a72793c59f096504acf78a5.tar.bz2
cru-cf07d193b97168048a72793c59f096504acf78a5.zip
...
Diffstat (limited to 'include/cru')
-rw-r--r--include/cru/win/graph/direct/WindowPainter.hpp21
-rw-r--r--include/cru/win/graph/direct/WindowRenderTarget.hpp (renamed from include/cru/win/native/WindowRenderTarget.hpp)28
-rw-r--r--include/cru/win/native/Base.hpp1
-rw-r--r--include/cru/win/native/Window.hpp6
4 files changed, 36 insertions, 20 deletions
diff --git a/include/cru/win/graph/direct/WindowPainter.hpp b/include/cru/win/graph/direct/WindowPainter.hpp
new file mode 100644
index 00000000..53961586
--- /dev/null
+++ b/include/cru/win/graph/direct/WindowPainter.hpp
@@ -0,0 +1,21 @@
+#pragma once
+#include "Painter.hpp"
+#include "WindowRenderTarget.hpp"
+
+namespace cru::platform::graph::win::direct {
+class D2DWindowPainter : public graph::win::direct::D2DPainter {
+ public:
+ explicit D2DWindowPainter(D2DWindowRenderTarget* window);
+
+ CRU_DELETE_COPY(D2DWindowPainter)
+ CRU_DELETE_MOVE(D2DWindowPainter)
+
+ ~D2DWindowPainter() override;
+
+ protected:
+ void DoEndDraw() override;
+
+ private:
+ D2DWindowRenderTarget* render_target_;
+};
+} // namespace cru::platform::graph::win::direct
diff --git a/include/cru/win/native/WindowRenderTarget.hpp b/include/cru/win/graph/direct/WindowRenderTarget.hpp
index 786a90a6..c9ee098f 100644
--- a/include/cru/win/native/WindowRenderTarget.hpp
+++ b/include/cru/win/graph/direct/WindowRenderTarget.hpp
@@ -1,21 +1,16 @@
#pragma once
-#include "Base.hpp"
+#include "Factory.hpp"
namespace cru::platform::graph::win::direct {
-class DirectGraphFactory;
-}
-
-namespace cru::platform::native::win {
// Represents a window render target.
-class WindowRenderTarget : public Object {
+class D2DWindowRenderTarget : public Object {
public:
- WindowRenderTarget(graph::win::direct::DirectGraphFactory* factory,
- WinNativeWindow* window);
+ D2DWindowRenderTarget(gsl::not_null<DirectGraphFactory*> factory, HWND hwnd);
- CRU_DELETE_COPY(WindowRenderTarget)
- CRU_DELETE_MOVE(WindowRenderTarget)
+ CRU_DELETE_COPY(D2DWindowRenderTarget)
+ CRU_DELETE_MOVE(D2DWindowRenderTarget)
- ~WindowRenderTarget() override = default;
+ ~D2DWindowRenderTarget() override = default;
public:
graph::win::direct::DirectGraphFactory* GetDirectFactory() const {
@@ -26,12 +21,11 @@ class WindowRenderTarget : public Object {
return d2d1_device_context_.Get();
}
+ void SetDpi(float x, float y);
+
// Resize the underlying buffer.
void ResizeBuffer(int width, int height);
- // Set this render target as the d2d device context's target.
- void SetAsTarget();
-
// Present the data of the underlying buffer to the window.
void Present();
@@ -39,10 +33,10 @@ class WindowRenderTarget : public Object {
void CreateTargetBitmap();
private:
- WinNativeWindow* window_;
- graph::win::direct::DirectGraphFactory* factory_;
+ DirectGraphFactory* factory_;
+ HWND hwnd_;
Microsoft::WRL::ComPtr<ID2D1DeviceContext> d2d1_device_context_;
Microsoft::WRL::ComPtr<IDXGISwapChain1> dxgi_swap_chain_;
Microsoft::WRL::ComPtr<ID2D1Bitmap1> target_bitmap_;
};
-} // namespace cru::platform::native::win
+} // namespace cru::platform::graph::win::direct
diff --git a/include/cru/win/native/Base.hpp b/include/cru/win/native/Base.hpp
index a50c6dd1..7ddc6b54 100644
--- a/include/cru/win/native/Base.hpp
+++ b/include/cru/win/native/Base.hpp
@@ -10,7 +10,6 @@ class WinCursor;
class WinCursorManager;
class WindowClass;
class WindowManager;
-class WindowRenderTarget;
class WinNativeWindow;
class WinNativeWindowResolver;
class WinUiApplication;
diff --git a/include/cru/win/native/Window.hpp b/include/cru/win/native/Window.hpp
index 37df0768..ecc0dd04 100644
--- a/include/cru/win/native/Window.hpp
+++ b/include/cru/win/native/Window.hpp
@@ -4,6 +4,7 @@
#include "WindowNativeMessageEventArgs.hpp"
#include "cru/platform/GraphBase.hpp"
#include "cru/platform/native/Window.hpp"
+#include "cru/win/graph/direct/WindowRenderTarget.hpp"
#include <memory>
@@ -86,7 +87,7 @@ class WinNativeWindow : public WinNativeResource, public virtual INativeWindow {
bool HandleNativeWindowMessage(HWND hwnd, UINT msg, WPARAM w_param,
LPARAM l_param, LRESULT* result);
- WindowRenderTarget* GetWindowRenderTarget() const {
+ graph::win::direct::D2DWindowRenderTarget* GetWindowRenderTarget() const {
return window_render_target_.get();
}
@@ -157,7 +158,8 @@ class WinNativeWindow : public WinNativeResource, public virtual INativeWindow {
bool has_focus_ = false;
bool is_mouse_in_ = false;
- std::unique_ptr<WindowRenderTarget> window_render_target_;
+ std::unique_ptr<graph::win::direct::D2DWindowRenderTarget>
+ window_render_target_;
std::shared_ptr<WinCursor> cursor_;