From cb40775d6d2372e4c3eb85cc61724ea61070ded1 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 22 Mar 2026 18:48:43 +0100 Subject: [PATCH] Replace DrawTextNoFormatting() with a flag --- src/openrct2-ui/interface/InGameConsole.cpp | 13 ++++++++----- src/openrct2-ui/interface/Widget.cpp | 5 +++-- src/openrct2-ui/windows/TextInput.cpp | 4 +++- src/openrct2/drawing/Text.cpp | 9 ++------- src/openrct2/drawing/Text.h | 4 +--- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/openrct2-ui/interface/InGameConsole.cpp b/src/openrct2-ui/interface/InGameConsole.cpp index b5b6b7d7c7..2be54719b6 100644 --- a/src/openrct2-ui/interface/InGameConsole.cpp +++ b/src/openrct2-ui/interface/InGameConsole.cpp @@ -344,18 +344,21 @@ void InGameConsole::Draw(RenderTarget& rt) const if (textColour.colour == OpenRCT2::Drawing::Colour::black) { DrawTextBasic(rt, screenCoords, "{BLACK}", { textColour, style }); - DrawTextNoFormatting(rt, screenCoords, _consoleLines[index].first, { kColourNull, style }); + DrawTextBasic( + rt, screenCoords, _consoleLines[index].first, { kColourNull, style, { TextPaintFlag::noFormatting } }); } else { - DrawTextNoFormatting(rt, screenCoords, _consoleLines[index].first, { textColour, style }); + DrawTextBasic( + rt, screenCoords, _consoleLines[index].first, { textColour, style, { TextPaintFlag::noFormatting } }); } } else { std::string lineColour = FormatTokenToStringWithBraces(_consoleLines[index].second); DrawTextBasic(rt, screenCoords, lineColour, { textColour, style }); - DrawTextNoFormatting(rt, screenCoords, _consoleLines[index].first, { OpenRCT2::Drawing::kColourNull, style }); + DrawTextBasic( + rt, screenCoords, _consoleLines[index].first, { kColourNull, style, { TextPaintFlag::noFormatting } }); } screenCoords.y += lineHeight; @@ -367,11 +370,11 @@ void InGameConsole::Draw(RenderTarget& rt) const if (textColour.colour == OpenRCT2::Drawing::Colour::black) { DrawTextBasic(rt, screenCoords, "{BLACK}", { textColour, style }); - DrawTextNoFormatting(rt, screenCoords, _consoleCurrentLine, { OpenRCT2::Drawing::kColourNull, style }); + DrawTextBasic(rt, screenCoords, _consoleCurrentLine, { kColourNull, style, { TextPaintFlag::noFormatting } }); } else { - DrawTextNoFormatting(rt, screenCoords, _consoleCurrentLine, { textColour, style }); + DrawTextBasic(rt, screenCoords, _consoleCurrentLine, { textColour, style, { TextPaintFlag::noFormatting } }); } // Draw caret diff --git a/src/openrct2-ui/interface/Widget.cpp b/src/openrct2-ui/interface/Widget.cpp index 7b42ee80ef..1ca328b370 100644 --- a/src/openrct2-ui/interface/Widget.cpp +++ b/src/openrct2-ui/interface/Widget.cpp @@ -1196,7 +1196,8 @@ namespace OpenRCT2::Ui { u8string wrappedString; wrapString(widget.string, bottomRight.x - topLeft.x - 5, FontStyle::medium, &wrappedString, nullptr); - DrawTextNoFormatting(rt, { topLeft.x + 2, topLeft.y }, wrappedString, { w.colours[1] }); + DrawTextBasic( + rt, { topLeft.x + 2, topLeft.y }, wrappedString, { w.colours[1], { TextPaintFlag::noFormatting } }); } return; } @@ -1206,7 +1207,7 @@ namespace OpenRCT2::Ui u8string wrappedString; wrapString(*textInput->Buffer, bottomRight.x - topLeft.x - 5 - 6, FontStyle::medium, &wrappedString, nullptr); - DrawTextNoFormatting(rt, { topLeft.x + 2, topLeft.y }, wrappedString, { w.colours[1] }); + DrawTextBasic(rt, { topLeft.x + 2, topLeft.y }, wrappedString, { w.colours[1], { TextPaintFlag::noFormatting } }); // Make a trimmed view of the string for measuring the width. int32_t curX = topLeft.x diff --git a/src/openrct2-ui/windows/TextInput.cpp b/src/openrct2-ui/windows/TextInput.cpp index 86f078e748..f1fa42f835 100644 --- a/src/openrct2-ui/windows/TextInput.cpp +++ b/src/openrct2-ui/windows/TextInput.cpp @@ -245,7 +245,9 @@ namespace OpenRCT2::Ui::Windows for (int32_t line = 0; line <= no_lines; line++) { screenCoords.x = windowPos.x + 12; - DrawTextNoFormatting(rt, screenCoords, wrapPointer, { colours[1], FontStyle::medium, TextAlignment::left }); + DrawTextBasic( + rt, screenCoords, wrapPointer, + { colours[1], FontStyle::medium, { TextPaintFlag::noFormatting }, TextAlignment::left }); size_t string_length = GetStringSize(wrapPointer) - 1; if (!cur_drawn && (textInput->SelectionStart <= char_count + string_length)) diff --git a/src/openrct2/drawing/Text.cpp b/src/openrct2/drawing/Text.cpp index 43c45260b7..c6393cf71f 100644 --- a/src/openrct2/drawing/Text.cpp +++ b/src/openrct2/drawing/Text.cpp @@ -80,9 +80,9 @@ public: } }; -static void DrawText( - RenderTarget& rt, const ScreenCoordsXY& coords, u8string_view text, const TextPaint& paint, bool noFormatting = false) +static void DrawText(RenderTarget& rt, const ScreenCoordsXY& coords, u8string_view text, const TextPaint& paint) { + auto noFormatting = paint.flags.has(TextPaintFlag::noFormatting); int32_t width = getStringWidth(text, paint.fontStyle, noFormatting); auto alignedCoords = coords; @@ -114,11 +114,6 @@ static void DrawText( } } -void DrawTextNoFormatting(RenderTarget& rt, const ScreenCoordsXY& coords, u8string_view string, TextPaint textPaint) -{ - DrawText(rt, coords, string, textPaint, true); -} - void DrawTextBasic(RenderTarget& rt, const ScreenCoordsXY& coords, StringId format, TextPaint textPaint) { DrawTextBasic(rt, coords, LanguageGetString(format), textPaint); diff --git a/src/openrct2/drawing/Text.h b/src/openrct2/drawing/Text.h index 41ef1b510a..19e0c202cf 100644 --- a/src/openrct2/drawing/Text.h +++ b/src/openrct2/drawing/Text.h @@ -38,6 +38,7 @@ enum class TextAlignment enum class TextPaintFlag { underline, + noFormatting, }; using TextPaintFlags = FlagHolder; @@ -210,9 +211,6 @@ struct TextPaint } }; -void DrawTextNoFormatting( - OpenRCT2::Drawing::RenderTarget& rt, const ScreenCoordsXY& coords, u8string_view string, TextPaint textPaint = {}); - void DrawTextBasic( OpenRCT2::Drawing::RenderTarget& rt, const ScreenCoordsXY& coords, StringId format, TextPaint textPaint = {}); void DrawTextBasic(