From 4562243c5fcccf213e521165a2ff63f98e935c29 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 8 Jan 2016 14:00:54 +0100 Subject: [PATCH] Utility/SimpleTextDrawer: Update SetColor method (will no longer force full regeneration) Former-commit-id: 3f3043ea5c5d3add1358d50eb3f92e452d931dbf --- include/Nazara/Utility/SimpleTextDrawer.hpp | 2 ++ src/Nazara/Utility/SimpleTextDrawer.cpp | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/include/Nazara/Utility/SimpleTextDrawer.hpp b/include/Nazara/Utility/SimpleTextDrawer.hpp index 67de92a4c..3f87bf3bb 100644 --- a/include/Nazara/Utility/SimpleTextDrawer.hpp +++ b/include/Nazara/Utility/SimpleTextDrawer.hpp @@ -59,6 +59,7 @@ namespace Nz void OnFontAtlasLayerChanged(const Font* font, AbstractImage* oldLayer, AbstractImage* newLayer); void OnFontInvalidated(const Font* font); void OnFontRelease(const Font* object); + void UpdateGlyphColor() const; void UpdateGlyphs() const; NazaraSlot(Font, OnFontAtlasChanged, m_atlasChangedSlot); @@ -75,6 +76,7 @@ namespace Nz mutable UInt32 m_previousCharacter; UInt32 m_style; mutable Vector2ui m_drawPos; + mutable bool m_colorUpdated; mutable bool m_glyphUpdated; unsigned int m_characterSize; }; diff --git a/src/Nazara/Utility/SimpleTextDrawer.cpp b/src/Nazara/Utility/SimpleTextDrawer.cpp index 4efeb4332..cc2130c05 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_colorUpdated(true), + m_glyphUpdated(true), m_characterSize(24) { SetFont(Font::GetDefault()); @@ -21,6 +22,7 @@ namespace Nz m_color(drawer.m_color), m_text(drawer.m_text), m_style(drawer.m_style), + m_colorUpdated(false), m_glyphUpdated(false), m_characterSize(drawer.m_characterSize) { @@ -86,6 +88,8 @@ namespace Nz { if (!m_glyphUpdated) UpdateGlyphs(); + else if (!m_colorUpdated) + UpdateGlyphColor(); return m_glyphs[index]; } @@ -119,7 +123,7 @@ namespace Nz { m_color = color; - m_glyphUpdated = false; + m_colorUpdated = false; } void SimpleTextDrawer::SetFont(Font* font) @@ -158,6 +162,7 @@ namespace Nz m_style = drawer.m_style; m_text = drawer.m_text; + m_colorUpdated = false; m_glyphUpdated = false; SetFont(drawer.m_font); @@ -169,6 +174,7 @@ namespace Nz DisconnectFontSlots(); m_bounds = std::move(drawer.m_bounds); + m_colorUpdated = std::move(drawer.m_colorUpdated); m_characterSize = std::move(drawer.m_characterSize); m_color = std::move(drawer.m_color); m_glyphs = std::move(drawer.m_glyphs); @@ -209,6 +215,7 @@ namespace Nz void SimpleTextDrawer::ClearGlyphs() const { m_bounds.MakeZero(); + m_colorUpdated = true; m_drawPos.Set(0, m_characterSize); //< Our draw "cursor" m_glyphs.clear(); m_glyphUpdated = true; @@ -387,6 +394,14 @@ namespace Nz SetFont(nullptr); } + void SimpleTextDrawer::UpdateGlyphColor() const + { + for (Glyph& glyph : m_glyphs) + glyph.color = m_color; + + m_colorUpdated = true; + } + void SimpleTextDrawer::UpdateGlyphs() const { NazaraAssert(m_font && m_font->IsValid(), "Invalid font");