From 354f6f7b3c1e474c7cd62a538f9b6e386b13eaf9 Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Sat, 1 Apr 2023 17:13:19 +0700 Subject: [PATCH] ignore codes for color change in M_StringWidth Fix #965 --- src/m_menu.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 2e97ba85..02912115 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -6841,10 +6841,26 @@ void M_DrawSelCell (menu_t* menu,int item) int M_StringWidth(const char *string) { - int i, c, w = 0; - for (i = 0;i < strlen(string);i++) - w += (c = toupper(string[i]) - HU_FONTSTART) < 0 || c >= HU_FONTSIZE ? - 4 : SHORT(hu_font[c]->width); + int c, w = 0; + + while (*string) + { + c = *string++; + if (c == '\x1b') // skip code for color change + { + if (*string) + string++; + continue; + } + c = toupper(c) - HU_FONTSTART; + if (c < 0 || c > HU_FONTSIZE) + { + w += SPACEWIDTH; + continue; + } + w += SHORT(hu_font[c]->width); + } + return w; }