* Draw string, possibly truncated to make it fit in its allocated space * * @param left The left most position to draw on. * @param right The right most position to draw on. * @param top The top most position to draw on. * @param str String to draw. * @param colour Colour used for drawing the string, for details see _string_colourmap in * table/palettes.h or docs/ottd
| 666 | * In case of right alignment the left most pixel we have drawn to. |
| 667 | */ |
| 668 | int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize) |
| 669 | { |
| 670 | /* The string may contain control chars to change the font, just use the biggest font for clipping. */ |
| 671 | int max_height = std::max({GetCharacterHeight(FS_SMALL), GetCharacterHeight(FS_NORMAL), GetCharacterHeight(FS_LARGE), GetCharacterHeight(FS_MONO)}); |
| 672 | |
| 673 | /* Funny glyphs may extent outside the usual bounds, so relax the clipping somewhat. */ |
| 674 | int extra = max_height / 2; |
| 675 | |
| 676 | if (_cur_dpi->top + _cur_dpi->height + extra < top || _cur_dpi->top > top + max_height + extra || |
| 677 | _cur_dpi->left + _cur_dpi->width + extra < left || _cur_dpi->left > right + extra) { |
| 678 | return 0; |
| 679 | } |
| 680 | |
| 681 | Layouter layout(str, INT32_MAX, fontsize); |
| 682 | if (layout.empty()) return 0; |
| 683 | |
| 684 | return DrawLayoutLine(*layout.front(), top, left, right, align, underline, true, colour); |
| 685 | } |
| 686 | |
| 687 | /** |
| 688 | * Draw string, possibly truncated to make it fit in its allocated space |
no test coverage detected