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

Function DrawString

src/gfx.cpp:668–685  ·  view source on GitHub ↗

* 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

Source from the content-addressed store, hash-verified

666 * In case of right alignment the left most pixel we have drawn to.
667 */
668int 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

Callers 15

DrawWidgetMethod · 0.70
DrawSettingMethod · 0.70
DrawWidgetMethod · 0.70
DrawWidgetMethod · 0.70
DrawDetailsMethod · 0.70
DrawWidgetMethod · 0.70
OnPaintMethod · 0.70
DrawListColumnMethod · 0.70
DrawWidgetMethod · 0.70
DrawWidgetMethod · 0.70
DrawWidgetMethod · 0.70
DrawWidgetMethod · 0.70

Calls 4

GetCharacterHeightFunction · 0.85
DrawLayoutLineFunction · 0.85
GetStringFunction · 0.70
emptyMethod · 0.45

Tested by

no test coverage detected