refactor font loading
This commit is contained in:
21
src/font.h
21
src/font.h
@@ -13,12 +13,18 @@ public:
|
||||
// {mix, max}
|
||||
glm::vec4 bounds{ 0 };
|
||||
int size = 0;
|
||||
stbtt_fontinfo font;
|
||||
Texture2D font_tex;
|
||||
std::string path;
|
||||
std::string id;
|
||||
std::vector<stbtt_bakedchar> chars;
|
||||
float scale = 1.f;
|
||||
|
||||
|
||||
Font() noexcept = default;
|
||||
Font(const Font&) = delete;
|
||||
void operator=(const Font&) = delete;
|
||||
Font(Font&& other) noexcept;
|
||||
void operator=(Font&& other) noexcept;
|
||||
|
||||
bool load(const std::string& ttf, int sz, float scale);
|
||||
void change_scale(float scale);
|
||||
void calc_bounds();
|
||||
@@ -30,8 +36,8 @@ public:
|
||||
static std::map<std::string, Font> m_fonts;
|
||||
static Sampler m_sampler;
|
||||
static void init();
|
||||
static bool load(const std::string& id, const char* ttf, int sz, float scale);
|
||||
static const Font& get(const std::string& id);
|
||||
static bool load(const std::string& id, const std::string& ttf, int sz, float scale);
|
||||
static const Font& get(const std::string& name, int size, const std::string& weight, bool italic);
|
||||
static void invalidate() { m_fonts.clear(); }
|
||||
static void change_scale(float scale);
|
||||
};
|
||||
@@ -50,10 +56,13 @@ public:
|
||||
int font_array_count = 0;
|
||||
int max_width = 0;
|
||||
GLuint font_buffers[2] = {0, 0};
|
||||
std::string font_id;
|
||||
std::string font;
|
||||
std::string weight;
|
||||
int italic;
|
||||
int size;
|
||||
glm::vec2 bb = { 0, 0 };
|
||||
glm::vec4 cur_box;
|
||||
bool create();
|
||||
void update(const std::string& id, const std::string& text);
|
||||
void update(const std::string& text, const std::string& font, int size, const std::string& weight, bool italic);
|
||||
void draw();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user