* Adds industry names to the smallmap. * @param dpi the part of the smallmap to be drawn into */
| 1009 | * @param dpi the part of the smallmap to be drawn into |
| 1010 | */ |
| 1011 | void DrawIndustryNames(const DrawPixelInfo *dpi, const int vertical_padding) const |
| 1012 | { |
| 1013 | if (this->map_type != SMT_INDUSTRY) return; |
| 1014 | |
| 1015 | for (const Industry *i : Industry::Iterate()) { |
| 1016 | const LegendAndColour &tbl = _legend_from_industries[_industry_to_list_pos[i->type]]; |
| 1017 | if (!tbl.show_on_map) continue; |
| 1018 | |
| 1019 | /* Industry names blink together with their blobs in the smallmap. */ |
| 1020 | const bool is_blinking = i->type == _smallmap_industry_highlight && !_smallmap_industry_highlight_state; |
| 1021 | if (is_blinking) continue; |
| 1022 | |
| 1023 | if (_industry_to_name_string_width[i->type] == 0) { |
| 1024 | _industry_to_name_string_width[i->type] = GetStringBoundingBox(tbl.legend, FS_SMALL).width; |
| 1025 | } |
| 1026 | const uint16_t &legend_text_width = _industry_to_name_string_width[i->type]; |
| 1027 | |
| 1028 | /* Remap the industry coordinate */ |
| 1029 | const TileIndex &tile = i->location.GetCenterTile(); |
| 1030 | const Point pt = this->RemapTile(TileX(tile), TileY(tile)); |
| 1031 | const int x = pt.x - this->subscroll - (legend_text_width / 2); |
| 1032 | const int y = pt.y + vertical_padding; |
| 1033 | |
| 1034 | /* Check if the industry name is within bounds */ |
| 1035 | if (x + legend_text_width > dpi->left && |
| 1036 | x < dpi->left + dpi->width && |
| 1037 | y + GetCharacterHeight(FS_SMALL) > dpi->top && |
| 1038 | y < dpi->top + dpi->height) { |
| 1039 | |
| 1040 | /* And draw it. */ |
| 1041 | DrawString(x, x + legend_text_width, y, tbl.legend, TC_WHITE, SA_LEFT, false, FS_SMALL); |
| 1042 | } |
| 1043 | } |
| 1044 | } |
| 1045 | |
| 1046 | /** |
| 1047 | * Draws the small map. |
no test coverage detected