diff --git a/src/kiwano/2d/Canvas.cpp b/src/kiwano/2d/Canvas.cpp index 09c9e911..c778f2e9 100644 --- a/src/kiwano/2d/Canvas.cpp +++ b/src/kiwano/2d/Canvas.cpp @@ -223,21 +223,22 @@ void Canvas::DrawTexture(TexturePtr texture, const Rect* src_rect, const Rect* d } } -void Canvas::DrawTextLayout(String const& text, Point const& point) +void Canvas::DrawTextLayout(String const& text, TextStyle const& style, Point const& point) { if (text.empty()) return; - TextLayout layout; - layout.SetStyle(text_style_); - layout.SetText(text); - DrawTextLayout(layout, point); + DrawTextLayout(TextLayout::Create(text, style), point); } -void Canvas::DrawTextLayout(TextLayout const& layout, Point const& point) +void Canvas::DrawTextLayout(TextLayoutPtr layout, Point const& point) { KGE_ASSERT(ctx_); - ctx_->DrawTextLayout(layout, point); + if (layout) + { + ctx_->DrawTextLayout(*layout, point); + cache_expired_ = true; + } } void Canvas::BeginPath(Point const& begin_pos) diff --git a/src/kiwano/2d/Canvas.h b/src/kiwano/2d/Canvas.h index b08696b8..d5580bc9 100644 --- a/src/kiwano/2d/Canvas.h +++ b/src/kiwano/2d/Canvas.h @@ -126,14 +126,15 @@ public: /// \~chinese /// @brief 绘制文字布局 /// @param text 文字 + /// @param style 文字样式 /// @param point 绘制文字的位置 - void DrawTextLayout(String const& text, Point const& point); + void DrawTextLayout(String const& text, TextStyle const& style, Point const& point); /// \~chinese /// @brief 绘制文字布局 /// @param layout 文字布局 /// @param point 绘制布局的位置 - void DrawTextLayout(TextLayout const& layout, Point const& point); + void DrawTextLayout(TextLayoutPtr layout, Point const& point); /// \~chinese /// @brief 开始绘制路径 @@ -218,11 +219,6 @@ public: /// @param stroke_style 轮廓样式 void SetStrokeStyle(StrokeStylePtr stroke_style); - /// \~chinese - /// @brief 设置文字画刷样式 - /// @param text_style 文字画刷样式 - void SetTextStyle(TextStyle const& text_style); - /// \~chinese /// @brief 设置画刷 /// @param[in] brush 画刷 @@ -285,7 +281,6 @@ private: private: float stroke_width_; - TextStyle text_style_; StrokeStylePtr stroke_style_; ShapeSink shape_sink_; BrushPtr fill_brush_; @@ -313,11 +308,6 @@ inline void Canvas::SetStrokeStyle(StrokeStylePtr stroke_style) stroke_style_ = stroke_style; } -inline void Canvas::SetTextStyle(TextStyle const& text_style) -{ - text_style_ = text_style; -} - inline void Canvas::SetStrokeColor(Color const& color) { if (!stroke_brush_) diff --git a/src/kiwano/2d/DebugActor.cpp b/src/kiwano/2d/DebugActor.cpp index c5811996..0f8626b2 100644 --- a/src/kiwano/2d/DebugActor.cpp +++ b/src/kiwano/2d/DebugActor.cpp @@ -59,13 +59,11 @@ DebugActor::DebugActor() BrushPtr fill_brush = new Brush; fill_brush->SetColor(Color::White); - TextStyle style; - style.font_family = "Arial"; - style.font_size = 16.f; - style.font_weight = FontWeight::Normal; - style.line_spacing = 20.f; - style.fill_brush = fill_brush; - debug_text_.SetStyle(style); + debug_text_style_.font_family = "Arial"; + debug_text_style_.font_size = 16.f; + debug_text_style_.font_weight = FontWeight::Normal; + debug_text_style_.line_spacing = 20.f; + debug_text_style_.fill_brush = fill_brush; AddListener([=](Event*) { SetOpacity(0.4f); }); AddListener([=](Event*) { SetOpacity(1.f); }); @@ -124,8 +122,7 @@ void DebugActor::OnUpdate(Duration dt) ss << pmc.PrivateUsage / 1024 << "Kb"; } - debug_text_.SetText(ss.str()); - debug_text_.Update(); + debug_text_.Reset(ss.str(), debug_text_style_); Size layout_size = debug_text_.GetLayoutSize(); if (layout_size.x > GetWidth() - 20) diff --git a/src/kiwano/2d/DebugActor.h b/src/kiwano/2d/DebugActor.h index 2a0a9c73..7b56a6bf 100644 --- a/src/kiwano/2d/DebugActor.h +++ b/src/kiwano/2d/DebugActor.h @@ -50,6 +50,7 @@ protected: private: std::locale comma_locale_; BrushPtr background_brush_; + TextStyle debug_text_style_; TextLayout debug_text_; List