* @todo replace Rectangle with cropped Surface */
| 737 | * @todo replace Rectangle with cropped Surface |
| 738 | */ |
| 739 | uint32_t DrawString(const Surface &out, string_view text, const Rectangle &rect, TextRenderOptions opts) |
| 740 | { |
| 741 | const GameFontTables size = GetFontSizeFromUiFlags(opts.flags); |
| 742 | const text_color color = GetColorFromFlags(opts.flags); |
| 743 | |
| 744 | int charactersInLine = 0; |
| 745 | int lineWidth = 0; |
| 746 | if (HasAnyOf(opts.flags, (UiFlags::AlignCenter | UiFlags::AlignRight | UiFlags::KerningFitSpacing))) |
| 747 | lineWidth = GetLineWidth(text, size, opts.spacing, &charactersInLine); |
| 748 | |
| 749 | Point characterPosition { GetLineStartX(opts.flags, rect, lineWidth), rect.position.y }; |
| 750 | const int initialX = characterPosition.x; |
| 751 | |
| 752 | const int rightMargin = rect.position.x + rect.size.width; |
| 753 | const int bottomMargin = rect.size.height != 0 ? std::min(rect.position.y + rect.size.height + BaseLineOffset[size], out.h()) : out.h(); |
| 754 | |
| 755 | if (opts.lineHeight == -1) |
| 756 | opts.lineHeight = GetLineHeight(text, size); |
| 757 | |
| 758 | if (HasAnyOf(opts.flags, UiFlags::VerticalCenter)) { |
| 759 | const int textHeight = static_cast<int>((c_count(text, '\n') + 1) * opts.lineHeight); |
| 760 | characterPosition.y += std::max(0, (rect.size.height - textHeight) / 2); |
| 761 | } |
| 762 | |
| 763 | characterPosition.y += BaseLineOffset[size]; |
| 764 | |
| 765 | const bool outlined = HasAnyOf(opts.flags, UiFlags::Outlined); |
| 766 | |
| 767 | const Surface clippedOut = ClipSurface(out, rect); |
| 768 | |
| 769 | // Only draw the PentaCursor if the cursor is not at the end. |
| 770 | if (HasAnyOf(opts.flags, UiFlags::PentaCursor) && static_cast<size_t>(opts.cursorPosition) == text.size()) { |
| 771 | opts.cursorPosition = -1; |
| 772 | } |
| 773 | |
| 774 | const uint32_t bytesDrawn = DoDrawString(clippedOut, text, rect, characterPosition, |
| 775 | lineWidth, charactersInLine, rightMargin, bottomMargin, size, color, outlined, opts); |
| 776 | |
| 777 | if (HasAnyOf(opts.flags, UiFlags::PentaCursor)) { |
| 778 | const ClxSprite sprite = (*pSPentSpn2Cels)[PentSpn2Spin()]; |
| 779 | MaybeWrap(characterPosition, sprite.width(), rightMargin, initialX, opts.lineHeight); |
| 780 | ClxDraw(clippedOut, characterPosition + Displacement { 0, opts.lineHeight - BaseLineOffset[size] }, sprite); |
| 781 | } |
| 782 | |
| 783 | return bytesDrawn; |
| 784 | } |
| 785 | |
| 786 | void DrawStringWithColors(const Surface &out, string_view fmt, DrawStringFormatArg *args, std::size_t argsLen, const Rectangle &rect, TextRenderOptions opts) |
| 787 | { |
nothing calls this directly
no test coverage detected