summaryrefslogtreecommitdiff
path: root/src/vehicle_gui.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-11-17 09:09:20 +0000
committerrubidium <rubidium@openttd.org>2009-11-17 09:09:20 +0000
commitbdb118aa69131d401850ad6209da8ffd748531b4 (patch)
tree0de56b7af7dc7046857df63ceecd3bb03de9e9dc /src/vehicle_gui.cpp
parenta808623b24b247d3a8b3b08875dd6cd2e22a85c6 (diff)
downloadopenttd-bdb118aa69131d401850ad6209da8ffd748531b4.tar.xz
(svn r18134) -Codechange: scale the offset of the text/vehicle in the vehicle lists based on the font and the unit numbers in the list
Diffstat (limited to 'src/vehicle_gui.cpp')
-rw-r--r--src/vehicle_gui.cpp26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index 20e35fcfa..9bf5e6841 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -100,6 +100,22 @@ void BaseVehicleListWindow::BuildVehicleList(Owner owner, uint16 index, uint16 w
GenerateVehicleSortList(&this->vehicles, this->vehicle_type, owner, index, window_type);
+ uint unitnumber = 0;
+ for (const Vehicle **v = this->vehicles.Begin(); v != this->vehicles.End(); v++) {
+ unitnumber = max<uint>(unitnumber, (*v)->unitnumber);
+ }
+
+ /* Because 111 is much less wide than e.g. 999 we use the
+ * wider numbers to determine the width instead of just
+ * the random number that it seems to be. */
+ if (unitnumber >= 1000) {
+ this->max_unitnumber = 9999;
+ } else if (unitnumber >= 100) {
+ this->max_unitnumber = 999;
+ } else {
+ this->max_unitnumber = 99;
+ }
+
this->vehicles.RebuildDone();
this->vscroll.SetCount(this->vehicles.Length());
}
@@ -827,11 +843,13 @@ void BaseVehicleListWindow::DrawVehicleListItems(VehicleID selected_vehicle, int
int right = r.right - WD_MATRIX_RIGHT;
bool rtl = _dynlang.text_dir == TD_RTL;
- int text_left = left + (rtl ? 0 : 19);
- int text_right = right - (rtl ? 19 : 0);
+ SetDParam(0, this->max_unitnumber);
+ int text_offset = GetStringBoundingBox(STR_JUST_INT).width + WD_FRAMERECT_RIGHT;
+ int text_left = left + (rtl ? 0 : text_offset);
+ int text_right = right - (rtl ? text_offset : 0);
- int orderlist_left = left + (rtl ? 0 : 138);
- int orderlist_right = right - (rtl ? 138 : 0);
+ int orderlist_left = left + (rtl ? 0 : 120 + text_offset);
+ int orderlist_right = right - (rtl ? 120 + text_offset : 0);
int vehicle_button_x = rtl ? right - 8 : left;