Changeset - r19846:75a27628493b
[Not reviewed]
master
0 18 0
frosch - 12 years ago 2012-12-08 17:18:51
frosch@openttd.org
(svn r24801) -Codechange: Add functions to set integral DParams to suitable values for size computations.
18 files changed with 82 insertions and 49 deletions:
0 comments (0 inline, 0 general)
src/build_vehicle_gui.cpp
Show inline comments
 
@@ -887,13 +887,13 @@ void DrawEngineList(VehicleType type, in
 
	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);
 
		SetDParam(0, 999);
 
		SetDParamMaxDigits(0, 3);
 
		count_width = GetStringBoundingBox(STR_TINY_BLACK_COMA).width;
 
	}
 

	
 
	int text_left  = l + (rtl ? WD_FRAMERECT_LEFT + replace_icon.width + 8 + count_width : sprite_width);
 
	int text_right = r - (rtl ? sprite_width : 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;
src/cheat_gui.cpp
Show inline comments
 
@@ -256,13 +256,13 @@ struct CheatWindow : Window {
 
							SetDParam(0, ConvertYMDToDate(MAX_YEAR, 11, 31));
 
							width = max(width, GetStringBoundingBox(ce->str).width);
 
							break;
 

	
 
						/* Draw coloured flag for change company cheat */
 
						case STR_CHEAT_CHANGE_COMPANY:
 
							SetDParam(0, 15);
 
							SetDParamMaxValue(0, MAX_COMPANIES);
 
							width = max(width, GetStringBoundingBox(ce->str).width + 10 + 10);
 
							break;
 

	
 
						default:
 
							SetDParam(0, INT64_MAX);
 
							width = max(width, GetStringBoundingBox(ce->str).width);
src/company_gui.cpp
Show inline comments
 
@@ -316,13 +316,13 @@ struct CompanyFinancesWindow : Window {
 
			case WID_CF_EXPS_PRICE3:
 
				size->height = _expenses_list_types[type].GetHeight();
 
				/* FALL THROUGH */
 
			case WID_CF_BALANCE_VALUE:
 
			case WID_CF_LOAN_VALUE:
 
			case WID_CF_TOTAL_VALUE:
 
				SetDParam(0, CompanyFinancesWindow::max_money);
 
				SetDParamMaxValue(0, CompanyFinancesWindow::max_money);
 
				size->width = max(GetStringBoundingBox(STR_FINANCES_NEGATIVE_INCOME).width, GetStringBoundingBox(STR_FINANCES_POSITIVE_INCOME).width) + padding.width;
 
				break;
 

	
 
			case WID_CF_MAXLOAN_GAP:
 
				size->height = FONT_HEIGHT_NORMAL;
 
				break;
 
@@ -1688,18 +1688,18 @@ struct CompanyInfrastructureWindow : Win
 
				max_cost = max(max_cost, CanalMaintenanceCost(c->infrastructure.water));
 
				max_val = max(max_val, c->infrastructure.station);
 
				max_cost = max(max_cost, StationMaintenanceCost(c->infrastructure.station));
 
				max_val = max(max_val, c->infrastructure.airport);
 
				max_cost = max(max_cost, AirportMaintenanceCost(c->index));
 

	
 
				SetDParam(0, max_val);
 
				SetDParam(1, max_cost * 12); // Convert to per year
 
				SetDParamMaxValue(0, max_val);
 
				SetDParamMaxValue(1, max_cost * 12); // Convert to per year
 
				size->width = max(size->width, GetStringBoundingBox(_settings_game.economy.infrastructure_maintenance ? STR_COMPANY_INFRASTRUCTURE_VIEW_COST : STR_WHITE_COMMA).width + 20); // Reserve some wiggle room.
 

	
 
				if (_settings_game.economy.infrastructure_maintenance) {
 
					SetDParam(0, this->GetTotalMaintenanceCost() * 12); // Convert to per year
 
					SetDParamMaxValue(0, this->GetTotalMaintenanceCost() * 12); // Convert to per year
 
					this->total_width = GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL).width + 20;
 
					size->width = max(size->width, this->total_width);
 
				}
 

	
 
				/* Set height of the total line. */
 
				if (widget == WID_CI_TOTAL) {
 
@@ -2092,33 +2092,33 @@ struct CompanyWindow : Window
 
			case WID_C_DESC_COMPANY_VALUE:
 
				SetDParam(0, INT64_MAX); // Arguably the maximum company value
 
				size->width = GetStringBoundingBox(STR_COMPANY_VIEW_COMPANY_VALUE).width;
 
				break;
 

	
 
			case WID_C_DESC_VEHICLE_COUNTS:
 
				SetDParam(0, 5000); // Maximum number of vehicles
 
				SetDParamMaxValue(0, 5000); // Maximum number of vehicles
 
				for (uint i = 0; i < lengthof(_company_view_vehicle_count_strings); i++) {
 
					size->width = max(size->width, GetStringBoundingBox(_company_view_vehicle_count_strings[i]).width);
 
				}
 
				break;
 

	
 
			case WID_C_DESC_INFRASTRUCTURE_COUNTS:
 
				SetDParam(0, UINT_MAX);
 
				SetDParamMaxValue(0, UINT_MAX);
 
				size->width = max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_RAIL).width);
 
				size->width = max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_ROAD).width);
 
				size->width = max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_WATER).width);
 
				size->width = max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_STATION).width);
 
				size->width = max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_AIRPORT).width);
 
				size->width = max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_NONE).width);
 
				break;
 

	
 
			case WID_C_DESC_OWNERS: {
 
				const Company *c2;
 

	
 
				FOR_ALL_COMPANIES(c2) {
 
					SetDParam(0, 25);
 
					SetDParamMaxValue(0, 75);
 
					SetDParam(1, c2->index);
 

	
 
					size->width = max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_SHARES_OWNED_BY).width);
 
				}
 
				break;
 
			}
