Skip to content

Commit

Permalink
Codechange: Remove FONT_HEIGHT_... macros. (#11481)
Browse files Browse the repository at this point in the history
These make it look like we're dealing with a constant, but actually each is a call to `GetCharacterHeight(...)`.
  • Loading branch information
PeterN committed Nov 21, 2023
1 parent 96ec9c1 commit c18a149
Show file tree
Hide file tree
Showing 57 changed files with 369 additions and 381 deletions.
2 changes: 1 addition & 1 deletion src/ai/ai_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ struct AIConfigWindow : public Window {
break;

case WID_AIC_LIST:
this->line_height = FONT_HEIGHT_NORMAL + padding.height;
this->line_height = GetCharacterHeight(FS_NORMAL) + padding.height;
resize->height = this->line_height;
size->height = 8 * this->line_height;
break;
Expand Down
6 changes: 3 additions & 3 deletions src/aircraft_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ void DrawAircraftDetails(const Aircraft *v, const Rect &r)
SetDParam(1, u->build_year);
SetDParam(2, u->value);
DrawString(r.left, r.right, y, STR_VEHICLE_INFO_BUILT_VALUE);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);

SetDParam(0, u->cargo_type);
SetDParam(1, u->cargo_cap);
SetDParam(2, u->Next()->cargo_type);
SetDParam(3, u->Next()->cargo_cap);
SetDParam(4, GetCargoSubtypeText(u));
DrawString(r.left, r.right, y, (u->Next()->cargo_cap != 0) ? STR_VEHICLE_INFO_CAPACITY_CAPACITY : STR_VEHICLE_INFO_CAPACITY);
y += FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_normal;
y += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
}

if (u->cargo_cap != 0) {
Expand All @@ -58,7 +58,7 @@ void DrawAircraftDetails(const Aircraft *v, const Rect &r)
SetDParam(1, cargo_count);
SetDParam(2, u->cargo.GetFirstStation());
DrawString(r.left, r.right, y, STR_VEHICLE_DETAILS_CARGO_FROM);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);
feeder_share += u->cargo.GetFeederShare();
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/airport_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ class BuildAirportWindow : public PickerWindowBase {
size->width = std::max(size->width, GetStringBoundingBox(as->name).width + padding.width);
}

this->line_height = FONT_HEIGHT_NORMAL + padding.height;
this->line_height = GetCharacterHeight(FS_NORMAL) + padding.height;
size->height = 5 * this->line_height;
break;
}
Expand Down Expand Up @@ -431,14 +431,14 @@ class BuildAirportWindow : public PickerWindowBase {
/* show the noise of the selected airport */
SetDParam(0, as->noise_level);
DrawString(r.left, r.right, top, STR_STATION_BUILD_NOISE);
top += FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_normal;
top += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
}

if (_settings_game.economy.infrastructure_maintenance) {
Money monthly = _price[PR_INFRASTRUCTURE_AIRPORT] * as->maintenance_cost >> 3;
SetDParam(0, monthly * 12);
DrawString(r.left, r.right, top, STR_STATION_BUILD_INFRASTRUCTURE_COST);
top += FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_normal;
top += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
}

