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

Method DrawWidget

src/town_gui.cpp:844–886  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

842 }
843
844 void DrawWidget(const Rect &r, WidgetID widget) const override
845 {
846 switch (widget) {
847 case WID_TD_SORT_ORDER:
848 this->DrawSortButtonState(widget, this->towns.IsDescSortOrder() ? SBS_DOWN : SBS_UP);
849 break;
850
851 case WID_TD_LIST: {
852 Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
853 if (this->towns.empty()) { // No towns available.
854 DrawString(tr, STR_TOWN_DIRECTORY_NONE);
855 break;
856 }
857
858 /* At least one town available. */
859 bool rtl = _current_text_dir == TD_RTL;
860 Dimension icon_size = GetSpriteSize(SPR_TOWN_RATING_GOOD);
861 int icon_x = tr.WithWidth(icon_size.width, rtl).left;
862 tr = tr.Indent(icon_size.width + WidgetDimensions::scaled.hsep_normal, rtl);
863
864 auto [first, last] = this->vscroll->GetVisibleRangeIterators(this->towns);
865 for (auto it = first; it != last; ++it) {
866 const Town *t = *it;
867 assert(t->xy != INVALID_TILE);
868
869 /* Draw rating icon. */
870 if (_game_mode == GM_EDITOR || !t->have_ratings.Test(_local_company)) {
871 DrawSprite(SPR_TOWN_RATING_NA, PAL_NONE, icon_x, tr.top + (this->resize.step_height - icon_size.height) / 2);
872 } else {
873 SpriteID icon = SPR_TOWN_RATING_APPALLING;
874 if (t->ratings[_local_company] > RATING_VERYPOOR) icon = SPR_TOWN_RATING_MEDIOCRE;
875 if (t->ratings[_local_company] > RATING_GOOD) icon = SPR_TOWN_RATING_GOOD;
876 DrawSprite(icon, PAL_NONE, icon_x, tr.top + (this->resize.step_height - icon_size.height) / 2);
877 }
878
879 DrawString(tr.left, tr.right, tr.top + (this->resize.step_height - GetCharacterHeight(FS_NORMAL)) / 2, GetTownString(t, t->cache.population));
880
881 tr.top += this->resize.step_height;
882 }
883 break;
884 }
885 }
886 }
887
888 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
889 {

Callers

nothing calls this directly

Calls 12

GetSpriteSizeFunction · 0.85
DrawSpriteFunction · 0.85
GetCharacterHeightFunction · 0.85
DrawSortButtonStateMethod · 0.80
IsDescSortOrderMethod · 0.80
ShrinkMethod · 0.80
WithWidthMethod · 0.80
IndentMethod · 0.80
TestMethod · 0.80
DrawStringFunction · 0.70
emptyMethod · 0.45

Tested by

no test coverage detected