mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Add GetParamMaxDigits/Value() functions.
Similar to SetDParamMaxDigits/Value(), except the value is returned instead of being set into a parameter.pull/13636/head
parent
4c99b5b368
commit
04a16a6b68
|
@ -176,21 +176,19 @@ uint64_t GetDParam(size_t n)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set DParam n to some number that is suitable for string size computations.
|
* Get some number that is suitable for string size computations.
|
||||||
* @param n Index of the string parameter.
|
* @param count Number of digits which shall be displayable.
|
||||||
* @param max_value The biggest value which shall be displayed.
|
|
||||||
* For the result only the number of digits of \a max_value matter.
|
|
||||||
* @param min_count Minimum number of digits independent of \a max.
|
|
||||||
* @param size Font of the number
|
* @param size Font of the number
|
||||||
|
* @returns Number to use for string size computations.
|
||||||
*/
|
*/
|
||||||
void SetDParamMaxValue(size_t n, uint64_t max_value, uint min_count, FontSize size)
|
uint64_t GetParamMaxDigits(uint count, FontSize size)
|
||||||
{
|
{
|
||||||
uint num_digits = 1;
|
auto [front, next] = GetBroadestDigit(size);
|
||||||
while (max_value >= 10) {
|
uint64_t val = count > 1 ? front : next;
|
||||||
num_digits++;
|
for (; count > 1; count--) {
|
||||||
max_value /= 10;
|
val = 10 * val + next;
|
||||||
}
|
}
|
||||||
SetDParamMaxDigits(n, std::max(min_count, num_digits), size);
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -201,12 +199,38 @@ void SetDParamMaxValue(size_t n, uint64_t max_value, uint min_count, FontSize si
|
||||||
*/
|
*/
|
||||||
void SetDParamMaxDigits(size_t n, uint count, FontSize size)
|
void SetDParamMaxDigits(size_t n, uint count, FontSize size)
|
||||||
{
|
{
|
||||||
auto [front, next] = GetBroadestDigit(size);
|
SetDParam(n, GetParamMaxDigits(count, size));
|
||||||
uint64_t val = count > 1 ? front : next;
|
|
||||||
for (; count > 1; count--) {
|
|
||||||
val = 10 * val + next;
|
|
||||||
}
|
}
|
||||||
SetDParam(n, val);
|
|
||||||
|
/**
|
||||||
|
* Get some number that is suitable for string size computations.
|
||||||
|
* @param max_value The biggest value which shall be displayed.
|
||||||
|
* For the result only the number of digits of \a max_value matter.
|
||||||
|
* @param min_count Minimum number of digits independent of \a max.
|
||||||
|
* @param size Font of the number
|
||||||
|
* @returns Number to use for string size computations.
|
||||||
|
*/
|
||||||
|
uint64_t GetParamMaxValue(uint64_t max_value, uint min_count, FontSize size)
|
||||||
|
{
|
||||||
|
uint num_digits = 1;
|
||||||
|
while (max_value >= 10) {
|
||||||
|
num_digits++;
|
||||||
|
max_value /= 10;
|
||||||
|
}
|
||||||
|
return GetParamMaxDigits(std::max(min_count, num_digits), size);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set DParam n to some number that is suitable for string size computations.
|
||||||
|
* @param n Index of the string parameter.
|
||||||
|
* @param max_value The biggest value which shall be displayed.
|
||||||
|
* For the result only the number of digits of \a max_value matter.
|
||||||
|
* @param min_count Minimum number of digits independent of \a max.
|
||||||
|
* @param size Font of the number
|
||||||
|
*/
|
||||||
|
void SetDParamMaxValue(size_t n, uint64_t max_value, uint min_count, FontSize size)
|
||||||
|
{
|
||||||
|
SetDParam(n, GetParamMaxValue(max_value, min_count, size));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -80,6 +80,9 @@ inline int64_t PackVelocity(uint speed, VehicleType type)
|
||||||
return speed | (static_cast<uint64_t>(type) << 56);
|
return speed | (static_cast<uint64_t>(type) << 56);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t GetParamMaxValue(uint64_t max_value, uint min_count = 0, FontSize size = FS_NORMAL);
|
||||||
|
uint64_t GetParamMaxDigits(uint count, FontSize size = FS_NORMAL);
|
||||||
|
|
||||||
void SetDParam(size_t n, uint64_t v);
|
void SetDParam(size_t n, uint64_t v);
|
||||||
void SetDParamMaxValue(size_t n, uint64_t max_value, uint min_count = 0, FontSize size = FS_NORMAL);
|
void SetDParamMaxValue(size_t n, uint64_t max_value, uint min_count = 0, FontSize size = FS_NORMAL);
|
||||||
void SetDParamMaxDigits(size_t n, uint count, FontSize size = FS_NORMAL);
|
void SetDParamMaxDigits(size_t n, uint count, FontSize size = FS_NORMAL);
|
||||||
|
|
Loading…
Reference in New Issue