diff options
author | crupest <crupest@outlook.com> | 2019-05-24 23:45:58 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2019-05-24 23:45:58 +0800 |
commit | b6db663269201fa14a6a4aa1b9042645a9e8f859 (patch) | |
tree | 1984e2c2784fb9623d4c20fbdd6fc650792e133c /include/cru/win | |
parent | b9df1bcaea0c19b2e29479cdb1ad5a39e23c4ee7 (diff) | |
download | cru-b6db663269201fa14a6a4aa1b9042645a9e8f859.tar.gz cru-b6db663269201fa14a6a4aa1b9042645a9e8f859.tar.bz2 cru-b6db663269201fa14a6a4aa1b9042645a9e8f859.zip |
...
Diffstat (limited to 'include/cru/win')
-rw-r--r-- | include/cru/win/graph/d2d_painter.hpp | 48 | ||||
-rw-r--r-- | include/cru/win/graph/graph_manager.hpp | 51 | ||||
-rw-r--r-- | include/cru/win/graph/util/convert_util.hpp (renamed from include/cru/win/graph/d2d_util.hpp) | 2 | ||||
-rw-r--r-- | include/cru/win/graph/win_brush.hpp | 11 | ||||
-rw-r--r-- | include/cru/win/graph/win_font.hpp | 6 | ||||
-rw-r--r-- | include/cru/win/graph/win_geometry.hpp | 12 | ||||
-rw-r--r-- | include/cru/win/graph/win_graph_factory.hpp | 53 | ||||
-rw-r--r-- | include/cru/win/graph/win_native_factory.hpp | 16 | ||||
-rw-r--r-- | include/cru/win/graph/win_painter.hpp | 43 | ||||
-rw-r--r-- | include/cru/win/graph/win_text_layout.hpp | 12 | ||||
-rw-r--r-- | include/cru/win/native/win_native_window.hpp | 2 | ||||
-rw-r--r-- | include/cru/win/native/window_render_target.hpp | 9 |
12 files changed, 127 insertions, 138 deletions
diff --git a/include/cru/win/graph/d2d_painter.hpp b/include/cru/win/graph/d2d_painter.hpp deleted file mode 100644 index d33dced4..00000000 --- a/include/cru/win/graph/d2d_painter.hpp +++ /dev/null @@ -1,48 +0,0 @@ -#pragma once -#include "../win_pre_config.hpp" - -#include "cru/platform/graph/painter.hpp" - -namespace cru::win::graph { -class GraphManager; - -class D2DPainter : public Object, public virtual platform::graph::Painter { - public: - explicit D2DPainter(ID2D1RenderTarget* render_target); - D2DPainter(const D2DPainter& other) = delete; - D2DPainter(D2DPainter&& other) = delete; - D2DPainter& operator=(const D2DPainter& other) = delete; - D2DPainter& operator=(D2DPainter&& other) = delete; - ~D2DPainter() override = default; - - platform::Matrix GetTransform() override; - void SetTransform(const platform::Matrix& matrix) override; - void Clear(const ui::Color& color) override; - void StrokeRectangle(const ui::Rect& rectangle, platform::graph::Brush* brush, - float width) override; - void FillRectangle(const ui::Rect& rectangle, - platform::graph::Brush* brush) override; - void StrokeGeometry(platform::graph::Geometry* geometry, - platform::graph::Brush* brush, float width) override; - void FillGeometry(platform::graph::Geometry* geometry, - platform::graph::Brush* brush) override; - void DrawText(const ui::Point& offset, - platform::graph::TextLayout* text_layout, - platform::graph::Brush* brush) override; - void EndDraw() override final; - bool IsDisposed() override final { return is_disposed_; } - - void EndDrawAndDeleteThis() { - EndDraw(); - delete this; - } - - protected: - virtual void DoEndDraw() = 0; - - private: - ID2D1RenderTarget* render_target_; - - bool is_disposed_ = false; -}; -} // namespace cru::win::graph diff --git a/include/cru/win/graph/graph_manager.hpp b/include/cru/win/graph/graph_manager.hpp deleted file mode 100644 index bf14b802..00000000 --- a/include/cru/win/graph/graph_manager.hpp +++ /dev/null @@ -1,51 +0,0 @@ -#pragma once -#include "../win_pre_config.hpp" - -#include "cru/common/base.hpp" -#include "cru/win/graph/win_graph_factory.hpp" - -#include <memory> - -namespace cru::win::graph { -class GraphManager final : public Object { - public: - static GraphManager* GetInstance(); - - public: - GraphManager(); - GraphManager(const GraphManager& other) = delete; - GraphManager(GraphManager&& other) = delete; - GraphManager& operator=(const GraphManager& other) = delete; - GraphManager& operator=(GraphManager&& other) = delete; - ~GraphManager() override = default; - - public: - ID2D1Factory1* GetD2D1Factory() const { return d2d1_factory_.Get(); } - - ID2D1DeviceContext* GetD2D1DeviceContext() const { - return d2d1_device_context_.Get(); - } - - ID3D11Device* GetD3D11Device() const { return d3d11_device_.Get(); } - - IDXGIFactory2* GetDxgiFactory() const { return dxgi_factory_.Get(); } - - IDWriteFactory* GetDWriteFactory() const { return dwrite_factory_.Get(); } - - IDWriteFontCollection* GetSystemFontCollection() const { - return dwrite_system_font_collection_.Get(); - } - - WinGraphFactory* GetGraphFactory() const { return graph_factory_.get(); } - - private: - Microsoft::WRL::ComPtr<ID3D11Device> d3d11_device_; - Microsoft::WRL::ComPtr<ID2D1Factory1> d2d1_factory_; - Microsoft::WRL::ComPtr<ID2D1DeviceContext> d2d1_device_context_; - Microsoft::WRL::ComPtr<IDXGIFactory2> dxgi_factory_; - Microsoft::WRL::ComPtr<IDWriteFactory> dwrite_factory_; - Microsoft::WRL::ComPtr<IDWriteFontCollection> dwrite_system_font_collection_; - - std::unique_ptr<WinGraphFactory> graph_factory_; -}; -} // namespace cru::win::graph diff --git a/include/cru/win/graph/d2d_util.hpp b/include/cru/win/graph/util/convert_util.hpp index 7a2da91f..4b5368b1 100644 --- a/include/cru/win/graph/d2d_util.hpp +++ b/include/cru/win/graph/util/convert_util.hpp @@ -1,5 +1,5 @@ #pragma once -#include "../win_pre_config.hpp" +#include "../../win_pre_config.hpp" #include "cru/common/ui_base.hpp" #include "cru/platform/matrix.hpp" diff --git a/include/cru/win/graph/win_brush.hpp b/include/cru/win/graph/win_brush.hpp index 69cd952d..c81019c0 100644 --- a/include/cru/win/graph/win_brush.hpp +++ b/include/cru/win/graph/win_brush.hpp @@ -4,18 +4,17 @@ #include "cru/platform/graph/brush.hpp" namespace cru::win::graph { -class GraphManager; +struct IWinNativeFactory; -struct WinBrush : virtual platform::graph::Brush { +struct IWinBrush : virtual platform::graph::IBrush { virtual ID2D1Brush* GetD2DBrush() = 0; }; class WinSolidColorBrush : public Object, - public virtual platform::graph::SolidColorBrush, - public virtual WinBrush { + public virtual platform::graph::ISolidColorBrush, + public virtual IWinBrush { public: - explicit WinSolidColorBrush(GraphManager* graph_manager, - const ui::Color& color); + WinSolidColorBrush(IWinNativeFactory* factory, const ui::Color& color); WinSolidColorBrush(const WinSolidColorBrush& other) = delete; WinSolidColorBrush(WinSolidColorBrush&& other) = delete; WinSolidColorBrush& operator=(const WinSolidColorBrush& other) = delete; diff --git a/include/cru/win/graph/win_font.hpp b/include/cru/win/graph/win_font.hpp index 3301e8da..44fa7edd 100644 --- a/include/cru/win/graph/win_font.hpp +++ b/include/cru/win/graph/win_font.hpp @@ -6,12 +6,12 @@ #include <string_view> namespace cru::win::graph { -class GraphManager; +struct IWinNativeFactory; class WinFontDescriptor : public Object, - public virtual platform::graph::FontDescriptor { + public virtual platform::graph::IFontDescriptor { public: - explicit WinFontDescriptor(GraphManager* graph_manager, + explicit WinFontDescriptor(IWinNativeFactory* factory, const std::wstring_view& font_family, float font_size); WinFontDescriptor(const WinFontDescriptor& other) = delete; diff --git a/include/cru/win/graph/win_geometry.hpp b/include/cru/win/graph/win_geometry.hpp index 005a4384..e312f13c 100644 --- a/include/cru/win/graph/win_geometry.hpp +++ b/include/cru/win/graph/win_geometry.hpp @@ -4,32 +4,32 @@ #include "cru/platform/graph/geometry.hpp" namespace cru::win::graph { -class GraphManager; +struct IWinNativeFactory; class WinGeometryBuilder : public Object, - public virtual platform::graph::GeometryBuilder { + public virtual platform::graph::IGeometryBuilder { public: - explicit WinGeometryBuilder(GraphManager* graph_manger); + explicit WinGeometryBuilder(IWinNativeFactory* factory); WinGeometryBuilder(const WinGeometryBuilder& other) = delete; WinGeometryBuilder(WinGeometryBuilder&& other) = delete; WinGeometryBuilder& operator=(const WinGeometryBuilder& other) = delete; WinGeometryBuilder& operator=(WinGeometryBuilder&& other) = delete; ~WinGeometryBuilder() override; - bool IsValid() override { return geometry_ != nullptr; } void BeginFigure(const ui::Point& point) override; void LineTo(const ui::Point& point) override; void QuadraticBezierTo(const ui::Point& control_point, const ui::Point& end_point) override; void CloseFigure(bool close) override; - platform::graph::Geometry* Build() override; + platform::graph::IGeometry* End() override; + bool IsEnded() const override { return geometry_ != nullptr; } private: Microsoft::WRL::ComPtr<ID2D1PathGeometry> geometry_; Microsoft::WRL::ComPtr<ID2D1GeometrySink> geometry_sink_; }; -class WinGeometry : public Object, public virtual platform::graph::Geometry { +class WinGeometry : public Object, public virtual platform::graph::IGeometry { public: explicit WinGeometry(Microsoft::WRL::ComPtr<ID2D1PathGeometry> geometry); WinGeometry(const WinGeometry& other) = delete; diff --git a/include/cru/win/graph/win_graph_factory.hpp b/include/cru/win/graph/win_graph_factory.hpp index f8a07819..02f1a0fc 100644 --- a/include/cru/win/graph/win_graph_factory.hpp +++ b/include/cru/win/graph/win_graph_factory.hpp @@ -2,29 +2,60 @@ #include "../win_pre_config.hpp" #include "cru/platform/graph/graph_factory.hpp" +#include "win_native_factory.hpp" namespace cru::win::graph { -class GraphManager; - class WinGraphFactory : public Object, - public virtual platform::graph::GraphFactory { + public virtual platform::graph::IGraphFactory, + public virtual IWinNativeFactory { + friend IGraphFactory* ::cru::platform::graph::IGraphFactory::CreateInstance(); + + public: + static WinGraphFactory* GetInstance(); + + private: + explicit WinGraphFactory(); + public: - explicit WinGraphFactory(GraphManager* graph_manager); WinGraphFactory(const WinGraphFactory& other) = delete; WinGraphFactory(WinGraphFactory&& other) = delete; WinGraphFactory& operator=(const WinGraphFactory& other) = delete; WinGraphFactory& operator=(WinGraphFactory&& other) = delete; - ~WinGraphFactory() override = default; + ~WinGraphFactory() override; + + ID2D1Factory1* GetD2D1Factory() const override { return d2d1_factory_.Get(); } + ID2D1DeviceContext* GetD2D1DeviceContext() const override { + return d2d1_device_context_.Get(); + } + ID3D11Device* GetD3D11Device() const override { return d3d11_device_.Get(); } + IDXGIFactory2* GetDxgiFactory() const override { return dxgi_factory_.Get(); } + IDWriteFactory* GetDWriteFactory() const override { + return dwrite_factory_.Get(); + } + IDWriteFontCollection* GetSystemFontCollection() const override { + return dwrite_system_font_collection_.Get(); + } - platform::graph::SolidColorBrush* CreateSolidColorBrush( + platform::graph::ISolidColorBrush* CreateSolidColorBrush( const ui::Color& color) override; - platform::graph::GeometryBuilder* CreateGeometryBuilder() override; - platform::graph::FontDescriptor* CreateFontDescriptor( + platform::graph::IGeometryBuilder* CreateGeometryBuilder() override; + platform::graph::IFontDescriptor* CreateFontDescriptor( const std::wstring_view& font_family, float font_size); - platform::graph::TextLayout* CreateTextLayout( - std::shared_ptr<platform::graph::FontDescriptor> font, std::wstring text); + platform::graph::ITextLayout* CreateTextLayout( + std::shared_ptr<platform::graph::IFontDescriptor> font, + std::wstring text); + + bool IsAutoDelete() const override { return auto_delete_; } + void SetAutoDelete(bool value) override { auto_delete_ = value; } private: - GraphManager* graph_manager_; + bool auto_delete_ = false; + + Microsoft::WRL::ComPtr<ID3D11Device> d3d11_device_; + Microsoft::WRL::ComPtr<ID2D1Factory1> d2d1_factory_; + Microsoft::WRL::ComPtr<ID2D1DeviceContext> d2d1_device_context_; + Microsoft::WRL::ComPtr<IDXGIFactory2> dxgi_factory_; + Microsoft::WRL::ComPtr<IDWriteFactory> dwrite_factory_; + Microsoft::WRL::ComPtr<IDWriteFontCollection> dwrite_system_font_collection_; }; } // namespace cru::win::graph diff --git a/include/cru/win/graph/win_native_factory.hpp b/include/cru/win/graph/win_native_factory.hpp new file mode 100644 index 00000000..f5ad033c --- /dev/null +++ b/include/cru/win/graph/win_native_factory.hpp @@ -0,0 +1,16 @@ +#pragma once +#include "../win_pre_config.hpp" + +#include "cru/common/base.hpp" + +namespace cru::win::graph { +// Interface provides access to root d2d resources. +struct IWinNativeFactory : virtual Interface { + virtual ID2D1Factory1* GetD2D1Factory() const = 0; + virtual ID2D1DeviceContext* GetD2D1DeviceContext() const = 0; + virtual ID3D11Device* GetD3D11Device() const = 0; + virtual IDXGIFactory2* GetDxgiFactory() const = 0; + virtual IDWriteFactory* GetDWriteFactory() const = 0; + virtual IDWriteFontCollection* GetSystemFontCollection() const = 0; +}; +} diff --git a/include/cru/win/graph/win_painter.hpp b/include/cru/win/graph/win_painter.hpp new file mode 100644 index 00000000..f218488c --- /dev/null +++ b/include/cru/win/graph/win_painter.hpp @@ -0,0 +1,43 @@ +#pragma once +#include "../win_pre_config.hpp" + +#include "cru/platform/graph/painter.hpp" + +namespace cru::win::graph { +class GraphManager; + +class WinPainter : public Object, public virtual platform::graph::IPainter { + public: + explicit WinPainter(ID2D1RenderTarget* render_target); + WinPainter(const WinPainter& other) = delete; + WinPainter(WinPainter&& other) = delete; + WinPainter& operator=(const WinPainter& other) = delete; + WinPainter& operator=(WinPainter&& other) = delete; + ~WinPainter() override = default; + + platform::Matrix GetTransform() override; + void SetTransform(const platform::Matrix& matrix) override; + void Clear(const ui::Color& color) override; + void StrokeRectangle(const ui::Rect& rectangle, platform::graph::IBrush* brush, + float width) override; + void FillRectangle(const ui::Rect& rectangle, + platform::graph::IBrush* brush) override; + void StrokeGeometry(platform::graph::IGeometry* geometry, + platform::graph::IBrush* brush, float width) override; + void FillGeometry(platform::graph::IGeometry* geometry, + platform::graph::IBrush* brush) override; + void DrawText(const ui::Point& offset, + platform::graph::ITextLayout* text_layout, + platform::graph::IBrush* brush) override; + void End() override final; + bool IsEnded() const override final { return is_draw_ended_; } + + protected: + virtual void DoEndDraw() = 0; + + private: + ID2D1RenderTarget* render_target_; + + bool is_draw_ended_ = false; +}; +} // namespace cru::win::graph diff --git a/include/cru/win/graph/win_text_layout.hpp b/include/cru/win/graph/win_text_layout.hpp index b861fda7..7339eff9 100644 --- a/include/cru/win/graph/win_text_layout.hpp +++ b/include/cru/win/graph/win_text_layout.hpp @@ -6,12 +6,12 @@ #include <memory> namespace cru::win::graph { -class GraphManager; +struct IWinNativeFactory; class WinFontDescriptor; -class WinTextLayout : public Object, public virtual platform::graph::TextLayout { +class WinTextLayout : public Object, public virtual platform::graph::ITextLayout { public: - explicit WinTextLayout(GraphManager* graph_manager, + explicit WinTextLayout(IWinNativeFactory* factory, std::shared_ptr<WinFontDescriptor> font, std::wstring text); WinTextLayout(const WinTextLayout& other) = delete; WinTextLayout(WinTextLayout&& other) = delete; @@ -21,8 +21,8 @@ class WinTextLayout : public Object, public virtual platform::graph::TextLayout std::wstring GetText() override; void SetText(std::wstring new_text) override; - std::shared_ptr<platform::graph::FontDescriptor> GetFont(); - void SetFont(std::shared_ptr<platform::graph::FontDescriptor> font); + std::shared_ptr<platform::graph::IFontDescriptor> GetFont(); + void SetFont(std::shared_ptr<platform::graph::IFontDescriptor> font); void SetMaxWidth(float max_width) override; void SetMaxHeight(float max_height) override; ui::Rect GetTextBounds() override; @@ -32,7 +32,7 @@ class WinTextLayout : public Object, public virtual platform::graph::TextLayout IDWriteTextLayout* GetDWriteTextLayout() const { return text_layout_.Get(); } private: - GraphManager* graph_manager_; + IWinNativeFactory* factory_; std::wstring text_; std::shared_ptr<WinFontDescriptor> font_descriptor_; float max_width_ = 0.0f; diff --git a/include/cru/win/native/win_native_window.hpp b/include/cru/win/native/win_native_window.hpp index 2b9be25d..272ca14b 100644 --- a/include/cru/win/native/win_native_window.hpp +++ b/include/cru/win/native/win_native_window.hpp @@ -45,7 +45,7 @@ class WinNativeWindow : public Object, // The lefttop of the rect is relative to screen lefttop. void SetWindowRect(const ui::Rect& rect) override; - platform::graph::Painter* BeginPaint() override; + platform::graph::IPainter* BeginPaint() override; Event<>* DestroyEvent() override { return &destroy_event_; } Event<const ui::Size&>* ResizeEvent() override { return &resize_event_; } diff --git a/include/cru/win/native/window_render_target.hpp b/include/cru/win/native/window_render_target.hpp index c55055c6..5ff8ec87 100644 --- a/include/cru/win/native/window_render_target.hpp +++ b/include/cru/win/native/window_render_target.hpp @@ -4,14 +4,14 @@ #include "cru/common/base.hpp" namespace cru::win::graph { -class GraphManager; +struct IWinNativeFactory; } namespace cru::win::native { // Represents a window render target. class WindowRenderTarget : public Object { public: - WindowRenderTarget(graph::GraphManager* graph_manager, HWND hwnd); + WindowRenderTarget(graph::IWinNativeFactory* factory, HWND hwnd); WindowRenderTarget(const WindowRenderTarget& other) = delete; WindowRenderTarget(WindowRenderTarget&& other) = delete; WindowRenderTarget& operator=(const WindowRenderTarget& other) = delete; @@ -19,8 +19,7 @@ class WindowRenderTarget : public Object { ~WindowRenderTarget() override = default; public: - // Get the graph manager that created the render target. - graph::GraphManager* GetGraphManager() const { return graph_manager_; } + graph::IWinNativeFactory* GetWinNativeFactory() const { return factory_; } // Get the target bitmap which can be set as the ID2D1DeviceContext's target. ID2D1Bitmap1* GetTargetBitmap() const { return target_bitmap_.Get(); } @@ -38,7 +37,7 @@ class WindowRenderTarget : public Object { void CreateTargetBitmap(); private: - graph::GraphManager* graph_manager_; + graph::IWinNativeFactory* factory_; Microsoft::WRL::ComPtr<IDXGISwapChain1> dxgi_swap_chain_; Microsoft::WRL::ComPtr<ID2D1Bitmap1> target_bitmap_; }; |