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

Method DrawWidget

src/dropdown.cpp:259–293  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

257 }
258
259 void DrawWidget(const Rect &r, WidgetID widget) const override
260 {
261 if (widget != WID_DM_ITEMS) return;
262
263 Colours colour = this->GetWidget<NWidgetCore>(widget)->colour;
264
265 Rect ir = r.Shrink(WidgetDimensions::scaled.dropdownlist);
266
267 /* Setup a clipping rectangle... */
268 DrawPixelInfo tmp_dpi;
269 if (!FillDrawPixelInfo(&tmp_dpi, ir)) return;
270 /* ...but keep coordinates relative to the window. */
271 tmp_dpi.left += ir.left;
272 tmp_dpi.top += ir.top;
273 AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
274
275 int y = -this->vscroll->GetPosition();
276 int y_end = ir.Height();
277
278 for (const auto &item : this->list) {
279 int item_height = item->Height();
280
281 /* Skip items that are scrolled up */
282 if (y > y_end) break;
283 if (y > -item_height) {
284 Rect full = ir.Translate(0, y).WithHeight(item_height);
285
286 bool selected = (this->selected_result == item->result) && item->Selectable() && this->selected_click_result < 0;
287 if (selected) GfxFillRect(full, PC_BLACK);
288
289 item->Draw(full, full.Shrink(WidgetDimensions::scaled.dropdowntext, RectPadding::zero), selected, selected ? this->selected_click_result : -1, colour);
290 }
291 y += item_height;
292 }
293 }
294
295 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
296 {

Callers

nothing calls this directly

Calls 9

ShrinkMethod · 0.80
GetPositionMethod · 0.80
WithHeightMethod · 0.80
TranslateMethod · 0.80
FillDrawPixelInfoFunction · 0.70
GfxFillRectFunction · 0.70
HeightMethod · 0.45
SelectableMethod · 0.45
DrawMethod · 0.45

Tested by

no test coverage detected