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

Method DrawWidget

src/statusbar_gui.cpp:106–162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

104 }
105
106 void DrawWidget(const Rect &r, WidgetID widget) const override
107 {
108 Rect tr = r.Shrink(WidgetDimensions::scaled.framerect, RectPadding::zero);
109 tr.top = CentreBounds(r.top, r.bottom, GetCharacterHeight(FS_NORMAL));
110 switch (widget) {
111 case WID_S_LEFT:
112 /* Draw the date */
113 DrawString(tr, GetString(STR_JUST_DATE_LONG, TimerGameCalendar::date), TC_WHITE, SA_HOR_CENTER);
114 break;
115
116 case WID_S_RIGHT: {
117 if (_local_company == COMPANY_SPECTATOR) {
118 DrawString(tr, STR_STATUSBAR_SPECTATOR, TC_FROMSTRING, SA_HOR_CENTER);
119 } else if (_settings_game.difficulty.infinite_money) {
120 DrawString(tr, STR_STATUSBAR_INFINITE_MONEY, TC_FROMSTRING, SA_HOR_CENTER);
121 } else {
122 /* Draw company money, if any */
123 const Company *c = Company::GetIfValid(_local_company);
124 if (c != nullptr) {
125 DrawString(tr, GetString(STR_JUST_CURRENCY_LONG, c->money), TC_WHITE, SA_HOR_CENTER);
126 }
127 }
128 break;
129 }
130
131 case WID_S_MIDDLE:
132 /* Draw status bar */
133 if (this->saving) { // true when saving is active
134 DrawString(tr, STR_STATUSBAR_SAVING_GAME, TC_FROMSTRING, SA_HOR_CENTER | SA_VERT_CENTER);
135 } else if (_do_autosave) {
136 DrawString(tr, STR_STATUSBAR_AUTOSAVE, TC_FROMSTRING, SA_HOR_CENTER);
137 } else if (_pause_mode.Any()) {
138 StringID msg = _pause_mode.Test(PauseMode::LinkGraph) ? STR_STATUSBAR_PAUSED_LINK_GRAPH : STR_STATUSBAR_PAUSED;
139 DrawString(tr, msg, TC_FROMSTRING, SA_HOR_CENTER);
140 } else if (this->ticker_scroll < TICKER_STOP && GetStatusbarNews() != nullptr && !GetStatusbarNews()->headline.empty()) {
141 /* Draw the scrolling news text */
142 if (!DrawScrollingStatusText(*GetStatusbarNews(), ScaleGUITrad(this->ticker_scroll), tr.left, tr.right, tr.top, tr.bottom)) {
143 InvalidateWindowData(WC_STATUS_BAR, 0, SBI_NEWS_DELETED);
144 if (Company::IsValidID(_local_company)) {
145 /* This is the default text */
146 DrawString(tr, GetString(STR_STATUSBAR_COMPANY_NAME, _local_company), TC_FROMSTRING, SA_HOR_CENTER);
147 }
148 }
149 } else {
150 if (Company::IsValidID(_local_company)) {
151 /* This is the default text */
152 DrawString(tr, GetString(STR_STATUSBAR_COMPANY_NAME, _local_company), TC_FROMSTRING, SA_HOR_CENTER);
153 }
154 }
155
156 if (!this->reminder_timeout.HasFired()) {
157 Dimension icon_size = GetSpriteSize(SPR_UNREAD_NEWS);
158 DrawSprite(SPR_UNREAD_NEWS, PAL_NONE, tr.right - icon_size.width, CentreBounds(r.top, r.bottom, icon_size.height));
159 }
160 break;
161 }
162 }
163

Callers

nothing calls this directly

Calls 15

CentreBoundsFunction · 0.85
GetCharacterHeightFunction · 0.85
GetStatusbarNewsFunction · 0.85
DrawScrollingStatusTextFunction · 0.85
GetSpriteSizeFunction · 0.85
DrawSpriteFunction · 0.85
ShrinkMethod · 0.80
AnyMethod · 0.80
TestMethod · 0.80
HasFiredMethod · 0.80
DrawStringFunction · 0.70
GetStringFunction · 0.70

Tested by

no test coverage detected