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
 
@@ -881,25 +881,25 @@ void DrawEngineList(VehicleType type, in
 
	int step_size = GetEngineListHeight(type);
 
	int sprite_left  = GetVehicleImageCellSize(type, EIT_PURCHASE).extend_left;
 
	int sprite_right = GetVehicleImageCellSize(type, EIT_PURCHASE).extend_right;
 
	int sprite_width = sprite_left + sprite_right;
 

	
 
	int sprite_x        = rtl ? r - sprite_right - 1 : l + sprite_left + 1;
 
	int sprite_y_offset = sprite_y_offsets[type] + step_size / 2;
 

	
 
	Dimension replace_icon = {0, 0};
 
	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;
 
	}
 

	
 
	int text_left  = l + (rtl ? WD_FRAMERECT_LEFT + replace_icon.width + 8 + count_width : sprite_width + WD_FRAMETEXT_LEFT);
 
	int text_right = r - (rtl ? sprite_width + WD_FRAMETEXT_RIGHT : WD_FRAMERECT_RIGHT + replace_icon.width + 8 + count_width);
 
	int replace_icon_left = rtl ? l + WD_FRAMERECT_LEFT : r - WD_FRAMERECT_RIGHT - replace_icon.width;
 
	int count_left = l;
 
	int count_right = rtl ? text_left : r - WD_FRAMERECT_RIGHT - replace_icon.width - 8;
 

	
 
	int normal_text_y_offset = (step_size - FONT_HEIGHT_NORMAL) / 2;
 
	int small_text_y_offset  = step_size - FONT_HEIGHT_SMALL - WD_FRAMERECT_BOTTOM - 1;
 
	int replace_icon_y_offset = (step_size - replace_icon.height) / 2 - 1;
src/depot_gui.cpp
Show inline comments
 
