2024-02-25 14:46:47 +00:00
|
|
|
#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;
|
2023-06-20 14:59:41 +00:00
|
|
|
|
|
|
|
struct GlyphTexture {
|
|
|
|
TexturePtr texture;
|
2024-04-23 21:44:53 +00:00
|
|
|
bool colored = false;
|
|
|
|
int64_t time = 0;
|
2023-07-03 04:21:51 +00:00
|
|
|
Vec2F offset;
|
2023-06-20 14:59:41 +00:00
|
|
|
};
|
|
|
|
|
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);
|
2023-06-20 14:59:41 +00:00
|
|
|
|
|
|
|
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();
|
2024-04-23 21:44:53 +00:00
|
|
|
void addFont(FontPtr const& font, String const& name);
|
2023-06-21 13:13:37 +00:00
|
|
|
void clearFonts();
|
2024-04-23 21:44:53 +00:00
|
|
|
void setFixedFonts(String const& defaultFontName, String const& fallbackFontName, String const& emojiFontName);
|
2023-06-20 04:33:09 +00:00
|
|
|
private:
|
2024-04-23 21:44:53 +00:00
|
|
|
Font* getFontForCharacter(String::Char);
|
|
|
|
|
2023-08-02 15:17:08 +00:00
|
|
|
CaseInsensitiveStringMap<FontPtr> m_fonts;
|
2023-06-21 09:46:23 +00:00
|
|
|
String m_fontName;
|
2024-04-23 21:44:53 +00:00
|
|
|
FontPtr m_activeFont;
|
2023-06-21 09:46:23 +00:00
|
|
|
FontPtr m_defaultFont;
|
2024-04-21 22:17:10 +00:00
|
|
|
FontPtr m_fallbackFont;
|
2024-04-23 21:44:53 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|