summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gfx.cpp18
-rw-r--r--src/gfx_func.h2
-rw-r--r--src/strings.cpp7
3 files changed, 14 insertions, 13 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()
diff --git a/src/gfx_func.h b/src/gfx_func.h
index f5dbcc0bf..65616e618 100644
--- a/src/gfx_func.h
+++ b/src/gfx_func.h
@@ -150,7 +150,7 @@ bool ToggleFullScreen(bool fs);
/* gfx.cpp */
byte GetCharacterWidth(FontSize size, uint32 key);
byte GetDigitWidth(FontSize size = FS_NORMAL);
-uint GetBroadestDigit(FontSize size = FS_NORMAL);
+void GetBroadestDigit(uint *front, uint *next, FontSize size = FS_NORMAL);
/**
* Get height of a character for a given font size.
diff --git a/src/strings.cpp b/src/strings.cpp
index 777d5ccf4..fcc8df60e 100644
--- a/src/strings.cpp
+++ b/src/strings.cpp
@@ -116,10 +116,11 @@ void SetDParamMaxValue(uint n, uint64 max_value, uint min_count, FontSize size)
*/
void SetDParamMaxDigits(uint n, uint count, FontSize size)
{
- uint biggest_digit = GetBroadestDigit(size);
- uint64 val = biggest_digit;
+ uint front, next;
+ GetBroadestDigit(&front, &next, size);
+ uint64 val = count > 1 ? front : next;
for (; count > 1; count--) {
- val = 10 * val + biggest_digit;
+ val = 10 * val + next;
}
SetDParam(n, val);
}