/* strings such as 'Size' and 'Coverage Area' */
Expand Down
4 changes: 2 additions & 2 deletions src/autoreplace_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ class ReplaceVehicleWindow : public Window {

case WID_RV_LEFT_DETAILS:
case WID_RV_RIGHT_DETAILS:
size->height = FONT_HEIGHT_NORMAL * this->details_height + padding.height;
size->height = GetCharacterHeight(FS_NORMAL) * this->details_height + padding.height;
break;

case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: {
Expand Down Expand Up @@ -530,7 +530,7 @@ class ReplaceVehicleWindow : public Window {
const Rect r = this->GetWidget<NWidgetBase>(side == 0 ? WID_RV_LEFT_DETAILS : WID_RV_RIGHT_DETAILS)->GetCurrentRect()
.Shrink(WidgetDimensions::scaled.frametext, WidgetDimensions::scaled.framerect);
int text_end = DrawVehiclePurchaseInfo(r.left, r.right, r.top, this->sel_engine[side], ted);
needed_height = std::max(needed_height, (text_end - r.top) / FONT_HEIGHT_NORMAL);
needed_height = std::max(needed_height, (text_end - r.top) / GetCharacterHeight(FS_NORMAL));
}
}
if (needed_height != this->details_height) { // Details window are not high enough, enlarge them.
Expand Down
76 changes: 38 additions & 38 deletions src/build_vehicle_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
*/
uint GetEngineListHeight(VehicleType type)
{
return std::max<uint>(FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.matrix.Vertical(), GetVehicleImageCellSize(type, EIT_PURCHASE).height);
return std::max<uint>(GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.matrix.Vertical(), GetVehicleImageCellSize(type, EIT_PURCHASE).height);
}

static const NWidgetPart _nested_build_vehicle_widgets[] = {
Expand Down Expand Up @@ -582,7 +582,7 @@ static int DrawCargoCapacityInfo(int left, int right, int y, TestedEngineDetails
SetDParam(1, te.all_capacities[cid]);
SetDParam(2, refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY);
DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);
}

return y;
Expand All @@ -602,30 +602,30 @@ static int DrawRailWagonPurchaseInfo(int left, int right, int y, EngineID engine
SetDParam(0, e->GetCost());
DrawString(left, right, y, STR_PURCHASE_INFO_COST);
}
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);

/* Wagon weight - (including cargo) */
uint weight = e->GetDisplayWeight();
SetDParam(0, weight);
SetDParam(1, GetCargoWeight(te.all_capacities, VEH_TRAIN) + weight);
DrawString(left, right, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);

/* Wagon speed limit, displayed if above zero */
if (_settings_game.vehicle.wagon_speed_limits) {
uint max_speed = e->GetDisplayMaxSpeed();
if (max_speed > 0) {
SetDParam(0, PackVelocity(max_speed, e->type));
DrawString(left, right, y, STR_PURCHASE_INFO_SPEED);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);
}
}

/* Running cost */
if (rvi->running_cost_class != INVALID_PRICE) {
SetDParam(0, e->GetRunningCost());
DrawString(left, right, y, STR_PURCHASE_INFO_RUNNINGCOST);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);
}

return y;
Expand All @@ -647,34 +647,34 @@ static int DrawRailEnginePurchaseInfo(int left, int right, int y, EngineID engin
SetDParam(1, e->GetDisplayWeight());
DrawString(left, right, y, STR_PURCHASE_INFO_COST_WEIGHT);
}
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);

/* Max speed - Engine power */
SetDParam(0, PackVelocity(e->GetDisplayMaxSpeed(), e->type));
SetDParam(1, e->GetPower());
DrawString(left, right, y, STR_PURCHASE_INFO_SPEED_POWER);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);

/* Max tractive effort - not applicable if old acceleration or maglev */
if (_settings_game.vehicle.train_acceleration_model != AM_ORIGINAL && GetRailTypeInfo(rvi->railtype)->acceleration_type != 2) {
SetDParam(0, e->GetDisplayMaxTractiveEffort());
DrawString(left, right, y, STR_PURCHASE_INFO_MAX_TE);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);
}

/* Running cost */
if (rvi->running_cost_class != INVALID_PRICE) {
SetDParam(0, e->GetRunningCost());
DrawString(left, right, y, STR_PURCHASE_INFO_RUNNINGCOST);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);
}

/* Powered wagons power - Powered wagons extra weight */
if (rvi->pow_wag_power != 0) {
SetDParam(0, rvi->pow_wag_power);
SetDParam(1, rvi->pow_wag_weight);
DrawString(left, right, y, STR_PURCHASE_INFO_PWAGPOWER_PWAGWEIGHT);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);
}

return y;
Expand All @@ -695,25 +695,25 @@ static int DrawRoadVehPurchaseInfo(int left, int right, int y, EngineID engine_n
SetDParam(0, e->GetCost());
DrawString(left, right, y, STR_PURCHASE_INFO_COST);
}
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);

/* Road vehicle weight - (including cargo) */
int16_t weight = e->GetDisplayWeight();
SetDParam(0, weight);
SetDParam(1, GetCargoWeight(te.all_capacities, VEH_ROAD) + weight);
DrawString(left, right, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);

/* Max speed - Engine power */
SetDParam(0, PackVelocity(e->GetDisplayMaxSpeed(), e->type));
SetDParam(1, e->GetPower());
DrawString(left, right, y, STR_PURCHASE_INFO_SPEED_POWER);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);

/* Max tractive effort */
SetDParam(0, e->GetDisplayMaxTractiveEffort());
DrawString(left, right, y, STR_PURCHASE_INFO_MAX_TE);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);
} else {
/* Purchase cost - Max speed */
if (te.cost != 0) {
Expand All @@ -726,13 +726,13 @@ static int DrawRoadVehPurchaseInfo(int left, int right, int y, EngineID engine_n
SetDParam(1, PackVelocity(e->GetDisplayMaxSpeed(), e->type));
DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
}
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);
}

