osb/source/rendering/StarFontTextureGroup.hpp

54 lines
1.4 KiB
C++
Raw Normal View History

2023-06-20 04:33:09 +00:00
#ifndef STAR_FONT_TEXTURE_GROUP_HPP
#define STAR_FONT_TEXTURE_GROUP_HPP
#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;
int64_t time;
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, bool isDefault = false);
2023-06-21 13:13:37 +00:00
void clearFonts();
2023-06-20 04:33:09 +00:00
private:
CaseInsensitiveStringMap<FontPtr> m_fonts;
2023-06-21 09:46:23 +00:00
String m_fontName;
2023-06-20 04:33:09 +00:00
FontPtr m_font;
2023-06-21 09:46:23 +00:00
FontPtr m_defaultFont;
2023-06-20 04:33:09 +00:00
TextureGroupPtr m_textureGroup;
HashMap<GlyphDescriptor, GlyphTexture> m_glyphs;
};
}
#endif