Changeset - r26582:f8bc4c09d3ec
[Not reviewed]
master
0 8 0
Peter Nelson - 2 years ago 2022-09-27 22:40:16
peter1138@openttd.org
Change: Use standard dimensions instead of custom widths.
8 files changed with 22 insertions and 30 deletions:
0 comments (0 inline, 0 general)
src/company_gui.cpp
Show inline comments
 
@@ -46,16 +46,12 @@
 
#include "widgets/company_widget.h"
 

	
 
#include "safeguards.h"
 

	
 

	
 
/** Company GUI constants. */
 
static const uint EXP_LINESPACE  = 2;      ///< Amount of vertical space for a horizontal (sub-)total line.
 
static const uint EXP_BLOCKSPACE = 10;     ///< Amount of vertical space between two blocks of numbers.
 
static const int  EXP_INDENT     = 10;     ///< Amount of horizontal space for an indented line.
 

	
 
static void DoSelectCompanyManagerFace(Window *parent);
 
static void ShowCompanyInfrastructure(CompanyID company);
 

	
 
/** List of revenues. */
 
static ExpensesType _expenses_list_revenue[] = {
 
	EXPENSES_TRAIN_REVENUE,
 
@@ -119,21 +115,21 @@ static const ExpensesList _expenses_list
 
 * Get the total height of the "categories" column.
 
 * @return The total height in pixels.
 
 */
 
static uint GetTotalCategoriesHeight()
 
{
 
	/* There's an empty line and blockspace on the year row */
 
	uint total_height = FONT_HEIGHT_NORMAL + EXP_BLOCKSPACE;
 
	uint total_height = FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_wide;
 

	
 
	for (uint i = 0; i < lengthof(_expenses_list_types); i++) {
 
		/* Title + expense list + total line + total + blockspace after category */
 
		total_height += FONT_HEIGHT_NORMAL + _expenses_list_types[i].GetHeight() + EXP_LINESPACE + FONT_HEIGHT_NORMAL + EXP_BLOCKSPACE;
 
		total_height += FONT_HEIGHT_NORMAL + _expenses_list_types[i].GetHeight() + WidgetDimensions::scaled.vsep_normal + FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_wide;
 
	}
 

	
 
	/* Total income */
 
	total_height += EXP_LINESPACE + FONT_HEIGHT_NORMAL + EXP_BLOCKSPACE;
 
	total_height += WidgetDimensions::scaled.vsep_normal + FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_wide;
 

	
 
	return total_height;
 
}
 

	
 
/**
 
 * Get the required width of the "categories" column, equal to the widest element.
 
@@ -156,13 +152,13 @@ static uint GetMaxCategoriesWidth()
 

	
 
/**
 
 * Draw a category of expenses (revenue, operating expenses, capital expenses).
 
 */
 
static void DrawCategory(const Rect &r, int start_y, ExpensesList list)
 
{
 
	Rect tr = r.Indent(EXP_INDENT, _current_text_dir == TD_RTL);
 
	Rect tr = r.Indent(WidgetDimensions::scaled.hsep_indent, _current_text_dir == TD_RTL);
 

	
 
	tr.top = start_y;
 
	ExpensesType et;
 

	
 
	for (uint i = 0; i < list.length; i++) {
 
		et = list.et[i];
 
@@ -176,32 +172,32 @@ static void DrawCategory(const Rect &r, 
 
 * @param r Available space for drawing.
 
 * @note The environment must provide padding at the left and right of \a r.
 
 */
 
static void DrawCategories(const Rect &r)
 
{
 
	/* Start with an empty space in the year row, plus the blockspace under the year. */
 
	int y = r.top + FONT_HEIGHT_NORMAL + EXP_BLOCKSPACE;
 
	int y = r.top + FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_wide;
 

	
 
	for (uint i = 0; i < lengthof(_expenses_list_types); i++) {
 
		/* Draw category title and advance y */
 
		DrawString(r.left, r.right, y, (STR_FINANCES_REVENUE_TITLE + i), TC_FROMSTRING, SA_LEFT);
 
		y += FONT_HEIGHT_NORMAL;
 

	
 
		/* Draw category items and advance y */
 
		DrawCategory(r, y, _expenses_list_types[i]);
 
		y += _expenses_list_types[i].GetHeight();
 

	
 
		/* Advance y by the height of the total and associated total line */
 
		y += EXP_LINESPACE + FONT_HEIGHT_NORMAL;
 
		y += WidgetDimensions::scaled.vsep_normal + FONT_HEIGHT_NORMAL;
 

	
 
		/* Advance y by a blockspace after this category block */
 
		y += EXP_BLOCKSPACE;
 
		y += WidgetDimensions::scaled.vsep_wide;
 
	}
 

	
 
	/* Draw total profit/loss */
 
	y += EXP_LINESPACE;
 
	y += WidgetDimensions::scaled.vsep_normal;
 
	DrawString(r.left, r.right, y, STR_FINANCES_NET_PROFIT, TC_FROMSTRING, SA_LEFT);
 
}
 

	
 
/**
 
 * Draw an amount of money.
 
 * @param amount Amount of money to draw,
 
@@ -240,13 +236,13 @@ static Money DrawYearCategory (const Rec
 
		if (cost != 0) DrawPrice(cost, r.left, r.right, y, TC_BLACK);
 
		y += FONT_HEIGHT_NORMAL;
 
	}
 

	
 
	/* Draw the total at the bottom of the category. */
 
	GfxFillRect(r.left, y, r.right, y, PC_BLACK);
 
	y += EXP_LINESPACE;
 
	y += WidgetDimensions::scaled.vsep_normal;
 
	if (sum != 0) DrawPrice(sum, r.left, r.right, y, TC_WHITE);
 

	
 
	/* Return the sum for the yearly total. */
 
	return sum;
 
}
 

	
 
@@ -263,25 +259,25 @@ static void DrawYearColumn(const Rect &r
 
	int y = r.top;
 
	Money sum;
 

	
 
	/* Year header */
 
	SetDParam(0, year);
 
	DrawString(r.left, r.right, y, STR_FINANCES_YEAR, TC_FROMSTRING, SA_RIGHT, true);
 
	y += FONT_HEIGHT_NORMAL + EXP_BLOCKSPACE;
 
	y += FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_wide;
 

	
 
	/* Categories */
 
	for (uint i = 0; i < lengthof(_expenses_list_types); i++) {
 
		y += FONT_HEIGHT_NORMAL;
 
		sum += DrawYearCategory(r, y, _expenses_list_types[i], tbl);
 
		/* Expense list + expense category title + expense category total + blockspace after category */
 
		y += _expenses_list_types[i].GetHeight() + EXP_LINESPACE + FONT_HEIGHT_NORMAL + EXP_BLOCKSPACE;
 
		y += _expenses_list_types[i].GetHeight() + WidgetDimensions::scaled.vsep_normal + FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_wide;
 
	}
 

	
 
	/* Total income. */
 
	GfxFillRect(r.left, y, r.right, y, PC_BLACK);
 
	y += EXP_LINESPACE;
 
	y += WidgetDimensions::scaled.vsep_normal;
 
	DrawPrice(sum, r.left, r.right, y, TC_WHITE);
 
}
 

	
 
static const NWidgetPart _nested_company_finances_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_GREY),
 
@@ -1999,13 +1995,13 @@ struct CompanyInfrastructureWindow : Win
 
				}
 

	
 
				size->width = std::max(size->width, count_width);
 

	
 
				/* Set height of the total line. */
 
				if (widget == WID_CI_TOTAL) {
 
					size->height = _settings_game.economy.infrastructure_maintenance ? std::max(size->height, EXP_LINESPACE + FONT_HEIGHT_NORMAL) : 0;
 
					size->height = _settings_game.economy.infrastructure_maintenance ? std::max<uint>(size->height, WidgetDimensions::scaled.vsep_normal + FONT_HEIGHT_NORMAL) : 0;
 
				}
 
				break;
 
			}
 
		}
 
	}
 

	
 
