Codechange: Remove FONT_HEIGHT_... macros. (#11481)

These make it look like we're dealing with a constant, but actually each is a call to `GetCharacterHeight(...)`.
This commit is contained in:
Peter Nelson
2023-11-21 19:04:24 +00:00
committed by GitHub
parent 96ec9c1b47
commit c18a1494b7
57 changed files with 369 additions and 381 deletions

View File

@@ -91,7 +91,7 @@ struct ExpensesList {
uint GetHeight() const
{
/* Add up the height of all the lines. */
return static_cast<uint>(this->items.size()) * FONT_HEIGHT_NORMAL;
return static_cast<uint>(this->items.size()) * GetCharacterHeight(FS_NORMAL);
}
/** Compute width of the expenses categories in pixels. */
@@ -119,15 +119,15 @@ static const std::initializer_list<ExpensesList> _expenses_list_types = {
static uint GetTotalCategoriesHeight()
{
/* There's an empty line and blockspace on the year row */
uint total_height = FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_wide;
uint total_height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_wide;
for (const ExpensesList &list : _expenses_list_types) {
/* Title + expense list + total line + total + blockspace after category */
total_height += FONT_HEIGHT_NORMAL + list.GetHeight() + WidgetDimensions::scaled.vsep_normal + FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_wide;
total_height += GetCharacterHeight(FS_NORMAL) + list.GetHeight() + WidgetDimensions::scaled.vsep_normal + GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_wide;
}
/* Total income */
total_height += WidgetDimensions::scaled.vsep_normal + FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_wide;
total_height += WidgetDimensions::scaled.vsep_normal + GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_wide;
return total_height;
}
@@ -162,7 +162,7 @@ static void DrawCategory(const Rect &r, int start_y, const ExpensesList &list)
for (const ExpensesType &et : list.items) {
DrawString(tr, STR_FINANCES_SECTION_CONSTRUCTION + et);
tr.top += FONT_HEIGHT_NORMAL;
tr.top += GetCharacterHeight(FS_NORMAL);
}
}
@@ -174,12 +174,12 @@ static void DrawCategory(const Rect &r, int start_y, const ExpensesList &list)
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 + WidgetDimensions::scaled.vsep_wide;
int y = r.top + GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_wide;
for (const ExpensesList &list : _expenses_list_types) {
/* Draw category title and advance y */
DrawString(r.left, r.right, y, list.title, TC_FROMSTRING, SA_LEFT);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);
/* Draw category items and advance y */
DrawCategory(r, y, list);
@@ -190,7 +190,7 @@ static void DrawCategories(const Rect &r)
/* Draw category total and advance y */
DrawString(r.left, r.right, y, STR_FINANCES_TOTAL_CAPTION, TC_FROMSTRING, SA_RIGHT);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);
/* Advance y by a blockspace after this category block */
y += WidgetDimensions::scaled.vsep_wide;
@@ -235,7 +235,7 @@ static Money DrawYearCategory(const Rect &r, int start_y, const ExpensesList &li
Money cost = tbl[et];
sum += cost;
if (cost != 0) DrawPrice(cost, r.left, r.right, y, TC_BLACK);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);
}
/* Draw the total at the bottom of the category. */
@@ -263,14 +263,14 @@ static void DrawYearColumn(const Rect &r, TimerGameCalendar::Year year, const Ex
/* Year header */
SetDParam(0, year);
DrawString(r.left, r.right, y, STR_FINANCES_YEAR, TC_FROMSTRING, SA_RIGHT, true);
y += FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_wide;
y += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_wide;
/* Categories */
for (const ExpensesList &list : _expenses_list_types) {
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);
sum += DrawYearCategory(r, y, list, tbl);
/* Expense list + expense category title + expense category total + blockspace after category */
y += list.GetHeight() + WidgetDimensions::scaled.vsep_normal + FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_wide;
y += list.GetHeight() + WidgetDimensions::scaled.vsep_normal + GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_wide;
}
/* Total income. */
@@ -405,7 +405,7 @@ struct CompanyFinancesWindow : Window {
break;
case WID_CF_INTEREST_RATE:
size->height = FONT_HEIGHT_NORMAL;
size->height = GetCharacterHeight(FS_NORMAL);
break;
}
}
@@ -586,7 +586,7 @@ public:
uint Height() const override
{
return std::max(FONT_HEIGHT_NORMAL, ScaleGUITrad(12) + WidgetDimensions::scaled.vsep_normal);
return std::max(GetCharacterHeight(FS_NORMAL), ScaleGUITrad(12) + WidgetDimensions::scaled.vsep_normal);
}
bool Selectable() const override
@@ -598,7 +598,7 @@ public:
{
bool rtl = _current_text_dir == TD_RTL;
int icon_y = CenterBounds(r.top, r.bottom, 0);
int text_y = CenterBounds(r.top, r.bottom, FONT_HEIGHT_NORMAL);
int text_y = CenterBounds(r.top, r.bottom, GetCharacterHeight(FS_NORMAL));
Rect tr = r.Shrink(WidgetDimensions::scaled.dropdowntext);
DrawSprite(SPR_VEH_BUS_SIDE_VIEW, PALETTE_RECOLOUR_START + (this->result % COLOUR_END),
rtl ? tr.right - ScaleGUITrad(14) : tr.left + ScaleGUITrad(14),
@@ -818,7 +818,7 @@ public:
case WID_SCL_MATRIX: {
/* 11 items in the default rail class */
this->square = GetSpriteSize(SPR_SQUARE);
this->line_height = std::max(this->square.height, (uint)FONT_HEIGHT_NORMAL) + padding.height;
this->line_height = std::max(this->square.height, (uint)GetCharacterHeight(FS_NORMAL)) + padding.height;
size->height = 11 * this->line_height;
resize->width = 1;
@@ -923,7 +923,7 @@ public:
Rect ir = r.WithHeight(this->resize.step_height).Shrink(WidgetDimensions::scaled.matrix);
int square_offs = (ir.Height() - this->square.height) / 2;
int text_offs = (ir.Height() - FONT_HEIGHT_NORMAL) / 2;
int text_offs = (ir.Height() - GetCharacterHeight(FS_NORMAL)) / 2;
int y = ir.top;
@@ -1928,7 +1928,7 @@ struct CompanyInfrastructureWindow : Window
size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_SIGNALS).width + padding.width + WidgetDimensions::scaled.hsep_indent);
}
size->height = std::max(size->height, lines * FONT_HEIGHT_NORMAL);
size->height = std::max(size->height, lines * GetCharacterHeight(FS_NORMAL));
break;
}
@@ -1945,7 +1945,7 @@ struct CompanyInfrastructureWindow : Window
}
}
size->height = std::max(size->height, lines * FONT_HEIGHT_NORMAL);
size->height = std::max(size->height, lines * GetCharacterHeight(FS_NORMAL));
break;
}
@@ -2006,7 +2006,7 @@ struct CompanyInfrastructureWindow : Window
/* Set height of the total line. */
if (widget == WID_CI_TOTAL) {
size->height = _settings_game.economy.infrastructure_maintenance ? std::max<uint>(size->height, WidgetDimensions::scaled.vsep_normal + FONT_HEIGHT_NORMAL) : 0;
size->height = _settings_game.economy.infrastructure_maintenance ? std::max<uint>(size->height, WidgetDimensions::scaled.vsep_normal + GetCharacterHeight(FS_NORMAL)) : 0;
}
break;
}
@@ -2023,7 +2023,7 @@ struct CompanyInfrastructureWindow : Window
void DrawCountLine(const Rect &r, int &y, int count, Money monthly_cost) const
{
SetDParam(0, count);
DrawString(r.left, r.right, y += FONT_HEIGHT_NORMAL, STR_JUST_COMMA, TC_WHITE, SA_RIGHT);
DrawString(r.left, r.right, y += GetCharacterHeight(FS_NORMAL), STR_JUST_COMMA, TC_WHITE, SA_RIGHT);
if (_settings_game.economy.infrastructure_maintenance) {
SetDParam(0, monthly_cost * 12); // Convert to per year
@@ -2047,13 +2047,13 @@ struct CompanyInfrastructureWindow : Window
/* Draw name of each valid railtype. */
for (const auto &rt : _sorted_railtypes) {
if (HasBit(this->railtypes, rt)) {
DrawString(ir.left, ir.right, y += FONT_HEIGHT_NORMAL, GetRailTypeInfo(rt)->strings.name, TC_WHITE);
DrawString(ir.left, ir.right, y += GetCharacterHeight(FS_NORMAL), GetRailTypeInfo(rt)->strings.name, TC_WHITE);
}
}
DrawString(ir.left, ir.right, y += FONT_HEIGHT_NORMAL, STR_COMPANY_INFRASTRUCTURE_VIEW_SIGNALS);
DrawString(ir.left, ir.right, y += GetCharacterHeight(FS_NORMAL), STR_COMPANY_INFRASTRUCTURE_VIEW_SIGNALS);
} else {
/* No valid railtype. */
DrawString(ir.left, ir.right, y += FONT_HEIGHT_NORMAL, STR_COMPANY_VIEW_INFRASTRUCTURE_NONE);
DrawString(ir.left, ir.right, y += GetCharacterHeight(FS_NORMAL), STR_COMPANY_VIEW_INFRASTRUCTURE_NONE);
}
break;
@@ -2079,7 +2079,7 @@ struct CompanyInfrastructureWindow : Window
/* Draw name of each valid roadtype. */
for (const auto &rt : _sorted_roadtypes) {
if (HasBit(this->roadtypes, rt) && RoadTypeIsRoad(rt) == (widget == WID_CI_ROAD_DESC)) {
DrawString(ir.left, ir.right, y += FONT_HEIGHT_NORMAL, GetRoadTypeInfo(rt)->strings.name, TC_WHITE);
DrawString(ir.left, ir.right, y += GetCharacterHeight(FS_NORMAL), GetRoadTypeInfo(rt)->strings.name, TC_WHITE);
}
}
@@ -2099,7 +2099,7 @@ struct CompanyInfrastructureWindow : Window
case WID_CI_WATER_DESC:
DrawString(r.left, r.right, y, STR_COMPANY_INFRASTRUCTURE_VIEW_WATER_SECT);
DrawString(ir.left, ir.right, y += FONT_HEIGHT_NORMAL, STR_COMPANY_INFRASTRUCTURE_VIEW_CANALS);
DrawString(ir.left, ir.right, y += GetCharacterHeight(FS_NORMAL), STR_COMPANY_INFRASTRUCTURE_VIEW_CANALS);
break;
case WID_CI_WATER_COUNT:
@@ -2118,8 +2118,8 @@ struct CompanyInfrastructureWindow : Window
case WID_CI_STATION_DESC:
DrawString(r.left, r.right, y, STR_COMPANY_INFRASTRUCTURE_VIEW_STATION_SECT);
DrawString(ir.left, ir.right, y += FONT_HEIGHT_NORMAL, STR_COMPANY_INFRASTRUCTURE_VIEW_STATIONS);
DrawString(ir.left, ir.right, y += FONT_HEIGHT_NORMAL, STR_COMPANY_INFRASTRUCTURE_VIEW_AIRPORTS);
DrawString(ir.left, ir.right, y += GetCharacterHeight(FS_NORMAL), STR_COMPANY_INFRASTRUCTURE_VIEW_STATIONS);
DrawString(ir.left, ir.right, y += GetCharacterHeight(FS_NORMAL), STR_COMPANY_INFRASTRUCTURE_VIEW_AIRPORTS);
break;
case WID_CI_STATION_COUNT:
@@ -2418,7 +2418,7 @@ struct CompanyWindow : Window
if (amount != 0) {
SetDParam(0, amount);
DrawString(r.left, r.right, y, _company_view_vehicle_count_strings[type]);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);
}
}
@@ -2437,7 +2437,7 @@ struct CompanyWindow : Window
if (rail_pieces != 0) {
SetDParam(0, rail_pieces);
DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_RAIL);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);
}
uint road_pieces = 0;
@@ -2445,25 +2445,25 @@ struct CompanyWindow : Window
if (road_pieces != 0) {
SetDParam(0, road_pieces);
DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_ROAD);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);
}
if (c->infrastructure.water != 0) {
SetDParam(0, c->infrastructure.water);
DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_WATER);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);
}
if (c->infrastructure.station != 0) {
SetDParam(0, c->infrastructure.station);
DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_STATION);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);
}
if (c->infrastructure.airport != 0) {
SetDParam(0, c->infrastructure.airport);
DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_AIRPORT);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);
}
if (y == r.top) {