diff --git a/src/gfx.cpp b/src/gfx.cpp index 608d69f3d1..46d9b689be 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -1528,6 +1528,24 @@ byte GetDigitWidth(FontSize size) return width; } +/** + * Return some number that is suitable for string size computations. + * @param count Number of digits which shall be displayable. + * @param size Font of the number + * @return The number. + */ +uint64 GetBroadestDigitsValue(uint count, FontSize size) +{ + uint front = 0; + uint next = 0; + GetBroadestDigit(&front, &next, size); + uint64 val = count > 1 ? front : next; + for (; count > 1; count--) { + val = 10 * val + next; + } + return val; +} + /** * Determine the broadest digits for guessing the maximum width of a n-digit number. * @param[out] front Broadest digit, which is not 0. (Use this digit as first digit for numbers with more than one digit.) diff --git a/src/gfx_func.h b/src/gfx_func.h index 23259e5e77..eaea93504b 100644 --- a/src/gfx_func.h +++ b/src/gfx_func.h @@ -220,6 +220,7 @@ bool ToggleFullScreen(bool fs); byte GetCharacterWidth(FontSize size, WChar key); byte GetDigitWidth(FontSize size = FS_NORMAL); void GetBroadestDigit(uint *front, uint *next, FontSize size = FS_NORMAL); +uint64 GetBroadestDigitsValue(uint count, FontSize size = FS_NORMAL); extern int font_height_cache[FS_END]; diff --git a/src/strings.cpp b/src/strings.cpp index 666428c177..da0e4fccab 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -116,14 +116,7 @@ void SetDParamMaxValue(uint n, uint64 max_value, uint min_count, FontSize size) */ void SetDParamMaxDigits(uint n, uint count, FontSize size) { - uint front = 0; - uint next = 0; - GetBroadestDigit(&front, &next, size); - uint64 val = count > 1 ? front : next; - for (; count > 1; count--) { - val = 10 * val + next; - } - SetDParam(n, val); + SetDParam(n, GetBroadestDigitsValue(count, size)); } /**