mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Return pair from GetBroadestDigit instead of out parameters.
parent
9a8d9e4e48
commit
4c99b5b368
22
src/gfx.cpp
22
src/gfx.cpp
|
@ -1248,21 +1248,25 @@ uint8_t GetDigitWidth(FontSize size)
|
|||
|
||||
/**
|
||||
* 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
|
||||
* @param size Font of the digit
|
||||
* @returns Broadest digits, first which is not 0 (use this digit as first digit for numbers with more than one
|
||||
* digit.), second including 0 (use this digit for all digits, except the first one; or for numbers with
|
||||
* only one digit.)
|
||||
*/
|
||||
void GetBroadestDigit(uint *front, uint *next, FontSize size)
|
||||
std::pair<uint8_t, uint8_t> GetBroadestDigit(FontSize size)
|
||||
{
|
||||
uint8_t front = 0;
|
||||
uint8_t next = 0;
|
||||
int width = -1;
|
||||
for (char c = '9'; c >= '0'; c--) {
|
||||
int w = GetCharacterWidth(size, c);
|
||||
if (w > width) {
|
||||
width = w;
|
||||
*next = c - '0';
|
||||
if (c != '0') *front = c - '0';
|
||||
}
|
||||
if (w <= width) continue;
|
||||
|
||||
width = w;
|
||||
next = c - '0';
|
||||
if (c != '0') front = c - '0';
|
||||
}
|
||||
return {front, next};
|
||||
}
|
||||
|
||||
void ScreenSizeChanged()
|
||||
|
|
|
@ -183,7 +183,7 @@ bool ToggleFullScreen(bool fs);
|
|||
/* gfx.cpp */
|
||||
uint8_t GetCharacterWidth(FontSize size, char32_t key);
|
||||
uint8_t GetDigitWidth(FontSize size = FS_NORMAL);
|
||||
void GetBroadestDigit(uint *front, uint *next, FontSize size = FS_NORMAL);
|
||||
std::pair<uint8_t, uint8_t> GetBroadestDigit(FontSize size);
|
||||
|
||||
int GetCharacterHeight(FontSize size);
|
||||
|
||||
|
|
|
@ -201,9 +201,7 @@ void SetDParamMaxValue(size_t n, uint64_t max_value, uint min_count, FontSize si
|
|||
*/
|
||||
void SetDParamMaxDigits(size_t n, uint count, FontSize size)
|
||||
{
|
||||
uint front = 0;
|
||||
uint next = 0;
|
||||
GetBroadestDigit(&front, &next, size);
|
||||
auto [front, next] = GetBroadestDigit(size);
|
||||
uint64_t val = count > 1 ? front : next;
|
||||
for (; count > 1; count--) {
|
||||
val = 10 * val + next;
|
||||
|
|
Loading…
Reference in New Issue