diff options
Diffstat (limited to 'include/cru/win/graph/direct/text_layout.hpp')
-rw-r--r-- | include/cru/win/graph/direct/text_layout.hpp | 55 |
1 files changed, 34 insertions, 21 deletions
diff --git a/include/cru/win/graph/direct/text_layout.hpp b/include/cru/win/graph/direct/text_layout.hpp index 7339eff9..c7657762 100644 --- a/include/cru/win/graph/direct/text_layout.hpp +++ b/include/cru/win/graph/direct/text_layout.hpp @@ -1,42 +1,55 @@ #pragma once -#include "../win_pre_config.hpp" +#include "com_resource.hpp" +#include "direct_factory.hpp" +#include "platform_id.hpp" #include "cru/platform/graph/text_layout.hpp" +#include "font.hpp" + #include <memory> -namespace cru::win::graph { -struct IWinNativeFactory; -class WinFontDescriptor; +namespace cru::platform::graph::win::direct { +class DWriteTextLayout : public TextLayout, + public IComResource<IDWriteTextLayout> { + public: + explicit DWriteTextLayout(IDirectFactory* factory, std::shared_ptr<Font> font, + std::wstring text); + + DWriteTextLayout(const DWriteTextLayout& other) = delete; + DWriteTextLayout& operator=(const DWriteTextLayout& other) = delete; + + DWriteTextLayout(DWriteTextLayout&& other) = delete; + DWriteTextLayout& operator=(DWriteTextLayout&& other) = delete; + + ~DWriteTextLayout() override = default; + + CRU_PLATFORMID_IMPLEMENT_DIRECT -class WinTextLayout : public Object, public virtual platform::graph::ITextLayout { public: - explicit WinTextLayout(IWinNativeFactory* factory, - std::shared_ptr<WinFontDescriptor> 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 = default; + IDWriteTextLayout* GetComInterface() const override { + return text_layout_.Get(); + } + public: std::wstring GetText() override; void SetText(std::wstring new_text) override; - std::shared_ptr<platform::graph::IFontDescriptor> GetFont(); - void SetFont(std::shared_ptr<platform::graph::IFontDescriptor> font); + + std::shared_ptr<Font> GetFont(); + void SetFont(std::shared_ptr<Font> font); + void SetMaxWidth(float max_width) override; void SetMaxHeight(float max_height) override; - ui::Rect GetTextBounds() override; - std::vector<ui::Rect> TextRangeRect( - const ui::TextRange& text_range) override; - IDWriteTextLayout* GetDWriteTextLayout() const { return text_layout_.Get(); } + Rect GetTextBounds() override; + std::vector<Rect> TextRangeRect(const TextRange& text_range) override; private: - IWinNativeFactory* factory_; + IDirectFactory* factory_; std::wstring text_; - std::shared_ptr<WinFontDescriptor> font_descriptor_; + std::shared_ptr<DWriteFont> font_; float max_width_ = 0.0f; float max_height_ = 0.0f; Microsoft::WRL::ComPtr<IDWriteTextLayout> text_layout_; }; -} // namespace cru::platform::win +} // namespace cru::platform::graph::win::direct |