@@ -592,25 +592,25 @@ struct DepotWindow : Window {
 
	uint count_width;
 
	uint header_width;
 
	uint flag_width;
 
	uint flag_height;
 

	
 
	virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
 
	{
 
		switch (widget) {
 
			case WID_D_MATRIX: {
 
				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 {
 
					this->count_width = 0;
 
				}
 

	
 
				Dimension unumber = { GetDigitWidth() * 4, FONT_HEIGHT_NORMAL };
 
				const Sprite *spr = GetSprite(SPR_FLAG_VEH_STOPPED, ST_NORMAL);
 
				this->flag_width  = UnScaleByZoom(spr->width, ZOOM_LVL_GUI) + WD_FRAMERECT_RIGHT;
 
				this->flag_height = UnScaleByZoom(spr->height, ZOOM_LVL_GUI);
 

	
 
				if (this->type == VEH_TRAIN || this->type == VEH_ROAD) {
src/gfx.cpp
Show inline comments
 
@@ -1680,24 +1680,42 @@ byte GetCharacterWidth(FontSize size, WC
 
 * @param size  Font of the digit
 
 * @return Width of the digit.
 
 */
 
byte GetDigitWidth(FontSize size)
 
{
 
	byte width = 0;
 
	for (char c = '0'; c <= '9'; c++) {
 
		width = max(GetCharacterWidth(size, c), width);
 
	}
 
	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()
 
{
 
	_dirty_bytes_per_line = CeilDiv(_screen.width, DIRTY_BLOCK_WIDTH);
 
	_dirty_blocks = ReallocT<byte>(_dirty_blocks, _dirty_bytes_per_line * CeilDiv(_screen.height, DIRTY_BLOCK_HEIGHT));
 

	
 
	/* check the dirty rect */
 
	if (_invalid_rect.right >= _screen.width) _invalid_rect.right = _screen.width;
 
	if (_invalid_rect.bottom >= _screen.height) _invalid_rect.bottom = _screen.height;
 

	
 
	/* screen size changed and the old bitmap is invalid now, so we don't want to undraw it */
 
	_cursor.visible = false;
src/gfx_func.h
Show inline comments
 
@@ -141,24 +141,25 @@ void DrawOverlappedWindowForAll(int left
 

	
 
void SetMouseCursor(CursorID cursor, PaletteID pal);
 
void SetAnimatedMouseCursor(const AnimCursor *table);
 
void CursorTick();
 
void UpdateCursorSize();
 
bool ChangeResInGame(int w, int h);
 
void SortResolutions(int count);
 
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.
 
 * @param size Font size to get height of
 
 * @return     Height of characters in the given font (pixels)
 
 */
 
static inline byte GetCharacterHeight(FontSize size)
 
{
 
	assert(size < FS_END);
 
	extern int _font_height[FS_END];
 
	return _font_height[size];
 
}
src/graph_gui.cpp
Show inline comments
 
@@ -495,25 +495,25 @@ public:
 
				SetDParam(1, month + STR_MONTH_ABBREV_JAN + 2);
 
				SetDParam(2, year);
 
				x_label_width = max(x_label_width, GetStringBoundingBox(month == 0 ? STR_GRAPH_X_LABEL_MONTH_YEAR : STR_GRAPH_X_LABEL_MONTH).width);
 

	
 
				month += 3;
 
				if (month >= 12) {
 
					month = 0;
 
					year++;
 
				}
 
			}
 
		} 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;
 
		}
 

	
 
		SetDParam(0, this->format_str_y_axis);
 
		SetDParam(1, INT64_MAX);
 
		uint y_label_width = GetStringBoundingBox(STR_GRAPH_Y_LABEL).width;
 

	
 
		size->width  = max<uint>(size->width,  5 + y_label_width + this->num_on_x_axis * (x_label_width + 5) + 9);
 
		size->height = max<uint>(size->height, 5 + (1 + MIN_GRAPH_NUM_LINES_Y * 2 + (this->month != 0xFF ? 3 : 1)) * FONT_HEIGHT_SMALL + 4);
 
		size->height = max<uint>(size->height, size->width / 3);
 
	}
 

	
src/group_gui.cpp
Show inline comments
 
@@ -174,25 +174,25 @@ private:
 
		this->column_size[VGC_AUTOREPLACE] = GetSpriteSize(SPR_GROUP_REPLACE_ACTIVE);
 
		this->tiny_step_height = max(this->tiny_step_height, this->column_size[VGC_AUTOREPLACE].height);
 

	
 
		this->column_size[VGC_PROFIT].width = 0;
 
		this->column_size[VGC_PROFIT].height = 0;
 
		static const SpriteID profit_sprites[] = {SPR_PROFIT_NA, SPR_PROFIT_NEGATIVE, SPR_PROFIT_SOME, SPR_PROFIT_LOT};
 
		for (uint i = 0; i < lengthof(profit_sprites); i++) {
 
			Dimension d = GetSpriteSize(profit_sprites[i]);
 
			this->column_size[VGC_PROFIT] = maxdim(this->column_size[VGC_PROFIT], d);
 
		}
 
		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);
 

	
 
		this->tiny_step_height += WD_MATRIX_TOP;
 

	
 
		return WD_FRAMERECT_LEFT + 8 +
 
			this->column_size[VGC_NAME].width + 8 +
 
			this->column_size[VGC_PROTECT].width + 2 +
 
			this->column_size[VGC_AUTOREPLACE].width + 2 +
 
			this->column_size[VGC_PROFIT].width + 2 +
 
			this->column_size[VGC_NUMBER].width + 2 +
 
			WD_FRAMERECT_RIGHT;
src/strings.cpp
Show inline comments
 
@@ -87,43 +87,45 @@ int64 StringParameters::GetInt64(WChar t
 
void StringParameters::ShiftParameters(uint amount)
 
{
 
	assert(amount <= this->num_param);
 
	MemMoveT(this->data + amount, this->data, this->num_param - amount);
 
}
 

	
 
/**
 
 * 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(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;
 
	}
 
	SetDParam(n, val);
 
}
 

	
 
/**
 
 * Copy \a num string parameters from array \a src into the global string parameter array.
 
 * @param offs Index in the global array to copy the first string parameter to.
 
 * @param src  Source array of string parameters.
 
 * @param num  Number of string parameters to copy.
src/strings_func.h
Show inline comments
 
@@ -146,26 +146,26 @@ static inline void SetDParamX(uint64 *s,
 
}
 

	
 
/**
 
 * Set a string parameter \a v at index \a n in the global string parameter array.
 
 * @param n Index of the string parameter.
 
 * @param v Value of the string parameter.
 
 */
 
static inline void SetDParam(uint n, uint64 v)
 
{
 
	_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);
 

	
 
void CopyInDParam(int offs, const uint64 *src, int num);
 
void CopyOutDParam(uint64 *dst, int offs, int num);
 
void CopyOutDParam(uint64 *dst, const char **strings, StringID string, int num);
 

	
 
/**
 
 * Get the current string parameter at index \a n from parameter array \a s.
 
 * @param s Array of string parameters.
 
 * @param n Index of the string parameter.
 
 * @return Value of the requested string parameter.
src/timetable_gui.cpp
Show inline comments
 
@@ -191,25 +191,25 @@ struct TimetableWindow : Window {
 
		bool travelling = (!v->current_order.IsType(OT_LOADING) || v->current_order.GetNonStopType() == ONSF_STOP_EVERYWHERE);
 
		Ticks start_time = _date_fract - v->current_order_time;
 

	
 
		FillTimetableArrivalDepartureTable(v, v->cur_real_order_index % v->GetNumOrders(), travelling, table, start_time);
 

	
 
		return (travelling && v->lateness_counter < 0);
 
	}
 

	
 
	virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
 
	{
 
		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;
 
				/* FALL THROUGH */
 
			case WID_VT_ARRIVAL_DEPARTURE_SELECTION:
 
			case WID_VT_TIMETABLE_PANEL:
 
				resize->height = FONT_HEIGHT_NORMAL;
 
				size->height = WD_FRAMERECT_TOP + 8 * resize->height + WD_FRAMERECT_BOTTOM;
 
				break;
 

	
 
			case WID_VT_SUMMARY_PANEL:
 
				size->height = WD_FRAMERECT_TOP + 2 * FONT_HEIGHT_NORMAL + WD_FRAMERECT_BOTTOM;
0 comments (0 inline, 0 general)