| 394 | } |
| 395 | |
| 396 | void DrawWidget(const Rect &r, WidgetID widget) const override |
| 397 | { |
| 398 | if (widget != WID_D_MATRIX) return; |
| 399 | |
| 400 | bool rtl = _current_text_dir == TD_RTL; |
| 401 | |
| 402 | /* Set the row and number of boxes in each row based on the number of boxes drawn in the matrix */ |
| 403 | const NWidgetCore *wid = this->GetWidget<NWidgetCore>(WID_D_MATRIX); |
| 404 | |
| 405 | /* Set up rect for each cell */ |
| 406 | Rect ir = r.WithHeight(this->resize.step_height); |
| 407 | if (this->num_columns != 1) ir = ir.WithWidth(this->resize.step_width, rtl); |
| 408 | ir = ir.Shrink(WidgetDimensions::scaled.framerect, RectPadding::zero); |
| 409 | |
| 410 | /* Draw vertical separators at whole tiles. |
| 411 | * This only works in two cases: |
| 412 | * - All vehicles use VEHICLEINFO_FULL_VEHICLE_WIDTH as reference width. |
| 413 | * - All vehicles are 8/8. This cannot be checked for NewGRF, so instead we check for "all vehicles are original vehicles". |
| 414 | */ |
| 415 | if (this->type == VEH_TRAIN && _consistent_train_width != 0) { |
| 416 | int w = ScaleSpriteTrad(2 * _consistent_train_width); |
| 417 | PixelColour col = GetColourGradient(wid->colour, SHADE_NORMAL); |
| 418 | Rect image = ir.Indent(this->header_width, rtl).Indent(this->count_width, !rtl); |
| 419 | int first_line = w + (-this->hscroll->GetPosition()) % w; |
| 420 | if (rtl) { |
| 421 | for (int x = image.right - first_line; x >= image.left; x -= w) { |
| 422 | GfxDrawLine(x, r.top, x, r.bottom, col, ScaleGUITrad(1), ScaleGUITrad(3)); |
| 423 | } |
| 424 | } else { |
| 425 | for (int x = image.left + first_line; x <= image.right; x += w) { |
| 426 | GfxDrawLine(x, r.top, x, r.bottom, col, ScaleGUITrad(1), ScaleGUITrad(3)); |
| 427 | } |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | uint16_t rows_in_display = wid->current_y / wid->resize_y; |
| 432 | |
| 433 | uint num = this->vscroll->GetPosition() * this->num_columns; |
| 434 | uint maxval = static_cast<uint>(std::min<size_t>(this->vehicle_list.size(), num + (rows_in_display * this->num_columns))); |
| 435 | for (; num < maxval; ir = ir.Translate(0, this->resize.step_height)) { // Draw the rows |
| 436 | Rect cell = ir; /* Keep track of horizontal cells */ |
| 437 | for (uint i = 0; i < this->num_columns && num < maxval; i++, num++) { |
| 438 | /* Draw all vehicles in the current row */ |
| 439 | const Vehicle *v = this->vehicle_list[num]; |
| 440 | this->DrawVehicleInDepot(v, cell); |
| 441 | cell = cell.Translate(rtl ? -(int)this->resize.step_width : (int)this->resize.step_width, 0); |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | maxval = static_cast<uint>(std::min<size_t>(this->vehicle_list.size() + this->wagon_list.size(), (this->vscroll->GetPosition() * this->num_columns) + (rows_in_display * this->num_columns))); |
| 446 | |
| 447 | /* Draw the train wagons without an engine in front. */ |
| 448 | for (; num < maxval; num++, ir = ir.Translate(0, this->resize.step_height)) { |
| 449 | const Vehicle *v = this->wagon_list[num - this->vehicle_list.size()]; |
| 450 | this->DrawVehicleInDepot(v, ir); |
| 451 | } |
| 452 | } |
| 453 |
nothing calls this directly
no test coverage detected