src/date_gui.cpp
Show inline comments
 
@@ -114,16 +114,14 @@ struct SetDateWindow : Window {
 
				for (uint i = 0; i < 12; i++) {
 
					d = maxdim(d, GetStringBoundingBox(STR_MONTH_JAN + i));
 
				}
 
				break;
 

	
 
			case WID_SD_YEAR:
 
				for (Year i = this->min_year; i <= this->max_year; i++) {
 
					SetDParam(0, i);
 
					d = maxdim(d, GetStringBoundingBox(STR_JUST_INT));
 
				}
 
				SetDParamMaxValue(0, this->max_year);
 
				d = maxdim(d, GetStringBoundingBox(STR_JUST_INT));
 
				break;
 
		}
 

	
 
		d.width += padding.width;
 
		d.height += padding.height;
 
		*size = d;
src/depot_gui.cpp
Show inline comments
 
@@ -576,13 +576,13 @@ struct DepotWindow : Window {
 
	{
 
		switch (widget) {
 
			case WID_D_MATRIX: {
 
				uint min_height = 0;
 

	
 
				if (this->type == VEH_TRAIN) {
 
					SetDParam(0, 1000);
 
					SetDParamMaxValue(0, 1000);
 
					SetDParam(1, 1);
 
					this->count_width = GetStringBoundingBox(STR_TINY_BLACK_DECIMAL).width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
 
				} else {
 
					this->count_width = 0;
 
				}
 

	
src/genworld_gui.cpp
Show inline comments
 
@@ -446,40 +446,40 @@ struct GenerateLandscapeWindow : public 
 
				SetDParam(0, ConvertYMDToDate(MAX_YEAR, 0, 1));
 
				*size = GetStringBoundingBox(STR_BLACK_DATE_LONG);
 
				break;
 

	
 
			case WID_GL_MAPSIZE_X_PULLDOWN:
 
			case WID_GL_MAPSIZE_Y_PULLDOWN:
 
				SetDParam(0, MAX_MAP_SIZE);
 
				SetDParamMaxValue(0, MAX_MAP_SIZE);
 
				*size = GetStringBoundingBox(STR_JUST_INT);
 
				break;
 

	
 
			case WID_GL_SNOW_LEVEL_TEXT:
 
				SetDParam(0, MAX_TILE_HEIGHT);
 
				SetDParamMaxValue(0, MAX_TILE_HEIGHT);
 
				*size = GetStringBoundingBox(STR_JUST_INT);
 
				break;
 

	
 
			case WID_GL_HEIGHTMAP_SIZE_TEXT:
 
				SetDParam(0, this->x);
 
				SetDParam(1, this->y);
 
				*size = GetStringBoundingBox(STR_MAPGEN_HEIGHTMAP_SIZE);
 
				break;
 

	
 
			case WID_GL_TOWN_PULLDOWN:
 
				strs = _num_towns;
 
				SetDParam(0, CUSTOM_TOWN_MAX_NUMBER);
 
				SetDParamMaxValue(0, CUSTOM_TOWN_MAX_NUMBER);
 
				*size = GetStringBoundingBox(STR_NUM_CUSTOM_NUMBER);
 
				break;
 

	
 
			case WID_GL_INDUSTRY_PULLDOWN:   strs = _num_inds; break;
 
			case WID_GL_LANDSCAPE_PULLDOWN:  strs = _landscape; break;
 
			case WID_GL_TREE_PULLDOWN:       strs = _tree_placer; break;
 
			case WID_GL_TERRAIN_PULLDOWN:    strs = _elevations; break;
 
			case WID_GL_WATER_PULLDOWN:
 
				strs = _sea_lakes;
 
				SetDParam(0, CUSTOM_SEA_LEVEL_MAX_PERCENTAGE);
 
				SetDParamMaxValue(0, CUSTOM_SEA_LEVEL_MAX_PERCENTAGE);
 
				*size = GetStringBoundingBox(STR_SEA_LEVEL_CUSTOM_PERCENTAGE);
 
				break;
 

	
 
			case WID_GL_RIVER_PULLDOWN:      strs = _rivers; break;
 
			case WID_GL_SMOOTHNESS_PULLDOWN: strs = _smoothness; break;
 
			case WID_GL_VARIETY_PULLDOWN:    strs = _variety; break;
 
@@ -920,17 +920,17 @@ struct CreateScenarioWindow : public Win
 
				SetDParam(0, ConvertYMDToDate(MAX_YEAR, 0, 1));
 
				str = STR_BLACK_DATE_LONG;
 
				break;
 

	
 
			case WID_CS_MAPSIZE_X_PULLDOWN:
 
			case WID_CS_MAPSIZE_Y_PULLDOWN:
 
				SetDParam(0, MAX_MAP_SIZE);
 
				SetDParamMaxValue(0, MAX_MAP_SIZE);
 
				break;
 

	
 
			case WID_CS_FLAT_LAND_HEIGHT_TEXT:
 
				SetDParam(0, MAX_TILE_HEIGHT);
 
				SetDParamMaxValue(0, MAX_TILE_HEIGHT);
 
				break;
 

	
 
			default:
 
				return;
 
		}
 
		*size = GetStringBoundingBox(str);
 
@@ -1191,13 +1191,13 @@ struct GenerateProgressWindow : public W
 
	}
 

	
 
	virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
 
	{
 
		switch (widget) {
 
			case WID_GP_PROGRESS_BAR: {
 
				SetDParam(0, 100);
 
				SetDParamMaxValue(0, 100);
 
				*size = GetStringBoundingBox(STR_GENERATION_PROGRESS);
 
				/* We need some spacing for the 'border' */
 
				size->height += 8;
 
				size->width += 8;
 
				break;
 
			}
src/graph_gui.cpp
Show inline comments
 
@@ -501,13 +501,13 @@ public:
 
					month = 0;
 
					year++;
 
				}
 
			}
 
		} else {
 
			/* Draw the label under the data point rather than on the grid line. */
 
			SetDParam(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);
 
			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;
 
@@ -1319,16 +1319,16 @@ struct PerformanceRatingDetailWindow : W
 
				size->height = this->bar_height + 2 * WD_MATRIX_TOP;
 

	
 
				uint score_info_width = 0;
 
				for (uint i = SCORE_BEGIN; i < SCORE_END; i++) {
 
					score_info_width = max(score_info_width, GetStringBoundingBox(STR_PERFORMANCE_DETAIL_VEHICLES + i).width);
 
				}
 
				SetDParam(0, 1000);
 
				SetDParamMaxValue(0, 1000);
 
				score_info_width += GetStringBoundingBox(STR_BLACK_COMMA).width + WD_FRAMERECT_LEFT;
 

	
 
				SetDParam(0, 100);
 
				SetDParamMaxValue(0, 100);
 
				this->bar_width = GetStringBoundingBox(STR_PERFORMANCE_DETAIL_PERCENT).width + 20; // Wide bars!
 

	
 
				/* At this number we are roughly at the max; it can become wider,
 
				 * but then you need at 1000 times more money. At that time you're
 
				 * not that interested anymore in the last few digits anyway.
 
				 * The 500 is because 999 999 500 to 999 999 999 are rounded to
src/group_gui.cpp
Show inline comments
 
@@ -179,13 +179,13 @@ private:
 
		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);
 

	
 
		SetDParam(0, GroupStatistics::Get(this->vli.company, ALL_GROUP, this->vli.vtype).num_vehicle > 900 ? 9999 : 999);
 
		SetDParamMaxValue(0, GroupStatistics::Get(this->vli.company, ALL_GROUP, this->vli.vtype).num_vehicle, 3);
 
		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 +
src/network/network_gui.cpp
Show inline comments
 
@@ -523,30 +523,30 @@ public:
 
			case WID_NG_NAME:
 
				size->width += 2 * WD_SORTBUTTON_ARROW_WIDTH; // Make space for the arrow
 
				break;
 

	
 
			case WID_NG_CLIENTS:
 
				size->width += 2 * WD_SORTBUTTON_ARROW_WIDTH; // Make space for the arrow
 
				SetDParam(0, MAX_CLIENTS);
 
				SetDParam(1, MAX_CLIENTS);
 
				SetDParam(2, MAX_COMPANIES);
 
				SetDParam(3, MAX_COMPANIES);
 
				SetDParamMaxValue(0, MAX_CLIENTS);
 
				SetDParamMaxValue(1, MAX_CLIENTS);
 
				SetDParamMaxValue(2, MAX_COMPANIES);
 
				SetDParamMaxValue(3, MAX_COMPANIES);
 
				*size = maxdim(*size, GetStringBoundingBox(STR_NETWORK_SERVER_LIST_GENERAL_ONLINE));
 
				break;
 

	
 
			case WID_NG_MAPSIZE:
 
				size->width += 2 * WD_SORTBUTTON_ARROW_WIDTH; // Make space for the arrow
 
				SetDParam(0, MAX_MAP_SIZE);
 
				SetDParam(1, MAX_MAP_SIZE);
 
				SetDParamMaxValue(0, MAX_MAP_SIZE);
 
				SetDParamMaxValue(1, MAX_MAP_SIZE);
 
				*size = maxdim(*size, GetStringBoundingBox(STR_NETWORK_SERVER_LIST_MAP_SIZE_SHORT));
 
				break;
 

	
 
			case WID_NG_DATE:
 
			case WID_NG_YEARS:
 
				size->width += 2 * WD_SORTBUTTON_ARROW_WIDTH; // Make space for the arrow
 
				SetDParam(0, 99999);
 
				SetDParamMaxValue(0, 5);
 
				*size = maxdim(*size, GetStringBoundingBox(STR_JUST_INT));
 
				break;
 

	
 
			case WID_NG_DETAILS_SPACER:
 
				size->height = 20 + 12 * FONT_HEIGHT_NORMAL;
 
				break;
 
@@ -2068,18 +2068,18 @@ struct NetworkJoinStatusWindow : Window 
 
		uint width = 0;
 
		for (uint i = 0; i < NETWORK_JOIN_STATUS_END; i++) {
 
			width = max(width, GetStringBoundingBox(STR_NETWORK_CONNECTING_1 + i).width);
 
		}
 

	
 
		/* For the number of waiting (other) players */
 
		SetDParam(0, MAX_CLIENTS);
 
		SetDParamMaxValue(0, MAX_CLIENTS);
 
		width = max(width, GetStringBoundingBox(STR_NETWORK_CONNECTING_WAITING).width);
 

	
 
		/* Account for downloading ~ 10 MiB */
 
		SetDParam(0, 10000000);
 
		SetDParam(1, 10000000);
 
		SetDParamMaxDigits(0, 8);
 
		SetDParamMaxDigits(1, 8);
 
		width = max(width, GetStringBoundingBox(STR_NETWORK_CONNECTING_DOWNLOADING_1).width);
 
		width = max(width, GetStringBoundingBox(STR_NETWORK_CONNECTING_DOWNLOADING_2).width);
 

	
 
		/* Give a bit more clearing for the widest strings than strictly needed */
 
		size->width = width + WD_FRAMERECT_LEFT + WD_FRAMERECT_BOTTOM + 10;
 
	}
src/newgrf_gui.cpp
Show inline comments
 
@@ -194,13 +194,13 @@ struct NewGRFParametersWindow : public W
 
			case WID_NP_NUMPAR_INC: {
 
				size->width = size->height = FONT_HEIGHT_NORMAL;
 
				break;
 
			}
 

	
 
			case WID_NP_NUMPAR: {
 
				SetDParam(0, 999);
 
				SetDParamMaxValue(0, lengthof(this->grf_config->param));
 
				Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
 
				d.width += padding.width;
 
				d.height += padding.height;
 
				*size = maxdim(*size, d);
 
				break;
 
			}
 
@@ -1962,23 +1962,23 @@ struct ScanProgressWindow : public Windo
 
	}
 

	
 
	virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
 
	{
 
		switch (widget) {
 
			case WID_SP_PROGRESS_BAR: {
 
				SetDParam(0, 100);
 
				SetDParamMaxValue(0, 100);
 
				*size = GetStringBoundingBox(STR_GENERATION_PROGRESS);
 
				/* We need some spacing for the 'border' */
 
				size->height += 8;
 
				size->width += 8;
 
				break;
 
			}
 

	
 
			case WID_SP_PROGRESS_TEXT:
 
				SetDParam(0, 9999);
 
				SetDParam(1, 9999);
 
				SetDParamMaxDigits(0, 4);
 
				SetDParamMaxDigits(1, 4);
 
				/* We really don't know the width. We could determine it by scanning the NewGRFs,
 
				 * but this is the status window for scanning them... */
 
				size->width = max(400U, GetStringBoundingBox(STR_NEWGRF_SCAN_STATUS).width);
 
				size->height = FONT_HEIGHT_NORMAL * 2 + WD_PAR_VSEP_NORMAL;
 
				break;
 
		}
src/order_gui.cpp
Show inline comments
 
@@ -1094,13 +1094,13 @@ public:
 

	
 
	virtual void DrawWidget(const Rect &r, int widget) const
 
	{
 
		if (widget != WID_O_ORDER_LIST) return;
 

	
 
		bool rtl = _current_text_dir == TD_RTL;
 
		SetDParam(0, 99);
 
		SetDParamMaxValue(0, this->vehicle->GetNumOrders(), 2);
 
		int index_column_width = GetStringBoundingBox(STR_ORDER_INDEX).width + 2 * GetSpriteSize(rtl ? SPR_ARROW_RIGHT : SPR_ARROW_LEFT).width + 3;
 
		int middle = rtl ? r.right - WD_FRAMETEXT_RIGHT - index_column_width : r.left + WD_FRAMETEXT_LEFT + index_column_width;
 

	
 
		int y = r.top + WD_FRAMERECT_TOP;
 
		int line_height = this->GetWidget<NWidgetBase>(WID_O_ORDER_LIST)->resize_y;
 

	
src/signs_gui.cpp
Show inline comments
 
@@ -271,13 +271,13 @@ struct SignListWindow : Window, SignList
 
				Dimension d = {this->text_offset + WD_FRAMETEXT_RIGHT, WD_FRAMERECT_TOP + 5 * resize->height + WD_FRAMERECT_BOTTOM};
 
				*size = maxdim(*size, d);
 
				break;
 
			}
 

	
 
			case WID_SIL_CAPTION:
 
				SetDParam(0, max<size_t>(1000, Sign::GetPoolSize()));
 
				SetDParamMaxValue(0, Sign::GetPoolSize(), 3);
 
				*size = GetStringBoundingBox(STR_SIGN_LIST_CAPTION);
 
				size->height += padding.height;
 
				size->width  += padding.width;
 
				break;
 
		}
 
	}
