summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeterN <peter1138@openttd.org>2021-04-25 17:51:03 +0100
committerGitHub <noreply@github.com>2021-04-25 17:51:03 +0100
commitf158957a4e9d7fab39e35b5dc3b5e31882d4da52 (patch)
tree4f96dd02b0a33442250b0d14a3d050a019c75c99
parent9d6ff1c780462bed9b1441571919c262f40df3a4 (diff)
downloadopenttd-f158957a4e9d7fab39e35b5dc3b5e31882d4da52.tar.xz
Fix: Use width of tiny arrow string instead of scaled pixels in ship/aircraft list. (#9102)
-rw-r--r--src/vehicle_gui.cpp21
-rw-r--r--src/vehicle_gui_base.h3
2 files changed, 16 insertions, 8 deletions
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index aa2893824..f4b518586 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -240,6 +240,11 @@ Dimension BaseVehicleListWindow::GetActionDropdownSize(bool show_autoreplace, bo
return d;
}
+void BaseVehicleListWindow::OnInit()
+{
+ this->order_arrow_width = GetStringBoundingBox(STR_TINY_RIGHT_ARROW).width;
+}
+
/**
* Display the Action dropdown window.
* @param show_autoreplace If true include the autoreplace item.
@@ -1406,14 +1411,14 @@ static const NWidgetPart _nested_vehicle_list[] = {
EndContainer(),
};
-static void DrawSmallOrderList(const Vehicle *v, int left, int right, int y, VehicleOrderID start = 0)
+static void DrawSmallOrderList(const Vehicle *v, int left, int right, int y, uint order_arrow_width, VehicleOrderID start)
{
const Order *order = v->GetOrder(start);
if (order == nullptr) return;
bool rtl = _current_text_dir == TD_RTL;
- int l_offset = rtl ? 0 : ScaleGUITrad(6);
- int r_offset = rtl ? ScaleGUITrad(6) : 0;
+ int l_offset = rtl ? 0 : order_arrow_width;
+ int r_offset = rtl ? order_arrow_width : 0;
int i = 0;
VehicleOrderID oid = start;
@@ -1438,11 +1443,11 @@ static void DrawSmallOrderList(const Vehicle *v, int left, int right, int y, Veh
}
/** Draw small order list in the vehicle GUI, but without the little black arrow. This is used for shared order groups. */
-static void DrawSmallOrderList(const Order *order, int left, int right, int y)
+static void DrawSmallOrderList(const Order *order, int left, int right, int y, uint order_arrow_width)
{
bool rtl = _current_text_dir == TD_RTL;
- int l_offset = rtl ? 0 : ScaleGUITrad(6);
- int r_offset = rtl ? ScaleGUITrad(6) : 0;
+ int l_offset = rtl ? 0 : order_arrow_width;
+ int r_offset = rtl ? order_arrow_width : 0;
int i = 0;
while (order != nullptr) {
if (order->IsType(OT_GOTO_STATION)) {
@@ -1550,7 +1555,7 @@ void BaseVehicleListWindow::DrawVehicleListItems(VehicleID selected_vehicle, int
DrawString(text_left, text_right, y, STR_TINY_GROUP, TC_BLACK);
}
- if (show_orderlist) DrawSmallOrderList(v, orderlist_left, orderlist_right, y, v->cur_real_order_index);
+ if (show_orderlist) DrawSmallOrderList(v, orderlist_left, orderlist_right, y, this->order_arrow_width, v->cur_real_order_index);
StringID str;
if (v->IsChainInDepot()) {
@@ -1572,7 +1577,7 @@ void BaseVehicleListWindow::DrawVehicleListItems(VehicleID selected_vehicle, int
DrawVehicleImage(vehgroup.vehicles_begin[i], image_left + 8 * i, image_right, y + FONT_HEIGHT_SMALL - 1, selected_vehicle, EIT_IN_LIST, 0);
}
- if (show_orderlist) DrawSmallOrderList((vehgroup.vehicles_begin[0])->GetFirstOrder(), orderlist_left, orderlist_right, y);
+ if (show_orderlist) DrawSmallOrderList((vehgroup.vehicles_begin[0])->GetFirstOrder(), orderlist_left, orderlist_right, y, this->order_arrow_width);
SetDParam(0, vehgroup.NumVehicles());
DrawString(left, right, y + 2, STR_BLACK_COMMA);
diff --git a/src/vehicle_gui_base.h b/src/vehicle_gui_base.h
index 4bbfbf2a8..d724bc343 100644
--- a/src/vehicle_gui_base.h
+++ b/src/vehicle_gui_base.h
@@ -83,6 +83,7 @@ struct BaseVehicleListWindow : public Window {
byte unitnumber_digits; ///< The number of digits of the highest unit number.
Scrollbar *vscroll;
VehicleListIdentifier vli; ///< Identifier of the vehicle list we want to currently show.
+ uint order_arrow_width; ///< Width of the arrow in the small order list.
typedef GUIVehicleGroupList::SortFunction VehicleGroupSortFunction;
typedef GUIVehicleList::SortFunction VehicleIndividualSortFunction;
@@ -104,6 +105,8 @@ struct BaseVehicleListWindow : public Window {
BaseVehicleListWindow(WindowDesc *desc, WindowNumber wno);
+ void OnInit() override;
+
void UpdateSortingFromGrouping();
void DrawVehicleListItems(VehicleID selected_vehicle, int line_height, const Rect &r) const;