summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeterN <peter1138@openttd.org>2021-04-25 19:34:16 +0100
committerGitHub <noreply@github.com>2021-04-25 19:34:16 +0100
commit224625942c44ec33519010ae320b3821d933229a (patch)
tree438df69a2a6296fc60a65ccd04fddca926284594
parent27031b396f4a41842e597abb2867bbe2832d315c (diff)
downloadopenttd-224625942c44ec33519010ae320b3821d933229a.tar.xz
Fix: Count engine details text in lines rather than pixels. (#9107)
This allows the details panel to scale correctly for different zoom levels.
-rw-r--r--src/autoreplace_gui.cpp8
-rw-r--r--src/build_vehicle_gui.cpp10
2 files changed, 9 insertions, 9 deletions
diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp
index d16e0916e..e04eba302 100644
--- a/src/autoreplace_gui.cpp
+++ b/src/autoreplace_gui.cpp
@@ -81,7 +81,7 @@ class ReplaceVehicleWindow : public Window {
bool replace_engines; ///< If \c true, engines are replaced, if \c false, wagons are replaced (only for trains).
bool reset_sel_engine; ///< Also reset #sel_engine while updating left and/or right and no valid engine selected.
GroupID sel_group; ///< Group selected to replace.
- int details_height; ///< Minimal needed height of the details panels (found so far).
+ int details_height; ///< Minimal needed height of the details panels, in text lines (found so far).
byte sort_criteria; ///< Criteria of sorting vehicles.
bool descending_sort_order; ///< Order of sorting vehicles.
bool show_hidden_engines; ///< Whether to show the hidden engines.
@@ -229,7 +229,7 @@ public:
this->engines[0].ForceRebuild();
this->engines[1].ForceRebuild();
this->reset_sel_engine = true;
- this->details_height = ((vehicletype == VEH_TRAIN) ? 10 : 9) * FONT_HEIGHT_NORMAL + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
+ this->details_height = ((vehicletype == VEH_TRAIN) ? 10 : 9);
this->sel_engine[0] = INVALID_ENGINE;
this->sel_engine[1] = INVALID_ENGINE;
this->show_hidden_engines = _engine_sort_show_hidden_engines[vehicletype];
@@ -274,7 +274,7 @@ public:
case WID_RV_LEFT_DETAILS:
case WID_RV_RIGHT_DETAILS:
- size->height = this->details_height;
+ size->height = FONT_HEIGHT_NORMAL * this->details_height + padding.height;
break;
case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: {
@@ -482,7 +482,7 @@ public:
NWidgetBase *nwi = this->GetWidget<NWidgetBase>(side == 0 ? WID_RV_LEFT_DETAILS : WID_RV_RIGHT_DETAILS);
int text_end = DrawVehiclePurchaseInfo(nwi->pos_x + WD_FRAMETEXT_LEFT, nwi->pos_x + nwi->current_x - WD_FRAMETEXT_RIGHT,
nwi->pos_y + WD_FRAMERECT_TOP, this->sel_engine[side], ted);
- needed_height = std::max(needed_height, text_end - (int)nwi->pos_y + WD_FRAMERECT_BOTTOM);
+ needed_height = std::max(needed_height, (text_end - (int)nwi->pos_y - WD_FRAMERECT_TOP) / FONT_HEIGHT_NORMAL);
}
}
if (needed_height != this->details_height) { // Details window are not high enough, enlarge them.
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp
index a7a7d8042..8ac049455 100644
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -1055,7 +1055,7 @@ struct BuildVehicleWindow : Window {
CargoID cargo_filter[NUM_CARGO + 3]; ///< Available cargo filters; CargoID or CF_ANY or CF_NONE or CF_ENGINES
StringID cargo_filter_texts[NUM_CARGO + 4]; ///< Texts for filter_cargo, terminated by INVALID_STRING_ID
byte cargo_filter_criteria; ///< Selected cargo filter
- int details_height; ///< Minimal needed height of the details panels (found so far).
+ int details_height; ///< Minimal needed height of the details panels, in text lines (found so far).
Scrollbar *vscroll;
TestedEngineDetails te; ///< Tested cost and capacity after refit.
@@ -1115,7 +1115,7 @@ struct BuildVehicleWindow : Window {
widget->tool_tip = STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP + type;
widget->SetLowered(this->show_hidden_engines);
- this->details_height = ((this->vehicle_type == VEH_TRAIN) ? 10 : 9) * FONT_HEIGHT_NORMAL + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
+ this->details_height = ((this->vehicle_type == VEH_TRAIN) ? 10 : 9);
this->FinishInitNested(tile == INVALID_TILE ? (int)type : tile);
@@ -1553,7 +1553,7 @@ struct BuildVehicleWindow : Window {
break;
case WID_BV_PANEL:
- size->height = this->details_height;
+ size->height = FONT_HEIGHT_NORMAL * this->details_height + padding.height;
break;
case WID_BV_SORT_ASCENDING_DESCENDING: {
@@ -1620,12 +1620,12 @@ struct BuildVehicleWindow : Window {
NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_BV_PANEL);
int text_end = DrawVehiclePurchaseInfo(nwi->pos_x + WD_FRAMETEXT_LEFT, nwi->pos_x + nwi->current_x - WD_FRAMETEXT_RIGHT,
nwi->pos_y + WD_FRAMERECT_TOP, this->sel_engine, this->te);
- needed_height = std::max(needed_height, text_end - (int)nwi->pos_y + WD_FRAMERECT_BOTTOM);
+ needed_height = std::max(needed_height, (text_end - (int)nwi->pos_y - WD_FRAMERECT_TOP) / FONT_HEIGHT_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);
+ this->ReInit(0, resize * FONT_HEIGHT_NORMAL);
return;
}
}