From b9ec4a4fc4c557768ad4b9914ae170467c269dcc Mon Sep 17 00:00:00 2001 From: Lynix Date: Wed, 6 Jan 2016 19:05:26 +0100 Subject: [PATCH] Utility/SimpleTextDrawer: Add Clear method Former-commit-id: 10f7c36edb7f0d1705709b070e78792708cdbebf --- include/Nazara/Utility/SimpleTextDrawer.hpp | 3 +++ src/Nazara/Utility/SimpleTextDrawer.cpp | 27 +++++++++++++++------ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/include/Nazara/Utility/SimpleTextDrawer.hpp b/include/Nazara/Utility/SimpleTextDrawer.hpp index d2bbd336c..67de92a4c 100644 --- a/include/Nazara/Utility/SimpleTextDrawer.hpp +++ b/include/Nazara/Utility/SimpleTextDrawer.hpp @@ -26,6 +26,8 @@ namespace Nz void AppendText(const String& str); + void Clear(); + const Rectui& GetBounds() const override; unsigned int GetCharacterSize() const; const Color& GetColor() const; @@ -50,6 +52,7 @@ namespace Nz static SimpleTextDrawer Draw(Font* font, const String& str, unsigned int characterSize, UInt32 style = TextStyle_Regular, const Color& color = Color::White); private: + void ClearGlyphs() const; void ConnectFontSlots(); void DisconnectFontSlots(); void GenerateGlyphs(const String& text) const; diff --git a/src/Nazara/Utility/SimpleTextDrawer.cpp b/src/Nazara/Utility/SimpleTextDrawer.cpp index 62914cd06..4efeb4332 100644 --- a/src/Nazara/Utility/SimpleTextDrawer.cpp +++ b/src/Nazara/Utility/SimpleTextDrawer.cpp @@ -11,7 +11,8 @@ namespace Nz SimpleTextDrawer::SimpleTextDrawer() : m_color(Color::White), m_style(TextStyle_Regular), - m_glyphUpdated(false) + m_glyphUpdated(false), + m_characterSize(24) { SetFont(Font::GetDefault()); } @@ -40,6 +41,12 @@ namespace Nz GenerateGlyphs(str); } + void SimpleTextDrawer::Clear() + { + m_text.Clear(true); + ClearGlyphs(); + } + const Rectui& SimpleTextDrawer::GetBounds() const { if (!m_glyphUpdated) @@ -199,6 +206,16 @@ namespace Nz return drawer; } + void SimpleTextDrawer::ClearGlyphs() const + { + m_bounds.MakeZero(); + m_drawPos.Set(0, m_characterSize); //< Our draw "cursor" + m_glyphs.clear(); + m_glyphUpdated = true; + m_previousCharacter = 0; + m_workingBounds.MakeZero(); //< Compute bounds as float to speedup bounds computation (as casting between floats and integers is costly) + } + void SimpleTextDrawer::ConnectFontSlots() { m_atlasChangedSlot.Connect(m_font->OnFontAtlasChanged, this, &SimpleTextDrawer::OnFontInvalidated); @@ -374,13 +391,7 @@ namespace Nz { NazaraAssert(m_font && m_font->IsValid(), "Invalid font"); - m_bounds.MakeZero(); - m_drawPos.Set(0, m_characterSize); //< Our draw "cursor" - m_glyphs.clear(); - m_glyphUpdated = true; - m_previousCharacter = 0; - m_workingBounds.MakeZero(); //< Compute bounds as float to speedup bounds computation (as casting between floats and integers is costly) - + ClearGlyphs(); GenerateGlyphs(m_text); } }