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

Method DrawWidget

src/group_gui.cpp:637–718  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

635 }
636
637 void DrawWidget(const Rect &r, WidgetID widget) const override
638 {
639 switch (widget) {
640 case WID_GL_ALL_VEHICLES:
641 DrawGroupInfo(r, ALL_GROUP);
642 break;
643
644 case WID_GL_DEFAULT_VEHICLES:
645 DrawGroupInfo(r, DEFAULT_GROUP);
646 break;
647
648 case WID_GL_INFO: {
649 Money this_year = 0;
650 Money last_year = 0;
651 uint64_t occupancy = 0;
652
653 for (const Vehicle * const v : this->vehicles) {
654 assert(v->owner == this->owner);
655
656 this_year += v->GetDisplayProfitThisYear();
657 last_year += v->GetDisplayProfitLastYear();
658 occupancy += v->trip_occupancy;
659 }
660
661 Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
662
663 DrawString(tr, TimerGameEconomy::UsingWallclockUnits() ? STR_GROUP_PROFIT_THIS_PERIOD : STR_GROUP_PROFIT_THIS_YEAR, TC_BLACK);
664 DrawString(tr, GetString(STR_JUST_CURRENCY_LONG, this_year), TC_BLACK, SA_RIGHT);
665
666 tr.top += GetCharacterHeight(FS_NORMAL);
667 DrawString(tr, TimerGameEconomy::UsingWallclockUnits() ? STR_GROUP_PROFIT_LAST_PERIOD : STR_GROUP_PROFIT_LAST_YEAR, TC_BLACK);
668 DrawString(tr, GetString(STR_JUST_CURRENCY_LONG, last_year), TC_BLACK, SA_RIGHT);
669
670 tr.top += GetCharacterHeight(FS_NORMAL);
671 DrawString(tr, STR_GROUP_OCCUPANCY, TC_BLACK);
672 const size_t vehicle_count = this->vehicles.size();
673 if (vehicle_count > 0) {
674 DrawString(tr, GetString(STR_GROUP_OCCUPANCY_VALUE, occupancy / vehicle_count), TC_BLACK, SA_RIGHT);
675 }
676
677 break;
678 }
679
680 case WID_GL_LIST_GROUP: {
681 Rect row = r.WithHeight(this->tiny_step_height);
682
683 auto [first, last] = this->group_sb->GetVisibleRangeIterators(this->groups);
684 for (auto it = first; it != last; ++it) {
685 const Group *g = it->group;
686 assert(g->owner == this->owner);
687
688 DrawGroupInfo(row, g->index, it->level_mask, it->indent, g->flags.Test(GroupFlag::ReplaceProtection), g->folded || (std::next(it) != std::end(this->groups) && std::next(it)->indent > it->indent));
689 row = row.Translate(0, this->tiny_step_height);
690 }
691 if ((uint)this->group_sb->GetPosition() + this->group_sb->GetCapacity() > this->groups.size()) {
692 DrawGroupInfo(row, NEW_GROUP);
693 }
694 break;

Callers

nothing calls this directly

Calls 15

GetCharacterHeightFunction · 0.85
GetColourGradientFunction · 0.85
ShrinkMethod · 0.80
WithHeightMethod · 0.80
TestMethod · 0.80
TranslateMethod · 0.80
GetPositionMethod · 0.80
DrawSortButtonStateMethod · 0.80
IsDescSortOrderMethod · 0.80
ToGroupIDMethod · 0.80
GetSingleVehicleMethod · 0.80

Tested by

no test coverage detected