aboutsummaryrefslogtreecommitdiff
path: root/src/common/Font.hpp
diff options
context:
space:
mode:
authorfschildt <florian.schildt@protonmail.com>2025-10-13 13:59:54 +0200
committerfschildt <florian.schildt@protonmail.com>2025-10-13 13:59:54 +0200
commitabb22cda9a82a323fd8f1d077adefd6970a1abaa (patch)
tree126a2de5c91f659b888ba776b7b821b9779e7bfe /src/common/Font.hpp
parent6f3590341312b0ffff2304d02b24ac6a5d14b182 (diff)
minesweeper: draw colored mine counters
Diffstat (limited to 'src/common/Font.hpp')
-rw-r--r--src/common/Font.hpp25
1 files changed, 19 insertions, 6 deletions
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 <filesystem>
+#include <common/defs.hpp>
#include <stb_truetype.h>
+#include <memory>
-struct MonoBitmap {
+
+struct AlphaBitmap {
int32_t w;
int32_t h;
std::unique_ptr<uint8_t> 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;
};