Utility/SimpleTextDrawer: Add Clear method
Former-commit-id: 10f7c36edb7f0d1705709b070e78792708cdbebf
This commit is contained in:
parent
f273c0229c
commit
b9ec4a4fc4
|
|
@ -26,6 +26,8 @@ namespace Nz
|
||||||
|
|
||||||
void AppendText(const String& str);
|
void AppendText(const String& str);
|
||||||
|
|
||||||
|
void Clear();
|
||||||
|
|
||||||
const Rectui& GetBounds() const override;
|
const Rectui& GetBounds() const override;
|
||||||
unsigned int GetCharacterSize() const;
|
unsigned int GetCharacterSize() const;
|
||||||
const Color& GetColor() 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);
|
static SimpleTextDrawer Draw(Font* font, const String& str, unsigned int characterSize, UInt32 style = TextStyle_Regular, const Color& color = Color::White);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void ClearGlyphs() const;
|
||||||
void ConnectFontSlots();
|
void ConnectFontSlots();
|
||||||
void DisconnectFontSlots();
|
void DisconnectFontSlots();
|
||||||
void GenerateGlyphs(const String& text) const;
|
void GenerateGlyphs(const String& text) const;
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,8 @@ namespace Nz
|
||||||
SimpleTextDrawer::SimpleTextDrawer() :
|
SimpleTextDrawer::SimpleTextDrawer() :
|
||||||
m_color(Color::White),
|
m_color(Color::White),
|
||||||
m_style(TextStyle_Regular),
|
m_style(TextStyle_Regular),
|
||||||
m_glyphUpdated(false)
|
m_glyphUpdated(false),
|
||||||
|
m_characterSize(24)
|
||||||
{
|
{
|
||||||
SetFont(Font::GetDefault());
|
SetFont(Font::GetDefault());
|
||||||
}
|
}
|
||||||
|
|
@ -40,6 +41,12 @@ namespace Nz
|
||||||
GenerateGlyphs(str);
|
GenerateGlyphs(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SimpleTextDrawer::Clear()
|
||||||
|
{
|
||||||
|
m_text.Clear(true);
|
||||||
|
ClearGlyphs();
|
||||||
|
}
|
||||||
|
|
||||||
const Rectui& SimpleTextDrawer::GetBounds() const
|
const Rectui& SimpleTextDrawer::GetBounds() const
|
||||||
{
|
{
|
||||||
if (!m_glyphUpdated)
|
if (!m_glyphUpdated)
|
||||||
|
|
@ -199,6 +206,16 @@ namespace Nz
|
||||||
return drawer;
|
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()
|
void SimpleTextDrawer::ConnectFontSlots()
|
||||||
{
|
{
|
||||||
m_atlasChangedSlot.Connect(m_font->OnFontAtlasChanged, this, &SimpleTextDrawer::OnFontInvalidated);
|
m_atlasChangedSlot.Connect(m_font->OnFontAtlasChanged, this, &SimpleTextDrawer::OnFontInvalidated);
|
||||||
|
|
@ -374,13 +391,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
NazaraAssert(m_font && m_font->IsValid(), "Invalid font");
|
NazaraAssert(m_font && m_font->IsValid(), "Invalid font");
|
||||||
|
|
||||||
m_bounds.MakeZero();
|
ClearGlyphs();
|
||||||
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)
|
|
||||||
|
|
||||||
GenerateGlyphs(m_text);
|
GenerateGlyphs(m_text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue