MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / DrawWidget

Method DrawWidget

src/vehicle_gui.cpp:1039–1120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1037 }
1038
1039 void DrawWidget(const Rect &r, WidgetID widget) const override
1040 {
1041 switch (widget) {
1042 case WID_VR_VEHICLE_PANEL_DISPLAY: {
1043 Vehicle *v = Vehicle::Get(this->window_number);
1044 DrawVehicleImage(v, r.WithX(this->sprite_left, this->sprite_right),
1045 VehicleID::Invalid(), EIT_IN_DETAILS, this->hscroll != nullptr ? this->hscroll->GetPosition() : 0);
1046
1047 /* Highlight selected vehicles. */
1048 if (this->order != INVALID_VEH_ORDER_ID) break;
1049 int x = 0;
1050 switch (v->type) {
1051 case VEH_TRAIN: {
1052 VehicleSet vehicles_to_refit;
1053 GetVehicleSet(vehicles_to_refit, Vehicle::Get(this->selected_vehicle), this->num_vehicles);
1054
1055 int left = INT32_MIN;
1056 int width = 0;
1057
1058 /* Determine top & bottom position of the highlight.*/
1059 const int height = ScaleSpriteTrad(12);
1060 const int highlight_top = CentreBounds(r.top, r.bottom, height);
1061 const int highlight_bottom = highlight_top + height - 1;
1062
1063 for (Train *u = Train::From(v); u != nullptr; u = u->Next()) {
1064 /* Start checking. */
1065 const bool contained = std::ranges::find(vehicles_to_refit, u->index) != vehicles_to_refit.end();
1066 if (contained && left == INT32_MIN) {
1067 left = x - this->hscroll->GetPosition() + r.left + this->vehicle_margin;
1068 width = 0;
1069 }
1070
1071 /* Draw a selection. */
1072 if ((!contained || u->Next() == nullptr) && left != INT32_MIN) {
1073 if (u->Next() == nullptr && contained) {
1074 int current_width = u->GetDisplayImageWidth();
1075 width += current_width;
1076 x += current_width;
1077 }
1078
1079 int right = Clamp(left + width, 0, r.right);
1080 left = std::max(0, left);
1081
1082 if (_current_text_dir == TD_RTL) {
1083 right = r.Width() - left;
1084 left = right - width;
1085 }
1086
1087 if (left != right) {
1088 Rect hr = {left, highlight_top, right, highlight_bottom};
1089 DrawFrameRect(hr.Expand(WidgetDimensions::scaled.bevel), COLOUR_WHITE, FrameFlag::BorderOnly);
1090 }
1091
1092 left = INT32_MIN;
1093 }
1094
1095 int current_width = u->GetDisplayImageWidth();
1096 width += current_width;

Callers

nothing calls this directly

Calls 15

GetCapacityStringMethod · 0.95
DrawVehicleImageFunction · 0.85
InvalidFunction · 0.85
GetVehicleSetFunction · 0.85
ScaleSpriteTradFunction · 0.85
CentreBoundsFunction · 0.85
ClampFunction · 0.85
DrawVehicleRefitWindowFunction · 0.85
WithXMethod · 0.80
GetPositionMethod · 0.80
ExpandMethod · 0.80
ShrinkMethod · 0.80

Tested by

no test coverage detected