@@ -2105,13 +2101,13 @@ struct CompanyInfrastructureWindow : Win
 
				break;
 

	
 
			case WID_CI_TOTAL:
 
				if (_settings_game.economy.infrastructure_maintenance) {
 
					Rect tr = r.WithWidth(this->total_width, _current_text_dir == TD_RTL);
 
					GfxFillRect(tr.left, y, tr.right, y, PC_WHITE);
 
					y += EXP_LINESPACE;
 
					y += WidgetDimensions::scaled.vsep_normal;
 
					SetDParam(0, this->GetTotalMaintenanceCost() * 12); // Convert to per year
 
					DrawString(tr.left, tr.right, y, STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL, TC_FROMSTRING, SA_RIGHT);
 
				}
 
				break;
 

	
 
			case WID_CI_STATION_DESC:
src/network/network_gui.cpp
Show inline comments
 
@@ -1504,14 +1504,12 @@ private:
 
	int hover_index; ///< Index of the current line we are hovering over, or -1 if none.
 
	int player_self_index; ///< The line the current player is on.
 
	int player_host_index; ///< The line the host is on.
 

	
 
	std::map<uint, std::vector<std::unique_ptr<ButtonCommon>>> buttons; ///< Per line which buttons are available.
 

	
 
	static const int CLIENT_OFFSET_LEFT = 12; ///< Offset of client entries compared to company entries.
 

	
 
	/**
 
	 * Chat button on a Company is clicked.
 
	 * @param w The instance of this window.
 
	 * @param pt The point where this button was clicked.
 
	 * @param company_id The company this button was assigned to.
 
	 */
 
