From dcd866074615ba357b62b6128f1c64d56ed4ad16 Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 4 Apr 2019 14:14:07 +0800 Subject: ... --- include/cru/platform/graph_factory.hpp | 7 +++++++ include/cru/platform/text_layout.hpp | 3 +++ include/cru/platform/win/win_text_layout.hpp | 18 +++++++++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/cru/platform/graph_factory.hpp b/include/cru/platform/graph_factory.hpp index f2e5f286..312dc0ea 100644 --- a/include/cru/platform/graph_factory.hpp +++ b/include/cru/platform/graph_factory.hpp @@ -3,12 +3,19 @@ #include "cru/common/ui_base.hpp" +#include +#include + namespace cru::platform { struct SolidColorBrush; struct GeometryBuilder; +struct FontDescriptor; +struct TextLayout; struct GraphFactory : virtual Interface { virtual SolidColorBrush* CreateSolidColorBrush(const ui::Color& color) = 0; virtual GeometryBuilder* CreateGeometryBuilder() = 0; + virtual FontDescriptor* CreateFontDescriptor(const std::wstring_view& font_family) = 0; + virtual TextLayout* CreateTextLayout(std::shared_ptr font, std::wstring text) = 0; }; } // namespace cru::platform diff --git a/include/cru/platform/text_layout.hpp b/include/cru/platform/text_layout.hpp index fce6ce5f..7bcf01fe 100644 --- a/include/cru/platform/text_layout.hpp +++ b/include/cru/platform/text_layout.hpp @@ -4,9 +4,12 @@ #include "cru/common/ui_base.hpp" #include +#include namespace cru::platform { struct TextLayout : virtual Interface { + virtual std::wstring GetText() = 0; + virtual void SetText(std::wstring new_text) = 0; virtual void SetMaxWidth(float max_width) = 0; virtual void SetMaxHeight(float max_height) = 0; virtual ui::Rect GetTextBounds() = 0; diff --git a/include/cru/platform/win/win_text_layout.hpp b/include/cru/platform/win/win_text_layout.hpp index 68961dd7..277bbcae 100644 --- a/include/cru/platform/win/win_text_layout.hpp +++ b/include/cru/platform/win/win_text_layout.hpp @@ -7,18 +7,34 @@ #include namespace cru::platform::win { +class GraphManager; + class WinTextLayout : public Object, public virtual TextLayout { public: - explicit WinTextLayout(std::shared_ptr font); + explicit WinTextLayout(GraphManager* graph_manager, + std::shared_ptr font, std::wstring text); WinTextLayout(const WinTextLayout& other) = delete; WinTextLayout(WinTextLayout&& other) = delete; WinTextLayout& operator=(const WinTextLayout& other) = delete; WinTextLayout& operator=(WinTextLayout&& other) = delete; ~WinTextLayout() override; + std::wstring GetText() override; + void SetText(std::wstring new_text) override; + void SetMaxWidth(float max_width) override; + void SetMaxHeight(float max_height) override; + ui::Rect GetTextBounds() override; + std::vector TextRangeRect( + const ui::TextRange& text_range) override; + IDWriteTextLayout* GetDWriteTextLayout() const { return text_layout_.Get(); } private: + GraphManager* graph_manager_; + std::wstring text_; + std::shared_ptr font_descriptor_; + float max_width_ = 0.0f; + float max_height_ = 0.0f; Microsoft::WRL::ComPtr text_layout_; }; } // namespace cru::platform::win -- cgit v1.2.3