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

Function DrawStringMultiLine

src/gfx.cpp:785–829  ·  view source on GitHub ↗

* Draw string, possibly over multiple lines. * * @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 bottom The bottom most position to draw on. * @param str String to draw. * @param colour Colour used for drawing the string, for details see _string_colourmap in * ta

Source from the content-addressed store, hash-verified

783 * @return If \a align is #SA_BOTTOM, the top to where we have written, else the bottom to where we have written.
784 */
785int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
786{
787 int maxw = right - left + 1;
788 int maxh = bottom - top + 1;
789
790 /* It makes no sense to even try if it can't be drawn anyway, or
791 * do we really want to support fonts of 0 or less pixels high? */
792 if (maxh <= 0) return top;
793
794 Layouter layout(str, maxw, fontsize);
795 int total_height = layout.GetBounds().height;
796 int y;
797 switch (align & SA_VERT_MASK) {
798 case SA_TOP:
799 y = top;
800 break;
801
802 case SA_VERT_CENTER:
803 y = RoundDivSU(bottom + top - total_height, 2);
804 break;
805
806 case SA_BOTTOM:
807 y = bottom - total_height;
808 break;
809
810 default: NOT_REACHED();
811 }
812
813 int last_line = top;
814 int first_line = bottom;
815
816 for (const auto &line : layout) {
817
818 int line_height = line->GetLeading();
819 if (y >= top && y + line_height - 1 <= bottom) {
820 last_line = y + line_height;
821 if (first_line > y) first_line = y;
822
823 DrawLayoutLine(*line, y, left, right, align, underline, false, colour);
824 }
825 y += line_height;
826 }
827
828 return ((align & SA_VERT_MASK) == SA_BOTTOM) ? first_line : last_line;
829}
830
831/**
832 * Draw string, possibly over multiple lines.

Callers 15

DrawWidgetMethod · 0.70
DrawDetailsMethod · 0.70
OnPaintMethod · 0.70
DrawWidgetMethod · 0.70
ShowNewGRFInfoFunction · 0.70
DrawWidgetMethod · 0.70
DrawWidgetMethod · 0.70
DrawWidgetMethod · 0.70
DrawMethod · 0.70
DrawMethod · 0.70
DrawWidgetMethod · 0.70

Calls 6

RoundDivSUFunction · 0.85
NOT_REACHEDFunction · 0.85
DrawLayoutLineFunction · 0.85
GetStringFunction · 0.70
GetBoundsMethod · 0.45
GetLeadingMethod · 0.45

Tested by

no test coverage detected