aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Michael Smith <mikesmiffy128@gmail.com> 2025-04-05 16:45:37 +0100
committerGravatar Michael Smith <mikesmiffy128@gmail.com> 2025-04-06 20:59:36 +0100
commit98f63b5bfc980d5be25ca1daf1bbcf66dc6696ab (patch)
treec910389ec84dc132c8fb8553aa80afe34850ad30
parent7ac57c976d95bce5a7a98e0f269e4cd3d61f3055 (diff)
downloadsst-98f63b5bfc980d5be25ca1daf1bbcf66dc6696ab.tar.gz
sst-98f63b5bfc980d5be25ca1daf1bbcf66dc6696ab.zip
Reload inputhud fonts on resolution change
This checks off another bug that we knew about for ages and I never had time to fix. Note that I've since learned that font handles don't work the way I assumed they did; things get cached and reused so there's no need to worry about leaks. As such, we could probably revisit how fonts are done here. However, the current implementation does work so that's potentially a job for some future release after 0.9.
-rw-r--r--src/inputhud.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/inputhud.c b/src/inputhud.c
index 6eaa857..88de5b4 100644
--- a/src/inputhud.c
+++ b/src/inputhud.c
@@ -310,8 +310,22 @@ static const char *const fontnames[] = {
};
static struct { ulong h; int sz; } fonts[countof(fontnames)];
+
+static int lastw = 0, lasth = 0;
+
+static void reloadfonts() {
+ for (int i = 0; i < countof(fontnames); ++i) {
+ if (fonts[i].h = hud_getfont(fontnames[i], true)) {
+ int dummy;
+ // use (roughly) the widest string as a reference for what will fit
+ hud_textsize(fonts[i].h, L"Speed", &fonts[i].sz, &dummy);
+ }
+ }
+}
+
HANDLE_EVENT(HudPaint, int screenw, int screenh) {
if (!con_getvari(sst_inputhud)) return;
+ if_cold (screenw != lastw || screenh != lasth) reloadfonts();
int basesz = screenw > screenh ? screenw : screenh;
int boxsz = ceilf(basesz * 0.025f);
if (boxsz < 24) boxsz = 24;
@@ -383,13 +397,6 @@ INIT {
errmsg_errorx("couldn't find input global");
return FEAT_INCOMPAT;
}
- for (int i = 0; i < countof(fontnames); ++i) {
- if (fonts[i].h = hud_getfont(fontnames[i], true)) {
- int dummy;
- // use (roughly) the widest string as a reference for what will fit
- hud_textsize(fonts[i].h, L"Speed", &fonts[i].sz, &dummy);
- }
- }
void **vtable = mem_loadptr(input);
// just unprotect the first few pointers (GetUserCmd is 8)
if_cold (!os_mprot(vtable, sizeof(void *) * 8, PAGE_READWRITE)) {