@@ -1848,13 +1846,13 @@ public:
 

	
 
				Dimension d = GetSpriteSize(SPR_COMPANY_ICON);
 
				uint text_left  = matrix.left  + (rtl ? 0 : d.width + WidgetDimensions::scaled.hsep_wide);
 
				uint text_right = matrix.right - (rtl ? d.width + WidgetDimensions::scaled.hsep_wide : 0);
 

	
 
				Dimension d2 = GetSpriteSize(SPR_PLAYER_SELF);
 
				uint offset_x = CLIENT_OFFSET_LEFT - d2.width - ScaleGUITrad(3);
 
				uint offset_x = WidgetDimensions::scaled.hsep_indent - d2.width - ScaleGUITrad(3);
 

	
 
				uint player_icon_x = rtl ? text_right - offset_x - d2.width : text_left + offset_x;
 

	
 
				if (IsInsideMM(pt.x, player_icon_x, player_icon_x + d2.width)) {
 
					if (index == this->player_self_index) {
 
						GuiShowTooltips(this, STR_NETWORK_CLIENT_LIST_PLAYER_ICON_SELF_TOOLTIP, 0, nullptr, close_cond);
src/newgrf_gui.cpp
Show inline comments
 
@@ -725,21 +725,21 @@ struct NewGRFWindow : public Window, New
 

	
 
	void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
 
	{
 
		switch (widget) {
 
			case WID_NS_FILE_LIST:
 
			{
 
				Dimension d = maxdim(GetSpriteSize(SPR_SQUARE), GetSpriteSize(SPR_WARNING_SIGN));
 
				Dimension d = maxdim(GetScaledSpriteSize(SPR_SQUARE), GetScaledSpriteSize(SPR_WARNING_SIGN));
 
				resize->height = std::max<uint>(d.height + 2U, FONT_HEIGHT_NORMAL);
 
				size->height = std::max(size->height, padding.height + 6 * resize->height);
 
				break;
 
			}
 

	
 
			case WID_NS_AVAIL_LIST:
 
			{
 
				Dimension d = maxdim(GetSpriteSize(SPR_SQUARE), GetSpriteSize(SPR_WARNING_SIGN));
 
				Dimension d = maxdim(GetScaledSpriteSize(SPR_SQUARE), GetScaledSpriteSize(SPR_WARNING_SIGN));
 
				resize->height = std::max<uint>(d.height + 2U, FONT_HEIGHT_NORMAL);
 
				size->height = std::max(size->height, padding.height + 8 * resize->height);
 
				break;
 
			}
 

	
 
			case WID_NS_NEWGRF_INFO_TITLE: {
src/news_gui.cpp
Show inline comments
 
@@ -1156,13 +1156,13 @@ struct MessageHistoryWindow : Window {
 
			this->line_height = FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_normal;
 
			resize->height = this->line_height;
 

	
 
			/* Months are off-by-one, so it's actually 8. Not using
 
			 * month 12 because the 1 is usually less wide. */
 
			SetDParam(0, ConvertYMDToDate(ORIGINAL_MAX_YEAR, 7, 30));
 
			this->date_width = GetStringBoundingBox(STR_SHORT_DATE).width + ScaleGUITrad(5);
 
			this->date_width = GetStringBoundingBox(STR_SHORT_DATE).width + WidgetDimensions::scaled.hsep_wide;
 

	
 
			size->height = 4 * resize->height + WidgetDimensions::scaled.framerect.Vertical(); // At least 4 lines are visible.
 
			size->width = std::max(200u, size->width); // At least 200 pixels wide.
 
		}
 
	}
 

	
src/settings_gui.cpp
Show inline comments
 
@@ -786,13 +786,12 @@ void ShowGameOptions()
 
{
 
	CloseWindowByClass(WC_GAME_OPTIONS);
 
	new GameOptionsWindow(&_game_options_desc);
 
}
 

	
 
static int SETTING_HEIGHT = 11;    ///< Height of a single setting in the tree view in pixels
 
static const int LEVEL_WIDTH = 15; ///< Indenting width of a sub-page in pixels
 

	
 
/**
 
 * Flags for #SettingEntry
 
 * @note The #SEF_BUTTONS_MASK matches expectations of the formal parameter 'state' of #DrawArrowButtons
 
 */
 
enum SettingEntryFlags {
src/smallmap_gui.cpp
Show inline comments
 
@@ -1224,13 +1224,13 @@ void SmallMapWindow::RebuildColourIndexI
 
		case WID_SM_LEGEND: {
 
			uint columns = this->GetNumberColumnsLegend(r.Width());
 
			uint number_of_rows = this->GetNumberRowsLegend(columns);
 
			bool rtl = _current_text_dir == TD_RTL;
 
			uint i = 0; // Row counter for industry legend.
 
			uint row_height = FONT_HEIGHT_SMALL;
 
			int padding = ScaleGUITrad(1);
 
			int padding = WidgetDimensions::scaled.hsep_normal;
 

	
 
			Rect origin = r.WithWidth(this->column_width, rtl).Shrink(WidgetDimensions::scaled.framerect).WithHeight(row_height);
 
			Rect text = origin.Indent(this->legend_width + WidgetDimensions::scaled.hsep_normal, rtl);
 
			Rect icon = origin.WithWidth(this->legend_width, rtl).Shrink(0, padding, 0, 0);
 

	
 
			StringID string = STR_NULL;
src/station_gui.cpp
Show inline comments
 
@@ -1759,13 +1759,13 @@ struct StationViewWindow : public Window
 
					if (pos == -this->scroll_to_row && Station::IsValidID(station)) {
 
						ScrollMainWindowToTile(Station::Get(station)->xy);
 
					}
 
				}
 

	
 
				bool rtl = _current_text_dir == TD_RTL;
 
				Rect text = r.Indent(column * this->expand_shrink_width, rtl).Indent(this->expand_shrink_width, !rtl);
 
				Rect text = r.Indent(column * WidgetDimensions::scaled.hsep_indent, rtl).Indent(this->expand_shrink_width, !rtl);
 
				Rect shrink = r.WithWidth(this->expand_shrink_width, !rtl);
 

	
 
				DrawString(text.left, text.right, y, str);
 

	
 
				if (column < NUM_COLUMNS - 1) {
 
					const char *sym = nullptr;
 
@@ -1837,13 +1837,13 @@ struct StationViewWindow : public Window
 

	
 
			const LinkGraph *lg = LinkGraph::GetIfValid(ge->link_graph);
 
			SetDParam(0, cs->name);
 
			SetDParam(1, lg != nullptr ? lg->Monthly((*lg)[ge->node].Supply()) : 0);
 
			SetDParam(2, STR_CARGO_RATING_APPALLING + (ge->rating >> 5));
 
			SetDParam(3, ToPercent8(ge->rating));
 
			DrawString(tr.Indent(6, rtl), STR_STATION_VIEW_CARGO_SUPPLY_RATING);
 
			DrawString(tr.Indent(WidgetDimensions::scaled.hsep_indent, rtl), STR_STATION_VIEW_CARGO_SUPPLY_RATING);
 
			tr.top += FONT_HEIGHT_NORMAL;
 
		}
 
		return CeilDiv(tr.top - r.top - WidgetDimensions::scaled.framerect.top, FONT_HEIGHT_NORMAL);
 
	}
 

	
 
	/**
src/train_gui.cpp
Show inline comments
 
@@ -179,13 +179,12 @@ struct CargoSummaryItem {
 
		return !(this->cargo != other.cargo);
 
	}
 
};
 

	
 
static const uint TRAIN_DETAILS_MIN_INDENT  = 32; ///< Minimum indent level in the train details window
 
static const uint TRAIN_DETAILS_MAX_INDENT  = 72; ///< Maximum indent level in the train details window; wider than this and we start on a new line
 
static const int  TRAIN_DETAILS_LIST_INDENT = 10; ///< Indent for list items in the Total Cargo window
 

	
 
/** Container for the cargo summary information. */
 
typedef std::vector<CargoSummaryItem> CargoSummary;
 
/** Reused container of cargo details */
 
static CargoSummary _cargo_summary;
 

	
 
@@ -451,13 +450,13 @@ void DrawTrainDetails(const Train *v, co
 

	
 
		/* draw total cargo tab */
 
		DrawString(r.left, r.right, y + text_y_offset, STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY_TEXT);
 
		y += line_height;
 

	
 
		/* Indent the total cargo capacity details */
 
		Rect ir = r.Indent(TRAIN_DETAILS_LIST_INDENT, rtl);
 
		Rect ir = r.Indent(WidgetDimensions::scaled.hsep_indent, rtl);
 
		for (CargoID i = 0; i < NUM_CARGO; i++) {
 
			if (max_cargo[i] > 0 && --vscroll_pos < 0 && vscroll_pos > -vscroll_cap) {
 
				SetDParam(0, i);            // {CARGO} #1
 
				SetDParam(1, act_cargo[i]); // {CARGO} #2
 
				SetDParam(2, i);            // {SHORTCARGO} #1
 
				SetDParam(3, max_cargo[i]); // {SHORTCARGO} #2
0 comments (0 inline, 0 general)