MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / drawStringCentredWrapped

Function drawStringCentredWrapped

src/OpenLoco/src/Graphics/TextRenderer.cpp:689–738  ·  view source on GitHub ↗

* 0x00494ECF * * @param rt @ * @param origin {x @ , y @ } * @param width @ * @param colour @ * @param stringId @ * @param args @ * returns width @ */

Source from the content-addressed store, hash-verified

687 * returns width @<ax>
688 */
689 static Ui::Point drawStringCentredWrapped(
690 TextDrawingState& drawState,
691 DrawingContext& ctx,
692 const RenderTarget& rt,
693 Ui::Point origin,
694 uint16_t width,
695 AdvancedColour colour,
696 StringId stringId,
697 FormatArgumentsView args)
698 {
699 // Setup the text colours (FIXME: This should be a separate function)
700 auto curDrawState = drawState;
701 char empty[1] = "";
702 drawString(drawState, ctx, rt, origin, colour, empty);
703 drawState = curDrawState;
704
705 char buffer[512];
706 StringManager::formatString(buffer, std::size(buffer), stringId, args);
707
708 auto wrapResult = wrapString(drawState.font, buffer, width);
709 auto breakCount = wrapResult.second + 1;
710
711 // wrapString might change the font due to formatting codes
712 uint16_t lineHeight = getLineHeight(drawState.font); // _112D404
713
714 Ui::Point basePoint = origin;
715 basePoint.y -= (lineHeight / 2) * (breakCount - 1);
716
717 const char* ptr = buffer;
718 uint16_t lineWidth{};
719 uint16_t maxLineWidth{};
720
721 for (auto i = 0; ptr != nullptr && i < breakCount; i++)
722 {
723 lineWidth = getStringWidth(drawState.font, ptr);
724 maxLineWidth = std::max(lineWidth, maxLineWidth);
725
726 auto point = basePoint;
727 point.x -= lineWidth / 2;
728
729 drawString(drawState, ctx, rt, point, AdvancedColour::FE(), const_cast<char*>(ptr));
730 ptr = advanceToNextLineWrapped(ptr);
731
732 basePoint.y += lineHeight;
733 }
734
735 basePoint.x -= maxLineWidth / 2;
736
737 return basePoint;
738 }
739
740 // 0x00494E33
741 // al: colour

Callers 1

Calls 6

drawStringFunction · 0.85
formatStringFunction · 0.85
wrapStringFunction · 0.85
getLineHeightFunction · 0.85
getStringWidthFunction · 0.85
advanceToNextLineWrappedFunction · 0.85

Tested by

no test coverage detected