diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-21 19:46:23 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-21 19:46:23 +1000 |
commit | 8dce3349312927653b2ca7a33dcee0d2e6b69137 (patch) | |
tree | c2eb04711315d887c10c5ee649982ed37ea802dc /source/rendering/StarFontTextureGroup.cpp | |
parent | f2e64e17527f16966a37c788ca65e1e88bf44907 (diff) |
custom fonts!!
Diffstat (limited to 'source/rendering/StarFontTextureGroup.cpp')
-rw-r--r-- | source/rendering/StarFontTextureGroup.cpp | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/source/rendering/StarFontTextureGroup.cpp b/source/rendering/StarFontTextureGroup.cpp index 340a389..21f6d6a 100644 --- a/source/rendering/StarFontTextureGroup.cpp +++ b/source/rendering/StarFontTextureGroup.cpp @@ -4,17 +4,31 @@ namespace Star { -FontTextureGroup::FontTextureGroup(FontPtr font, TextureGroupPtr textureGroup) - : m_font(move(font)), m_textureGroup(move(textureGroup)) {} +FontTextureGroup::FontTextureGroup(TextureGroupPtr textureGroup) + : m_textureGroup(move(textureGroup)) {} void FontTextureGroup::cleanup(int64_t timeout) { int64_t currentTime = Time::monotonicMilliseconds(); eraseWhere(m_glyphs, [&](auto const& p) { return currentTime - p.second.time > timeout; }); } +void FontTextureGroup::switchFont(String const& font) { + if (m_fontName != font) { + m_fontName = font; + auto find = m_fonts.find(font); + m_font = find != m_fonts.end() ? find->second : m_defaultFont; + } +} + +void FontTextureGroup::addFont(FontPtr const& font, String const& name, bool default) { + m_fonts[name] = font; + if (default) + m_defaultFont = m_font = font; +} + const FontTextureGroup::GlyphTexture& FontTextureGroup::glyphTexture(String::Char c, unsigned size, String const& processingDirectives) { - auto res = m_glyphs.insert(GlyphDescriptor{c, size, processingDirectives}, GlyphTexture()); + auto res = m_glyphs.insert(GlyphDescriptor{c, size, processingDirectives, m_font.get() }, GlyphTexture()); if (res.second) { m_font->setPixelSize(size); |