diff options
author | frosch <frosch@openttd.org> | 2013-06-01 15:10:32 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2013-06-01 15:10:32 +0000 |
commit | 4261b6cc822fa03e5d2c9824fdd610d21c7b289f (patch) | |
tree | 78836a3dc158844b9061ded777544aa2237032df /src/gfx.cpp | |
parent | ce110eed32eef08e7ce1c35a2c5893698afee73a (diff) | |
download | openttd-4261b6cc822fa03e5d2c9824fdd610d21c7b289f.tar.xz |
(svn r25314) -Fix (r25313): If '0' is the broadest digit, 0 * sum(10^i, i=0..(n-1)) is not the broadest n-digit number.
-Fix [FS#5562]: Proper size-estimation for numbers with n digits.
Diffstat (limited to 'src/gfx.cpp')
-rw-r--r-- | src/gfx.cpp | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/gfx.cpp b/src/gfx.cpp index b9249af47..962913495 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -1690,22 +1690,22 @@ byte GetDigitWidth(FontSize size) } /** - * Return the digit with the biggest width. + * 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.) + * @param [out] next Broadest digit, including 0. (Use this digit for all digits, except the first one; or for numbers with only one digit.) * @param size Font of the digit - * @return Broadest digit. */ -uint GetBroadestDigit(FontSize size) +void GetBroadestDigit(uint *front, uint *next, FontSize size) { - uint digit = 0; - byte width = 0; - for (char c = '0'; c <= '9'; c++) { - byte w = GetCharacterWidth(size, c); + int width = -1; + for (char c = '9'; c >= '0'; c--) { + int w = GetCharacterWidth(size, c); if (w > width) { width = w; - digit = c - '0'; + *next = c - '0'; + if (c != '0') *front = c - '0'; } } - return digit; } void ScreenSizeChanged() |