src/statusbar_gui.cpp
Show inline comments
 
@@ -101,13 +101,13 @@ struct StatusBarWindow : Window {
 

	
 
	virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
 
	{
 
		Dimension d;
 
		switch (widget) {
 
			case WID_S_LEFT:
 
				SetDParam(0, MAX_YEAR * DAYS_IN_YEAR);
 
				SetDParamMaxValue(0, MAX_YEAR * DAYS_IN_YEAR);
 
				d = GetStringBoundingBox(STR_WHITE_DATE_LONG);
 
				break;
 

	
 
			case WID_S_RIGHT: {
 
				int64 max_money = UINT32_MAX;
 
				const Company *c;
src/strings.cpp
Show inline comments
 
@@ -88,12 +88,44 @@ void StringParameters::ShiftParameters(u
 
{
 
	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 indepentent of \a max.
 
 */
 
void SetDParamMaxValue(uint n, uint64 max_value, uint min_count)
 
{
 
	uint num_digits = 1;
 
	while (max_value >= 10) {
 
		num_digits++;
 
		max_value /= 10;
 
	}
 
	SetDParamMaxDigits(n, max(min_count, num_digits));
 
}
 

	
 
/**
 
 * 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.
 
 */
 
void SetDParamMaxDigits(uint n, uint count)
 
{
 
	static const uint biggest_digit = 8; ///< Digit with the biggest string width.
 
	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.
 
 */
 
void CopyInDParam(int offs, const uint64 *src, int num)
src/strings_func.h
Show inline comments
 
@@ -152,12 +152,15 @@ static inline void SetDParamX(uint64 *s,
 
 */
 
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 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);
 

	
src/timetable_gui.cpp
Show inline comments
 
@@ -197,13 +197,13 @@ struct TimetableWindow : Window {
 
	}
 

	
 
	virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
 
	{
 
		switch (widget) {
 
			case WID_VT_ARRIVAL_DEPARTURE_PANEL:
 
				SetDParam(0, MAX_YEAR * DAYS_IN_YEAR);
 
				SetDParamMaxValue(0, MAX_YEAR * DAYS_IN_YEAR);
 
				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:
 
@@ -365,13 +365,13 @@ struct TimetableWindow : Window {
 
				int y = r.top + WD_FRAMERECT_TOP;
 
				int i = this->vscroll->GetPosition();
 
				VehicleOrderID order_id = (i + 1) / 2;
 
				bool final_order = false;
 

	
 
				bool rtl = _current_text_dir == TD_RTL;
 
				SetDParam(0, 99);
 
				SetDParamMaxValue(0, v->GetNumOrders(), 2);
 
				int index_column_width = GetStringBoundingBox(STR_ORDER_INDEX).width + 2 * GetSpriteSize(rtl ? SPR_ARROW_RIGHT : SPR_ARROW_LEFT).width + 3;
 
				int middle = rtl ? r.right - WD_FRAMERECT_RIGHT - index_column_width : r.left + WD_FRAMERECT_LEFT + index_column_width;
 

	
 
				const Order *order = v->GetOrder(order_id);
 
				while (order != NULL) {
 
					/* Don't draw anything if it extends past the end of the window. */
src/town_gui.cpp
Show inline comments
 
@@ -777,13 +777,13 @@ public:
 
				for (uint i = 0; i < this->towns.Length(); i++) {
 
					const Town *t = this->towns[i];
 

	
 
					assert(t != NULL);
 

	
 
					SetDParam(0, t->index);
 
					SetDParam(1, 10000000); // 10^7
 
					SetDParamMaxDigits(1, 8);
 
					d = maxdim(d, GetStringBoundingBox(STR_TOWN_DIRECTORY_TOWN));
 
				}
 
				Dimension icon_size = GetSpriteSize(SPR_TOWN_RATING_GOOD);
 
				d.width += icon_size.width + 2;
 
				d.height = max(d.height, icon_size.height);
 
				resize->height = d.height;
 
@@ -791,13 +791,13 @@ public:
 
				d.width += padding.width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
 
				d.height += padding.height + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
 
				*size = maxdim(*size, d);
 
				break;
 
			}
 
			case WID_TD_WORLD_POPULATION: {
 
				SetDParam(0, 1000000000); // 10^9
 
				SetDParamMaxDigits(0, 10);
 
				Dimension d = GetStringBoundingBox(STR_TOWN_POPULATION);
 
				d.width += padding.width;
 
				d.height += padding.height;
 
				*size = maxdim(*size, d);
 
				break;
 
			}
src/vehicle_gui.cpp
Show inline comments
 
@@ -1802,13 +1802,13 @@ struct VehicleDetailsWindow : Window {
 
	{
 
		switch (widget) {
 
			case WID_VD_TOP_DETAILS: {
 
				Dimension dim = { 0, 0 };
 
				size->height = WD_FRAMERECT_TOP + 4 * FONT_HEIGHT_NORMAL + WD_FRAMERECT_BOTTOM;
 

	
 
				for (uint i = 0; i < 4; i++) SetDParam(i, INT16_MAX);
 
				for (uint i = 0; i < 4; i++) SetDParamMaxValue(i, INT16_MAX);
 
				static const StringID info_strings[] = {
 
					STR_VEHICLE_INFO_MAX_SPEED,
 
					STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED,
 
					STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE,
 
					STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR,
 
					STR_VEHICLE_INFO_RELIABILITY_BREAKDOWNS
 
@@ -1846,14 +1846,14 @@ struct VehicleDetailsWindow : Window {
 
			case WID_VD_MATRIX:
 
				resize->height = WD_MATRIX_TOP + FONT_HEIGHT_NORMAL + WD_MATRIX_BOTTOM;
 
				size->height = 4 * resize->height;
 
				break;
 

	
 
			case WID_VD_SERVICING_INTERVAL:
 
				SetDParam(0, 9999); // Roughly the maximum interval
 
				SetDParam(1, MAX_YEAR * DAYS_IN_YEAR); // Roughly the maximum year
 
				SetDParamMaxValue(0, MAX_SERVINT_DAYS); // Roughly the maximum interval
 
				SetDParamMaxValue(1, MAX_YEAR * DAYS_IN_YEAR); // Roughly the maximum year
 
				size->width = max(GetStringBoundingBox(STR_VEHICLE_DETAILS_SERVICING_INTERVAL_PERCENT).width, GetStringBoundingBox(STR_VEHICLE_DETAILS_SERVICING_INTERVAL_DAYS).width) + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
 
				size->height = WD_FRAMERECT_TOP + FONT_HEIGHT_NORMAL + WD_FRAMERECT_BOTTOM;
 
				break;
 
		}
 
	}
 

	
0 comments (0 inline, 0 general)