/* Running cost */
SetDParam(0, e->GetRunningCost());
DrawString(left, right, y, STR_PURCHASE_INFO_RUNNINGCOST);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);

return y;
}
Expand All @@ -758,7 +758,7 @@ static int DrawShipPurchaseInfo(int left, int right, int y, EngineID engine_numb
SetDParam(1, PackVelocity(ocean_speed, e->type));
DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
}
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);
} else {
if (te.cost != 0) {
SetDParam(0, e->GetCost() + te.cost);
Expand All @@ -768,28 +768,28 @@ static int DrawShipPurchaseInfo(int left, int right, int y, EngineID engine_numb
SetDParam(0, e->GetCost());
DrawString(left, right, y, STR_PURCHASE_INFO_COST);
}
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);

SetDParam(0, PackVelocity(ocean_speed, e->type));
DrawString(left, right, y, STR_PURCHASE_INFO_SPEED_OCEAN);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);

SetDParam(0, PackVelocity(canal_speed, e->type));
DrawString(left, right, y, STR_PURCHASE_INFO_SPEED_CANAL);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);
}

/* Cargo type + capacity */
SetDParam(0, te.cargo);
SetDParam(1, te.capacity);
SetDParam(2, refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY);
DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);

/* Running cost */
SetDParam(0, e->GetRunningCost());
DrawString(left, right, y, STR_PURCHASE_INFO_RUNNINGCOST);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);

return y;
}
Expand Down Expand Up @@ -818,7 +818,7 @@ static int DrawAircraftPurchaseInfo(int left, int right, int y, EngineID engine_
SetDParam(1, PackVelocity(e->GetDisplayMaxSpeed(), e->type));
DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
}
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);

/* Cargo capacity */
if (te.mail_capacity > 0) {
Expand All @@ -835,24 +835,24 @@ static int DrawAircraftPurchaseInfo(int left, int right, int y, EngineID engine_
SetDParam(2, refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY);
DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
}
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);

/* Running cost */
SetDParam(0, e->GetRunningCost());
DrawString(left, right, y, STR_PURCHASE_INFO_RUNNINGCOST);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);

/* Aircraft type */
SetDParam(0, e->GetAircraftTypeText());
DrawString(left, right, y, STR_PURCHASE_INFO_AIRCRAFT_TYPE);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);

/* Aircraft range, if available. */
uint16_t range = e->GetRange();
if (range != 0) {
SetDParam(0, range);
DrawString(left, right, y, STR_PURCHASE_INFO_AIRCRAFT_RANGE);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);
}

return y;
Expand Down Expand Up @@ -958,7 +958,7 @@ int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number,
SetDParam(0, CT_INVALID);
SetDParam(2, STR_EMPTY);
DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);
} else {
y = new_y;
}
Expand All @@ -970,12 +970,12 @@ int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number,
SetDParam(0, ymd.year);
SetDParam(1, TimerGameCalendar::DateToYear(e->GetLifeLengthInDays()));
DrawString(left, right, y, STR_PURCHASE_INFO_DESIGNED_LIFE);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);

/* Reliability */
SetDParam(0, ToPercent16(e->reliability));
DrawString(left, right, y, STR_PURCHASE_INFO_RELIABILITY);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);
}

if (refittable) y = ShowRefitOptionsList(left, right, y, engine_number);
Expand All @@ -988,7 +988,7 @@ int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number,
if (_settings_client.gui.show_newgrf_name && config != nullptr)
{
DrawString(left, right, y, config->GetName(), TC_BLACK);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);
}

return y;
Expand Down Expand Up @@ -1044,8 +1044,8 @@ void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_li
Rect rr = tr.WithWidth(replace_icon.width, !rtl); // Replace icon position
if (show_count) tr = tr.Indent(count_width + WidgetDimensions::scaled.hsep_normal + replace_icon.width + WidgetDimensions::scaled.hsep_wide, !rtl);

int normal_text_y_offset = (ir.Height() - FONT_HEIGHT_NORMAL) / 2;
int small_text_y_offset = ir.Height() - FONT_HEIGHT_SMALL;
int normal_text_y_offset = (ir.Height() - GetCharacterHeight(FS_NORMAL)) / 2;
int small_text_y_offset = ir.Height() - GetCharacterHeight(FS_SMALL);
int replace_icon_y_offset = (ir.Height() - replace_icon.height) / 2;

