| 1596 | } |
| 1597 | |
| 1598 | void DrawWidget(const Rect &r, WidgetID widget) const override |
| 1599 | { |
| 1600 | switch (widget) { |
| 1601 | case WID_SM_MAP: { |
| 1602 | Rect ir = r.Shrink(WidgetDimensions::scaled.bevel); |
| 1603 | DrawPixelInfo new_dpi; |
| 1604 | if (!FillDrawPixelInfo(&new_dpi, ir)) return; |
| 1605 | this->DrawSmallMap(&new_dpi); |
| 1606 | break; |
| 1607 | } |
| 1608 | |
| 1609 | case WID_SM_LEGEND: { |
| 1610 | uint columns = this->GetNumberColumnsLegend(r.Width()); |
| 1611 | uint number_of_rows = this->GetNumberRowsLegend(columns); |
| 1612 | bool rtl = _current_text_dir == TD_RTL; |
| 1613 | uint i = 0; // Row counter for industry legend. |
| 1614 | uint row_height = GetCharacterHeight(FS_SMALL); |
| 1615 | int padding = ScaleGUITrad(1); |
| 1616 | |
| 1617 | Rect origin = r.WithWidth(this->column_width, rtl).Shrink(WidgetDimensions::scaled.framerect).WithHeight(row_height); |
| 1618 | Rect text = origin.Indent(this->legend_width + WidgetDimensions::scaled.hsep_normal, rtl); |
| 1619 | Rect icon = origin.WithWidth(this->legend_width, rtl).Shrink(0, padding, 0, 0); |
| 1620 | |
| 1621 | StringID string = STR_NULL; |
| 1622 | switch (this->map_type) { |
| 1623 | case SMT_INDUSTRY: |
| 1624 | string = STR_SMALLMAP_INDUSTRY; |
| 1625 | break; |
| 1626 | case SMT_LINKSTATS: |
| 1627 | string = STR_SMALLMAP_LINKSTATS; |
| 1628 | break; |
| 1629 | case SMT_OWNER: |
| 1630 | string = STR_SMALLMAP_COMPANY; |
| 1631 | break; |
| 1632 | default: |
| 1633 | break; |
| 1634 | } |
| 1635 | |
| 1636 | for (const LegendAndColour *tbl = _legend_table[this->map_type]; !tbl->end; ++tbl) { |
| 1637 | if (tbl->col_break || ((this->map_type == SMT_INDUSTRY || this->map_type == SMT_OWNER || this->map_type == SMT_LINKSTATS) && i++ >= number_of_rows)) { |
| 1638 | /* Column break needed, continue at top, COLUMN_WIDTH pixels |
| 1639 | * (one "row") to the right. */ |
| 1640 | int x = rtl ? -(int)this->column_width : this->column_width; |
| 1641 | int y = origin.top - text.top; |
| 1642 | text = text.Translate(x, y); |
| 1643 | icon = icon.Translate(x, y); |
| 1644 | i = 1; |
| 1645 | } |
| 1646 | |
| 1647 | PixelColour legend_colour = tbl->colour; |
| 1648 | |
| 1649 | std::array<StringParameter, 2> params{}; |
| 1650 | switch (this->map_type) { |
| 1651 | case SMT_INDUSTRY: |
| 1652 | /* Industry name must be formatted, since it's not in tiny font in the specs. |
| 1653 | * So, draw with a parameter and use the STR_SMALLMAP_INDUSTRY string, which is tiny font */ |
| 1654 | params[0] = tbl->legend; |
| 1655 | params[1] = Industry::GetIndustryTypeCount(tbl->type); |
nothing calls this directly
no test coverage detected