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

Method DrawWidget

src/industry_gui.cpp:504–597  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

502 }
503
504 void DrawWidget(const Rect &r, WidgetID widget) const override
505 {
506 switch (widget) {
507 case WID_DPI_MATRIX_WIDGET: {
508 bool rtl = _current_text_dir == TD_RTL;
509 Rect text = r.WithHeight(this->resize.step_height).Shrink(WidgetDimensions::scaled.matrix);
510 Rect icon = text.WithWidth(this->legend.width, rtl);
511 text = text.Indent(this->legend.width + WidgetDimensions::scaled.hsep_wide, rtl);
512
513 /* Vertical offset for legend icon. */
514 icon.top = r.top + (this->resize.step_height - this->legend.height + 1) / 2;
515 icon.bottom = icon.top + this->legend.height - 1;
516
517 auto badge_column_widths = badge_classes.GetColumnWidths();
518
519 auto [first, last] = this->vscroll->GetVisibleRangeIterators(this->list);
520 for (auto it = first; it != last; ++it) {
521 IndustryType type = *it;
522 bool selected = this->selected_type == type;
523 const IndustrySpec *indsp = GetIndustrySpec(type);
524
525 Rect tr = text;
526 if (badge_column_widths.size() >= 1 && badge_column_widths[0] > 0) {
527 DrawBadgeColumn(tr.WithWidth(badge_column_widths[0], rtl), 0, this->badge_classes, indsp->badges, GSF_INDUSTRIES, std::nullopt, PAL_NONE);
528 tr = tr.Indent(badge_column_widths[0], rtl);
529 }
530 if (badge_column_widths.size() >= 2 && badge_column_widths[1] > 0) {
531 DrawBadgeColumn(tr.WithWidth(badge_column_widths[1], !rtl), 0, this->badge_classes, indsp->badges, GSF_INDUSTRIES, std::nullopt, PAL_NONE);
532 tr = tr.Indent(badge_column_widths[1], !rtl);
533 }
534
535 /* Draw the name of the industry in white is selected, otherwise, in orange */
536 DrawString(tr, indsp->name, selected ? TC_WHITE : TC_ORANGE);
537 GfxFillRect(icon, selected ? PC_WHITE : PC_BLACK);
538 GfxFillRect(icon.Shrink(WidgetDimensions::scaled.bevel), indsp->map_colour);
539 DrawString(tr, GetString(STR_JUST_COMMA, Industry::GetIndustryTypeCount(type)), TC_BLACK, SA_RIGHT, false, FS_SMALL);
540
541 text = text.Translate(0, this->resize.step_height);
542 icon = icon.Translate(0, this->resize.step_height);
543 }
544 break;
545 }
546
547 case WID_DPI_INFOPANEL: {
548 Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
549
550 if (this->selected_type == IT_INVALID) {
551 DrawStringMultiLine(ir, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_TOOLTIP);
552 break;
553 }
554
555 const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
556
557 if (_game_mode != GM_EDITOR) {
558 DrawString(ir, GetString(STR_FUND_INDUSTRY_INDUSTRY_BUILD_COST, indsp->GetConstructionCost()));
559 ir.top += GetCharacterHeight(FS_NORMAL);
560 }
561

Callers

nothing calls this directly

Calls 15

MakeCargoListStringMethod · 0.95
GetIndustrySpecFunction · 0.85
DrawBadgeColumnFunction · 0.85
GetCharacterHeightFunction · 0.85
GetAllCargoSuffixesFunction · 0.85
DrawBadgeNameListFunction · 0.85
GetIndustryCallbackFunction · 0.85
ShrinkMethod · 0.80
WithHeightMethod · 0.80
WithWidthMethod · 0.80

Tested by

no test coverage detected