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); } }