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

Method DrawWidget

src/station_gui.cpp:495–553  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

493 }
494
495 void DrawWidget(const Rect &r, WidgetID widget) const override
496 {
497 switch (widget) {
498 case WID_STL_SORTBY:
499 /* draw arrow pointing up/down for ascending/descending sorting */
500 this->DrawSortButtonState(WID_STL_SORTBY, this->stations.IsDescSortOrder() ? SBS_DOWN : SBS_UP);
501 break;
502
503 case WID_STL_LIST: {
504 bool rtl = _current_text_dir == TD_RTL;
505 Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
506 uint line_height = this->GetWidget<NWidgetBase>(widget)->resize_y;
507 /* Spacing between station name and first rating graph. */
508 int text_spacing = WidgetDimensions::scaled.hsep_wide;
509 /* Spacing between additional rating graphs. */
510 int rating_spacing = WidgetDimensions::scaled.hsep_normal;
511
512 auto [first, last] = this->vscroll->GetVisibleRangeIterators(this->stations);
513 for (auto it = first; it != last; ++it) {
514 const Station *st = *it;
515 assert(st->xy != INVALID_TILE);
516
517 /* Do not do the complex check HasStationInUse here, it may be even false
518 * when the order had been removed and the station list hasn't been removed yet */
519 assert(st->owner == owner || st->owner == OWNER_NONE);
520
521 int x = DrawString(tr.left, tr.right, tr.top + (line_height - GetCharacterHeight(FS_NORMAL)) / 2, GetString(STR_STATION_LIST_STATION, st->index, st->facilities));
522 x += rtl ? -text_spacing : text_spacing;
523
524 /* show cargo waiting and station ratings */
525 for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
526 CargoType cargo_type = cs->Index();
527 if (st->goods[cargo_type].HasRating()) {
528 /* For RTL we work in exactly the opposite direction. So
529 * decrement the space needed first, then draw to the left
530 * instead of drawing to the left and then incrementing
531 * the space. */
532 if (rtl) {
533 x -= rating_width + rating_spacing;
534 if (x < tr.left) break;
535 }
536 StationsWndShowStationRating(x, x + rating_width, tr.top, cargo_type, st->goods[cargo_type].TotalCount(), st->goods[cargo_type].rating);
537 if (!rtl) {
538 x += rating_width + rating_spacing;
539 if (x > tr.right) break;
540 }
541 }
542 }
543 tr.top += line_height;
544 }
545
546 if (this->vscroll->GetCount() == 0) { // company has no stations
547 DrawString(tr.left, tr.right, tr.top + (line_height - GetCharacterHeight(FS_NORMAL)) / 2, STR_STATION_LIST_NONE);
548 return;
549 }
550 break;
551 }
552 }

Callers

nothing calls this directly

Calls 13

GetCharacterHeightFunction · 0.85
DrawSortButtonStateMethod · 0.80
IsDescSortOrderMethod · 0.80
ShrinkMethod · 0.80
HasRatingMethod · 0.80
DrawStringFunction · 0.70
GetStringFunction · 0.70
IndexMethod · 0.45
TotalCountMethod · 0.45

Tested by

no test coverage detected