| 1524 | } |
| 1525 | |
| 1526 | void OnInit() override |
| 1527 | { |
| 1528 | uint min_width = 0; |
| 1529 | this->min_number_of_columns = INDUSTRY_MIN_NUMBER_OF_COLUMNS; |
| 1530 | this->min_number_of_fixed_rows = lengthof(_linkstat_colours_in_legenda); |
| 1531 | for (uint i = 0; i < lengthof(_legend_table); i++) { |
| 1532 | uint height = 0; |
| 1533 | uint num_columns = 1; |
| 1534 | for (const LegendAndColour *tbl = _legend_table[i]; !tbl->end; ++tbl) { |
| 1535 | std::string str; |
| 1536 | if (i == SMT_INDUSTRY) { |
| 1537 | str = GetString(STR_SMALLMAP_INDUSTRY, tbl->legend, IndustryPool::MAX_SIZE); |
| 1538 | } else if (i == SMT_LINKSTATS) { |
| 1539 | str = GetString(STR_SMALLMAP_LINKSTATS, tbl->legend); |
| 1540 | } else if (i == SMT_OWNER) { |
| 1541 | if (tbl->company != CompanyID::Invalid()) { |
| 1542 | if (!Company::IsValidID(tbl->company)) { |
| 1543 | /* Rebuild the owner legend. */ |
| 1544 | BuildOwnerLegend(); |
| 1545 | this->OnInit(); |
| 1546 | return; |
| 1547 | } |
| 1548 | /* Non-fixed legend entries for the owner view. */ |
| 1549 | str = GetString(STR_SMALLMAP_COMPANY, tbl->company); |
| 1550 | } else { |
| 1551 | str = GetString(tbl->legend); |
| 1552 | } |
| 1553 | } else { |
| 1554 | if (tbl->col_break) { |
| 1555 | this->min_number_of_fixed_rows = std::max(this->min_number_of_fixed_rows, height); |
| 1556 | height = 0; |
| 1557 | num_columns++; |
| 1558 | } |
| 1559 | height++; |
| 1560 | if (i == SMT_CONTOUR) { |
| 1561 | str = GetString(tbl->legend, tbl->height * TILE_HEIGHT_STEP); |
| 1562 | } else { |
| 1563 | str = GetString(tbl->legend); |
| 1564 | } |
| 1565 | } |
| 1566 | min_width = std::max(GetStringBoundingBox(str).width, min_width); |
| 1567 | } |
| 1568 | this->min_number_of_fixed_rows = std::max(this->min_number_of_fixed_rows, height); |
| 1569 | this->min_number_of_columns = std::max(this->min_number_of_columns, num_columns); |
| 1570 | } |
| 1571 | |
| 1572 | /* Width of the legend blob. */ |
| 1573 | this->legend_width = GetCharacterHeight(FS_SMALL) * 9 / 6; |
| 1574 | |
| 1575 | /* The width of a column is the minimum width of all texts + the size of the blob + some spacing */ |
| 1576 | this->column_width = min_width + WidgetDimensions::scaled.hsep_normal + this->legend_width + WidgetDimensions::scaled.framerect.Horizontal(); |
| 1577 | |
| 1578 | /* Cached string widths of industry names in the smallmap. Calculation is deferred to DrawIndustryNames(). */ |
| 1579 | std::fill(std::begin(_industry_to_name_string_width), std::end(_industry_to_name_string_width), 0); |
| 1580 | } |
| 1581 | |
| 1582 | void OnPaint() override |
| 1583 | { |
nothing calls this directly
no test coverage detected