From 09864c09e519eaa58e3a7269baad7f48e8145f4f Mon Sep 17 00:00:00 2001 From: crupest Date: Sun, 23 Sep 2018 17:58:28 +0800 Subject: Move CreateDefaultTextFormat to graph. --- CruUI/ui/controls/text_block.cpp | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) (limited to 'CruUI/ui/controls/text_block.cpp') diff --git a/CruUI/ui/controls/text_block.cpp b/CruUI/ui/controls/text_block.cpp index 8800fd91..f0ef41d9 100644 --- a/CruUI/ui/controls/text_block.cpp +++ b/CruUI/ui/controls/text_block.cpp @@ -21,8 +21,11 @@ namespace cru const Microsoft::WRL::ComPtr& init_brush) : Control(false) { text_format_ = init_text_format; + if (init_brush == nullptr) brush_ = CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::Black)); + else + brush_ = init_brush; selection_brush_ = CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::LightSkyBlue)); } @@ -60,7 +63,7 @@ namespace cru void TextBlock::RemoveTextLayoutHandler(const TextLayoutHandlerPtr& handler) { const auto find_result = std::find(text_layout_handlers_.cbegin(), text_layout_handlers_.cend(), - handler); + handler); if (find_result != text_layout_handlers_.cend()) text_layout_handlers_.erase(find_result); } @@ -259,23 +262,6 @@ namespace cru Repaint(); } - void TextBlock::CreateDefaultTextFormat() - { - const auto dwrite_factory = GetDWriteFactory(); - - ThrowIfFailed(dwrite_factory->CreateTextFormat( - L"΅ΘΟί", nullptr, - DWRITE_FONT_WEIGHT_NORMAL, - DWRITE_FONT_STYLE_NORMAL, - DWRITE_FONT_STRETCH_NORMAL, - 24.0, L"zh-cn", - &text_format_ - )); - - ThrowIfFailed(text_format_->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER)); - ThrowIfFailed(text_format_->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER)); - } - void TextBlock::RecreateTextLayout() { if (text_.empty()) @@ -287,7 +273,7 @@ namespace cru const auto dwrite_factory = GetDWriteFactory(); if (text_format_ == nullptr) - CreateDefaultTextFormat(); + text_format_ = graph::CreateDefaultTextFormat(); const auto&& size = GetSize(); -- cgit v1.2.3