Changeset - r20303:6adbc75a1297
[Not reviewed]
master
0 9 0
frosch - 11 years ago 2013-06-01 14:33:48
frosch@openttd.org
(svn r25313) -Fix: Do not assume '8' to be the broadest digit, but test all of them.
9 files changed with 32 insertions and 11 deletions:
0 comments (0 inline, 0 general)
src/build_vehicle_gui.cpp
Show inline comments
 
@@ -890,7 +890,7 @@ void DrawEngineList(VehicleType type, in
 
	int count_width = 0;
 
	if (show_count) {
 
		replace_icon = GetSpriteSize(SPR_GROUP_REPLACE_ACTIVE);
 
		SetDParamMaxDigits(0, 3);
 
		SetDParamMaxDigits(0, 3, FS_SMALL);
 
		count_width = GetStringBoundingBox(STR_TINY_BLACK_COMA).width;
 
	}
 

	
src/depot_gui.cpp
Show inline comments
 
@@ -601,7 +601,7 @@ struct DepotWindow : Window {
 
				uint min_height = 0;
 

	
 
				if (this->type == VEH_TRAIN) {
 
					SetDParamMaxValue(0, 1000);
 
					SetDParamMaxValue(0, 1000, 0, FS_SMALL);
 
					SetDParam(1, 1);
 
					this->count_width = GetStringBoundingBox(STR_TINY_BLACK_DECIMAL).width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
 
				} else {
src/gfx.cpp
Show inline comments
 
@@ -1689,6 +1689,24 @@ byte GetDigitWidth(FontSize size)
 
	return width;
 
}
 

	
 
/**
 
 * Return the digit with the biggest width.
 
 * @param size  Font of the digit
 
 * @return Broadest digit.
 
 */
 
uint GetBroadestDigit(FontSize size)
 
{
 
	uint digit = 0;
 
	byte width = 0;
 
	for (char c = '0'; c <= '9'; c++) {
 
		byte w = GetCharacterWidth(size, c);
 
		if (w > width) {
 
			width = w;
 
			digit = c - '0';
 
		}
 
	}
 
	return digit;
 
}
 

	
 
void ScreenSizeChanged()
 
{
src/gfx_func.h
Show inline comments
 
@@ -150,6 +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);
 

	
 
/**
 
 * Get height of a character for a given font size.
src/graph_gui.cpp
Show inline comments
 
@@ -504,7 +504,7 @@ public:
 
			}
 
		} else {
 
			/* Draw the label under the data point rather than on the grid line. */
 
			SetDParamMaxValue(0, this->x_values_start + this->num_on_x_axis * this->x_values_increment);
 
			SetDParamMaxValue(0, this->x_values_start + this->num_on_x_axis * this->x_values_increment, 0, FS_SMALL);
 
			x_label_width = GetStringBoundingBox(STR_GRAPH_Y_LABEL_NUMBER).width;
 
		}
 

	
src/group_gui.cpp
Show inline comments
 
@@ -183,7 +183,7 @@ private:
 
		}
 
		this->tiny_step_height = max(this->tiny_step_height, this->column_size[VGC_PROFIT].height);
 

	
 
		SetDParamMaxValue(0, GroupStatistics::Get(this->vli.company, ALL_GROUP, this->vli.vtype).num_vehicle, 3);
 
		SetDParamMaxValue(0, GroupStatistics::Get(this->vli.company, ALL_GROUP, this->vli.vtype).num_vehicle, 3, FS_SMALL);
 
		this->column_size[VGC_NUMBER] = GetStringBoundingBox(STR_TINY_COMMA);
 
		this->tiny_step_height = max(this->tiny_step_height, this->column_size[VGC_NUMBER].height);
 

	
src/strings.cpp
Show inline comments
 
@@ -96,25 +96,27 @@ void StringParameters::ShiftParameters(u
 
 * @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(uint n, uint64 max_value, uint min_count)
 
void SetDParamMaxValue(uint n, uint64 max_value, uint min_count, FontSize size)
 
{
 
	uint num_digits = 1;
 
	while (max_value >= 10) {
 
		num_digits++;
 
		max_value /= 10;
 
	}
 
	SetDParamMaxDigits(n, max(min_count, num_digits));
 
	SetDParamMaxDigits(n, 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 count Number of digits which shall be displayable.
 
 * @param size  Font of the number
 
 */
 
void SetDParamMaxDigits(uint n, uint count)
 
void SetDParamMaxDigits(uint n, uint count, FontSize size)
 
{
 
	static const uint biggest_digit = 8; ///< Digit with the biggest string width.
 
	uint biggest_digit = GetBroadestDigit(size);
 
	uint64 val = biggest_digit;
 
	for (; count > 1; count--) {
 
		val = 10 * val + biggest_digit;
src/strings_func.h
Show inline comments
 
@@ -155,8 +155,8 @@ static inline void SetDParam(uint n, uin
 
	_global_string_params.SetParam(n, v);
 
}
 

	
 
void SetDParamMaxValue(uint n, uint64 max_value, uint min_count = 0);
 
void SetDParamMaxDigits(uint n, uint count);
 
void SetDParamMaxValue(uint n, uint64 max_value, uint min_count = 0, FontSize size = FS_NORMAL);
 
void SetDParamMaxDigits(uint n, uint count, FontSize size = FS_NORMAL);
 

	
 
void SetDParamStr(uint n, const char *str);
 

	
src/timetable_gui.cpp
Show inline comments
 
@@ -200,7 +200,7 @@ struct TimetableWindow : Window {
 
	{
 
		switch (widget) {
 
			case WID_VT_ARRIVAL_DEPARTURE_PANEL:
 
				SetDParamMaxValue(0, MAX_YEAR * DAYS_IN_YEAR);
 
				SetDParamMaxValue(0, MAX_YEAR * DAYS_IN_YEAR, 0, FS_SMALL);
 
				this->deparr_time_width = GetStringBoundingBox(STR_JUST_DATE_TINY).width;
 
				this->deparr_abbr_width = max(GetStringBoundingBox(STR_TIMETABLE_ARRIVAL_ABBREVIATION).width, GetStringBoundingBox(STR_TIMETABLE_DEPARTURE_ABBREVIATION).width);
 
				size->width = WD_FRAMERECT_LEFT + this->deparr_abbr_width + 10 + this->deparr_time_width + WD_FRAMERECT_RIGHT;
0 comments (0 inline, 0 general)