From abb22cda9a82a323fd8f1d077adefd6970a1abaa Mon Sep 17 00:00:00 2001 From: fschildt Date: Mon, 13 Oct 2025 13:59:54 +0200 Subject: minesweeper: draw colored mine counters --- src/common/Font.hpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'src/common/Font.hpp') diff --git a/src/common/Font.hpp b/src/common/Font.hpp index 91afe06..af4ddb5 100644 --- a/src/common/Font.hpp +++ b/src/common/Font.hpp @@ -1,10 +1,12 @@ #pragma once -#include +#include #include +#include -struct MonoBitmap { + +struct AlphaBitmap { int32_t w; int32_t h; std::unique_ptr pixels; @@ -15,7 +17,7 @@ struct Glyph { int32_t xoff; int32_t yoff; int32_t xadvance; - MonoBitmap bitmap; + AlphaBitmap bitmap; }; @@ -24,12 +26,22 @@ public: ~Font(); bool Init(const char* path, int font_size); - void Deinit(); + AlphaBitmap& GetAlphaBitmap(char32_t c); + Glyph& GetGlyph(char32_t c); + + - void LoadGlyph(Glyph& glyph, uint32_t codepoint); +private: + bool ReadFile(const char* path); + void LoadGlyph(Glyph& glyph, char32_t c); private: + static constexpr char first_ascii_ch = ' '; + static constexpr char last_ascii_ch = '~'; + static constexpr char ascii_glyph_count = last_ascii_ch - first_ascii_ch + 1; + + const char* m_file_content = nullptr; float m_font_scale; @@ -37,7 +49,8 @@ private: int m_font_yadvance; stbtt_fontinfo m_font_info; - Glyph m_glyphs['~' - ' ' + 1]; + Glyph m_glyphs[ascii_glyph_count]; + Glyph m_fail_glyph; }; -- cgit v1.2.3