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

Method DrawWidget

src/order_gui.cpp:1069–1124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1067 }
1068
1069 void DrawWidget(const Rect &r, WidgetID widget) const override
1070 {
1071 if (widget != WID_O_ORDER_LIST) return;
1072
1073 Rect ir = r.Shrink(WidgetDimensions::scaled.frametext, WidgetDimensions::scaled.framerect);
1074 bool rtl = _current_text_dir == TD_RTL;
1075 uint64_t max_value = GetParamMaxValue(this->vehicle->GetNumOrders(), 2);
1076 int index_column_width = GetStringBoundingBox(GetString(STR_ORDER_INDEX, max_value)).width + 2 * GetSpriteSize(rtl ? SPR_ARROW_RIGHT : SPR_ARROW_LEFT).width + WidgetDimensions::scaled.hsep_normal;
1077 int middle = rtl ? ir.right - index_column_width : ir.left + index_column_width;
1078
1079 int y = ir.top;
1080 int line_height = this->GetWidget<NWidgetBase>(WID_O_ORDER_LIST)->resize_y;
1081
1082 VehicleOrderID i = this->vscroll->GetPosition();
1083 VehicleOrderID num_orders = this->vehicle->GetNumOrders();
1084
1085 /* First draw the highlighting underground if it exists. */
1086 if (this->order_over != INVALID_VEH_ORDER_ID) {
1087 while (i < num_orders) {
1088 /* Don't draw anything if it extends past the end of the window. */
1089 if (!this->vscroll->IsVisible(i)) break;
1090
1091 if (i != this->selected_order && i == this->order_over) {
1092 /* Highlight dragged order destination. */
1093 int top = (this->order_over < this->selected_order ? y : y + line_height) - WidgetDimensions::scaled.framerect.top;
1094 int bottom = std::min(top + 2, ir.bottom);
1095 top = std::max(top - 3, ir.top);
1096 GfxFillRect(ir.left, top, ir.right, bottom, GetColourGradient(COLOUR_GREY, SHADE_LIGHTEST));
1097 break;
1098 }
1099 y += line_height;
1100
1101 i++;
1102 }
1103
1104 /* Reset counters for drawing the orders. */
1105 y = ir.top;
1106 i = this->vscroll->GetPosition();
1107 }
1108
1109 /* Draw the orders. */
1110 while (i < num_orders) {
1111 /* Don't draw anything if it extends past the end of the window. */
1112 if (!this->vscroll->IsVisible(i)) break;
1113
1114 DrawOrderString(this->vehicle, this->vehicle->GetOrder(i), i, y, i == this->selected_order, false, ir.left, middle, ir.right);
1115 y += line_height;
1116
1117 i++;
1118 }
1119
1120 if (this->vscroll->IsVisible(i)) {
1121 StringID str = this->vehicle->IsOrderListShared() ? STR_ORDERS_END_OF_SHARED_ORDERS : STR_ORDERS_END_OF_ORDERS;
1122 DrawString(rtl ? ir.left : middle, rtl ? middle : ir.right, y, str, (i == this->selected_order) ? TC_WHITE : TC_BLACK);
1123 }
1124 }
1125
1126 std::string GetWidgetString(WidgetID widget, StringID stringid) const override

Callers

nothing calls this directly

Calls 15

GetParamMaxValueFunction · 0.85
GetStringBoundingBoxFunction · 0.85
GetSpriteSizeFunction · 0.85
GetColourGradientFunction · 0.85
DrawOrderStringFunction · 0.85
ShrinkMethod · 0.80
GetPositionMethod · 0.80
GetOrderMethod · 0.80
IsOrderListSharedMethod · 0.80
GetStringFunction · 0.70
GfxFillRectFunction · 0.70

Tested by

no test coverage detected