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

Method DrawWidget

src/fios_gui.cpp:489–544  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

487 }
488
489 void DrawWidget(const Rect &r, WidgetID widget) const override
490 {
491 switch (widget) {
492 case WID_SL_SORT_BYNAME:
493 case WID_SL_SORT_BYDATE:
494 if (((_savegame_sort_order & SORT_BY_NAME) != 0) == (widget == WID_SL_SORT_BYNAME)) {
495 this->DrawSortButtonState(widget, _savegame_sort_order & SORT_DESCENDING ? SBS_DOWN : SBS_UP);
496 }
497 break;
498
499 case WID_SL_BACKGROUND: {
500 static std::string path;
501 static std::optional<uint64_t> free_space = std::nullopt;
502
503 if (_fios_path_changed) {
504 path = FiosGetCurrentPath();
505 free_space = FiosGetDiskFreeSpace(path);
506 _fios_path_changed = false;
507 }
508
509 Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
510
511 if (free_space.has_value()) {
512 DrawString(ir.left, ir.right, ir.top + GetCharacterHeight(FS_NORMAL), GetString(STR_SAVELOAD_BYTES_FREE, free_space.value()));
513 } else {
514 DrawString(ir.left, ir.right, ir.top + GetCharacterHeight(FS_NORMAL), STR_ERROR_UNABLE_TO_READ_DRIVE);
515 }
516 DrawString(ir.left, ir.right, ir.top, path, TC_BLACK);
517 break;
518 }
519
520 case WID_SL_DRIVES_DIRECTORIES_LIST: {
521 const Rect br = r.Shrink(WidgetDimensions::scaled.bevel);
522 GfxFillRect(br, PC_BLACK);
523
524 Rect tr = r.Shrink(WidgetDimensions::scaled.inset).WithHeight(this->resize.step_height);
525 auto [first, last] = this->vscroll->GetVisibleRangeIterators(this->display_list);
526 for (auto it = first; it != last; ++it) {
527 const FiosItem *item = *it;
528
529 if (item == this->selected) {
530 GfxFillRect(br.WithY(tr), PC_DARK_BLUE);
531 } else if (item == this->highlighted) {
532 GfxFillRect(br.WithY(tr), PC_VERY_DARK_BLUE);
533 }
534 DrawString(tr, item->title.GetDecodedString(), _fios_colours[item->type.detailed]);
535 tr = tr.Translate(0, this->resize.step_height);
536 }
537 break;
538 }
539
540 case WID_SL_DETAILS:
541 this->DrawDetails(r);
542 break;
543 }
544 }
545
546 void DrawDetails(const Rect &r) const

Callers

nothing calls this directly

Calls 15

DrawDetailsMethod · 0.95
FiosGetCurrentPathFunction · 0.85
GetCharacterHeightFunction · 0.85
DrawSortButtonStateMethod · 0.80
ShrinkMethod · 0.80
WithHeightMethod · 0.80
WithYMethod · 0.80
GetDecodedStringMethod · 0.80
TranslateMethod · 0.80
DrawStringFunction · 0.70
GetStringFunction · 0.70

Tested by

no test coverage detected