osb/source/rendering/StarFontTextureGroup.hpp

57 lines
1.6 KiB
C++
Raw Normal View History

#pragma once
2023-06-20 04:33:09 +00:00
#include "StarColor.hpp"
#include "StarFont.hpp"
#include "StarRenderer.hpp"
2023-07-03 20:01:29 +00:00
#include "StarDirectives.hpp"
2023-06-20 04:33:09 +00:00
namespace Star {
STAR_CLASS(FontTextureGroup);
class FontTextureGroup {
public:
2023-06-21 09:46:23 +00:00
// Font* is only included for key uniqueness and should not be dereferenced
2023-07-03 20:01:29 +00:00
typedef tuple<String::Char, unsigned, size_t, Font*> GlyphDescriptor;
struct GlyphTexture {
TexturePtr texture;
bool colored = false;
int64_t time = 0;
Vec2F offset;
};
2023-06-21 09:46:23 +00:00
FontTextureGroup(TextureGroupPtr textureGroup);
2023-06-20 04:33:09 +00:00
2023-07-03 20:01:29 +00:00
const GlyphTexture& glyphTexture(String::Char, unsigned fontSize, Directives const* processingDirectives = nullptr);
TexturePtr glyphTexturePtr(String::Char, unsigned fontSize);
2023-07-03 20:01:29 +00:00
TexturePtr glyphTexturePtr(String::Char, unsigned fontSize, Directives const* processingDirectives = nullptr);
2023-06-20 04:33:09 +00:00
unsigned glyphWidth(String::Char c, unsigned fontSize);
// Removes glyphs that haven't been used in more than the given time in
// milliseconds
void cleanup(int64_t timeout);
2023-06-21 09:46:23 +00:00
// Switches the current font
void switchFont(String const& font);
2023-06-21 12:29:40 +00:00
String const& activeFont();
void addFont(FontPtr const& font, String const& name);
2023-06-21 13:13:37 +00:00
void clearFonts();
void setFixedFonts(String const& defaultFontName, String const& fallbackFontName, String const& emojiFontName);
2023-06-20 04:33:09 +00:00
private:
Font* getFontForCharacter(String::Char);
CaseInsensitiveStringMap<FontPtr> m_fonts;
2023-06-21 09:46:23 +00:00
String m_fontName;
FontPtr m_activeFont;
2023-06-21 09:46:23 +00:00
FontPtr m_defaultFont;
FontPtr m_fallbackFont;
FontPtr m_emojiFont;
2023-06-21 09:46:23 +00:00
2023-06-20 04:33:09 +00:00
TextureGroupPtr m_textureGroup;
HashMap<GlyphDescriptor, GlyphTexture> m_glyphs;
};
}