int y = ir.top;
Expand Down Expand Up @@ -1085,7 +1085,7 @@ void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_li
if (indent > 0) {
/* Draw tree lines */
Rect fr = ir.Indent(indent - WidgetDimensions::scaled.hsep_indent, rtl).WithWidth(circle_width, rtl);
int ycenter = y + normal_text_y_offset + FONT_HEIGHT_NORMAL / 2;
int ycenter = y + normal_text_y_offset + GetCharacterHeight(FS_NORMAL) / 2;
bool continues = (min + 1U) < eng_list.size() && eng_list[min + 1].indent == item.indent;
GfxDrawLine(fr.left + circle_width / 2, y - WidgetDimensions::scaled.matrix.top, fr.left + circle_width / 2, continues ? y - WidgetDimensions::scaled.matrix.top + step_size - 1 : ycenter, linecolour, WidgetDimensions::scaled.fullbevel.top);
GfxDrawLine(fr.left + circle_width / 2, ycenter, fr.right, ycenter, linecolour, WidgetDimensions::scaled.fullbevel.top);
Expand Down Expand Up @@ -1751,7 +1751,7 @@ struct BuildVehicleWindow : Window {
break;

case WID_BV_PANEL:
size->height = FONT_HEIGHT_NORMAL * this->details_height + padding.height;
size->height = GetCharacterHeight(FS_NORMAL) * this->details_height + padding.height;
break;

case WID_BV_SORT_ASCENDING_DESCENDING: {
Expand Down Expand Up @@ -1822,12 +1822,12 @@ struct BuildVehicleWindow : Window {
if (this->sel_engine != INVALID_ENGINE) {
const Rect r = this->GetWidget<NWidgetBase>(WID_BV_PANEL)->GetCurrentRect().Shrink(WidgetDimensions::scaled.frametext, WidgetDimensions::scaled.framerect);
int text_end = DrawVehiclePurchaseInfo(r.left, r.right, r.top, this->sel_engine, this->te);
needed_height = std::max(needed_height, (text_end - r.top) / FONT_HEIGHT_NORMAL);
needed_height = std::max(needed_height, (text_end - r.top) / GetCharacterHeight(FS_NORMAL));
}
if (needed_height != this->details_height) { // Details window are not high enough, enlarge them.
int resize = needed_height - this->details_height;
this->details_height = needed_height;
this->ReInit(0, resize * FONT_HEIGHT_NORMAL);
this->ReInit(0, resize * GetCharacterHeight(FS_NORMAL));
return;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/cheat_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ struct CheatWindow : Window {
uint text_left = ir.left + (rtl ? 0 : WidgetDimensions::scaled.hsep_wide * 4 + this->box.width + SETTING_BUTTON_WIDTH);
uint text_right = ir.right - (rtl ? WidgetDimensions::scaled.hsep_wide * 4 + this->box.width + SETTING_BUTTON_WIDTH : 0);

int text_y_offset = (this->line_height - FONT_HEIGHT_NORMAL) / 2;
int text_y_offset = (this->line_height - GetCharacterHeight(FS_NORMAL)) / 2;
int box_y_offset = (this->line_height - this->box.height) / 2;
int button_y_offset = (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
int icon_y_offset = (this->line_height - this->icon.height) / 2;
Expand Down Expand Up @@ -339,7 +339,7 @@ struct CheatWindow : Window {

this->line_height = std::max(this->box.height, this->icon.height);
this->line_height = std::max<uint>(this->line_height, SETTING_BUTTON_HEIGHT);
this->line_height = std::max<uint>(this->line_height, FONT_HEIGHT_NORMAL) + WidgetDimensions::scaled.framerect.Vertical();
this->line_height = std::max<uint>(this->line_height, GetCharacterHeight(FS_NORMAL)) + WidgetDimensions::scaled.framerect.Vertical();

size->width = width + WidgetDimensions::scaled.hsep_wide * 4 + this->box.width + SETTING_BUTTON_WIDTH /* stuff on the left */ + WidgetDimensions::scaled.hsep_wide * 2 /* extra spacing on right */;
size->height = WidgetDimensions::scaled.framerect.Vertical() + this->line_height * lengthof(_cheats_ui);
Expand Down

0 comments on commit c18a149

Please sign in to comment.