From df1564c9cdcfe720e9f8dfc44eed9a9ebc5a4652 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 22 Mar 2026 14:14:32 +0100 Subject: [PATCH] Namespace Drawing.String.cpp, declare its functions in Drawing.String.h --- src/openrct2-ui/interface/InGameConsole.cpp | 1 + src/openrct2-ui/interface/Widget.cpp | 1 + src/openrct2-ui/scripting/CustomListView.cpp | 1 + .../scripting/ScGraphicsContext.hpp | 5 +- src/openrct2-ui/windows/Changelog.cpp | 3 +- src/openrct2-ui/windows/DebugPaint.cpp | 3 +- src/openrct2-ui/windows/Dropdown.cpp | 1 + src/openrct2-ui/windows/Error.cpp | 5 +- src/openrct2-ui/windows/Finances.cpp | 1 + src/openrct2-ui/windows/GameBottomToolbar.cpp | 1 + src/openrct2-ui/windows/LoadSave.cpp | 1 + src/openrct2-ui/windows/Map.cpp | 1 + src/openrct2-ui/windows/Multiplayer.cpp | 1 + src/openrct2-ui/windows/NetworkStatus.cpp | 5 +- src/openrct2-ui/windows/NewRide.cpp | 1 + src/openrct2-ui/windows/Options.cpp | 1 + src/openrct2-ui/windows/Park.cpp | 1 + src/openrct2-ui/windows/Ride.cpp | 1 + src/openrct2-ui/windows/ScenarioSelect.cpp | 1 + src/openrct2-ui/windows/ServerList.cpp | 1 + src/openrct2-ui/windows/TextInput.cpp | 1 + src/openrct2-ui/windows/Themes.cpp | 1 + src/openrct2-ui/windows/TitleVersion.cpp | 5 +- src/openrct2-ui/windows/Tooltip.cpp | 1 + src/openrct2-ui/windows/TrackList.cpp | 1 + src/openrct2/drawing/Drawing.String.cpp | 1620 +++++++++-------- src/openrct2/drawing/Drawing.String.h | 77 +- src/openrct2/drawing/Drawing.h | 23 - src/openrct2/drawing/IDrawingContext.h | 3 +- src/openrct2/drawing/ScrollingText.cpp | 1 + src/openrct2/drawing/Text.cpp | 1 + src/openrct2/drawing/X8DrawingEngine.h | 3 +- src/openrct2/entity/MoneyEffect.cpp | 3 +- src/openrct2/interface/Chat.cpp | 1 + src/openrct2/paint/Paint.cpp | 1 + src/openrct2/paint/Painter.cpp | 1 + 36 files changed, 910 insertions(+), 869 deletions(-) diff --git a/src/openrct2-ui/interface/InGameConsole.cpp b/src/openrct2-ui/interface/InGameConsole.cpp index 59116c9db5..6968c327da 100644 --- a/src/openrct2-ui/interface/InGameConsole.cpp +++ b/src/openrct2-ui/interface/InGameConsole.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include diff --git a/src/openrct2-ui/interface/Widget.cpp b/src/openrct2-ui/interface/Widget.cpp index 3ccaed2c73..822c9a75f4 100644 --- a/src/openrct2-ui/interface/Widget.cpp +++ b/src/openrct2-ui/interface/Widget.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include diff --git a/src/openrct2-ui/scripting/CustomListView.cpp b/src/openrct2-ui/scripting/CustomListView.cpp index 99a245d5cd..184efcf3ae 100644 --- a/src/openrct2-ui/scripting/CustomListView.cpp +++ b/src/openrct2-ui/scripting/CustomListView.cpp @@ -19,6 +19,7 @@ #include #include #include + #include #include #include #include diff --git a/src/openrct2-ui/scripting/ScGraphicsContext.hpp b/src/openrct2-ui/scripting/ScGraphicsContext.hpp index 2598080656..da3a75395f 100644 --- a/src/openrct2-ui/scripting/ScGraphicsContext.hpp +++ b/src/openrct2-ui/scripting/ScGraphicsContext.hpp @@ -13,6 +13,7 @@ #include "CustomImages.h" + #include #include #include #include @@ -158,8 +159,8 @@ namespace OpenRCT2::Scripting DukValue measureText(const std::string& text) { - auto width = GfxGetStringWidth(text, FontStyle::medium); - auto height = StringGetHeightRaw(text.c_str(), FontStyle::medium); + auto width = Drawing::GfxGetStringWidth(text, FontStyle::medium); + auto height = Drawing::StringGetHeightRaw(text.c_str(), FontStyle::medium); return ToDuk(_ctx, { width, height }); } diff --git a/src/openrct2-ui/windows/Changelog.cpp b/src/openrct2-ui/windows/Changelog.cpp index ce9e495af9..6f146c875b 100644 --- a/src/openrct2-ui/windows/Changelog.cpp +++ b/src/openrct2-ui/windows/Changelog.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -261,7 +262,7 @@ namespace OpenRCT2::Ui::Windows _changelogLongestLineWidth = 0; for (const auto& line : _changelogLines) { - int32_t linewidth = GfxGetStringWidth(line.c_str(), FontStyle::medium); + int32_t linewidth = Drawing::GfxGetStringWidth(line.c_str(), FontStyle::medium); _changelogLongestLineWidth = std::max(linewidth, _changelogLongestLineWidth); } } diff --git a/src/openrct2-ui/windows/DebugPaint.cpp b/src/openrct2-ui/windows/DebugPaint.cpp index 132a5fb7f6..e13dc922d8 100644 --- a/src/openrct2-ui/windows/DebugPaint.cpp +++ b/src/openrct2-ui/windows/DebugPaint.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -126,7 +127,7 @@ namespace OpenRCT2::Ui::Windows const auto& stringIdx = widgets[widgetIndex].text; auto string = ls.GetString(stringIdx); Guard::ArgumentNotNull(string); - const auto strWidth = GfxGetStringWidth(string, FontStyle::medium); + const auto strWidth = Drawing::GfxGetStringWidth(string, FontStyle::medium); newWidth = std::max(strWidth, newWidth); } diff --git a/src/openrct2-ui/windows/Dropdown.cpp b/src/openrct2-ui/windows/Dropdown.cpp index 5531de409f..a0f41e1374 100644 --- a/src/openrct2-ui/windows/Dropdown.cpp +++ b/src/openrct2-ui/windows/Dropdown.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include diff --git a/src/openrct2-ui/windows/Error.cpp b/src/openrct2-ui/windows/Error.cpp index 72c4fb3556..6df2c89d20 100644 --- a/src/openrct2-ui/windows/Error.cpp +++ b/src/openrct2-ui/windows/Error.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -126,12 +127,12 @@ namespace OpenRCT2::Ui::Windows windowMgr->CloseByClass(WindowClass::error); // How wide is the error string? - int32_t width = GfxGetStringWidthNewLined(buffer.data(), FontStyle::medium); + int32_t width = Drawing::GfxGetStringWidthNewLined(buffer.data(), FontStyle::medium); width = std::clamp(width + 2 * kPadding, kMinWidth, kMaxWidth); // How high is the error string? int32_t numLines{}; - GfxWrapString(buffer, width + 1, FontStyle::medium, &buffer, &numLines); + Drawing::GfxWrapString(buffer, width + 1, FontStyle::medium, &buffer, &numLines); int32_t height = (numLines + 1) * FontGetLineHeight(FontStyle::medium) + (2 * kPadding); // Position error message around the cursor diff --git a/src/openrct2-ui/windows/Finances.cpp b/src/openrct2-ui/windows/Finances.cpp index a46965b328..48b1d2b278 100644 --- a/src/openrct2-ui/windows/Finances.cpp +++ b/src/openrct2-ui/windows/Finances.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include diff --git a/src/openrct2-ui/windows/GameBottomToolbar.cpp b/src/openrct2-ui/windows/GameBottomToolbar.cpp index e965191281..cc8674232a 100644 --- a/src/openrct2-ui/windows/GameBottomToolbar.cpp +++ b/src/openrct2-ui/windows/GameBottomToolbar.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include diff --git a/src/openrct2-ui/windows/LoadSave.cpp b/src/openrct2-ui/windows/LoadSave.cpp index 4d74fa317f..70e9fefcc4 100644 --- a/src/openrct2-ui/windows/LoadSave.cpp +++ b/src/openrct2-ui/windows/LoadSave.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include diff --git a/src/openrct2-ui/windows/Map.cpp b/src/openrct2-ui/windows/Map.cpp index 2e1ae73d57..efc41c7a62 100644 --- a/src/openrct2-ui/windows/Map.cpp +++ b/src/openrct2-ui/windows/Map.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include diff --git a/src/openrct2-ui/windows/Multiplayer.cpp b/src/openrct2-ui/windows/Multiplayer.cpp index 497cd31f65..bc9c1e125f 100644 --- a/src/openrct2-ui/windows/Multiplayer.cpp +++ b/src/openrct2-ui/windows/Multiplayer.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include diff --git a/src/openrct2-ui/windows/NetworkStatus.cpp b/src/openrct2-ui/windows/NetworkStatus.cpp index a54288b1b5..e112098e73 100644 --- a/src/openrct2-ui/windows/NetworkStatus.cpp +++ b/src/openrct2-ui/windows/NetworkStatus.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -93,10 +94,10 @@ namespace OpenRCT2::Ui::Windows _buffer.assign("{WHITE}"); _buffer += _windowNetworkStatusText; - GfxClipString(_buffer.data(), widgets[WIDX_BACKGROUND].right - 50, FontStyle::medium); + Drawing::GfxClipString(_buffer.data(), widgets[WIDX_BACKGROUND].right - 50, FontStyle::medium); ScreenCoordsXY screenCoords(windowPos.x + (width / 2), windowPos.y + (height / 2)); - screenCoords.x -= GfxGetStringWidth(_buffer, FontStyle::medium) / 2; + screenCoords.x -= Drawing::GfxGetStringWidth(_buffer, FontStyle::medium) / 2; DrawTextBasic(rt, screenCoords, _buffer, { Drawing::Colour::black }); } diff --git a/src/openrct2-ui/windows/NewRide.cpp b/src/openrct2-ui/windows/NewRide.cpp index e95d8a5830..d5c041bbb9 100644 --- a/src/openrct2-ui/windows/NewRide.cpp +++ b/src/openrct2-ui/windows/NewRide.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include diff --git a/src/openrct2-ui/windows/Options.cpp b/src/openrct2-ui/windows/Options.cpp index efdb45d884..02965a93f4 100644 --- a/src/openrct2-ui/windows/Options.cpp +++ b/src/openrct2-ui/windows/Options.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include diff --git a/src/openrct2-ui/windows/Park.cpp b/src/openrct2-ui/windows/Park.cpp index ace15fbbeb..283f28f459 100644 --- a/src/openrct2-ui/windows/Park.cpp +++ b/src/openrct2-ui/windows/Park.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index c9cc15ef20..ccfa4d2df9 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include diff --git a/src/openrct2-ui/windows/ScenarioSelect.cpp b/src/openrct2-ui/windows/ScenarioSelect.cpp index 9c2ece20b4..2d35f26f94 100644 --- a/src/openrct2-ui/windows/ScenarioSelect.cpp +++ b/src/openrct2-ui/windows/ScenarioSelect.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include diff --git a/src/openrct2-ui/windows/ServerList.cpp b/src/openrct2-ui/windows/ServerList.cpp index 6d751fc15d..0759fc9608 100644 --- a/src/openrct2-ui/windows/ServerList.cpp +++ b/src/openrct2-ui/windows/ServerList.cpp @@ -20,6 +20,7 @@ #include #include #include + #include #include #include #include diff --git a/src/openrct2-ui/windows/TextInput.cpp b/src/openrct2-ui/windows/TextInput.cpp index 3f28bdd38a..6264f0eda9 100644 --- a/src/openrct2-ui/windows/TextInput.cpp +++ b/src/openrct2-ui/windows/TextInput.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include diff --git a/src/openrct2-ui/windows/Themes.cpp b/src/openrct2-ui/windows/Themes.cpp index e8aa9c6488..ba8823e6a6 100644 --- a/src/openrct2-ui/windows/Themes.cpp +++ b/src/openrct2-ui/windows/Themes.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include diff --git a/src/openrct2-ui/windows/TitleVersion.cpp b/src/openrct2-ui/windows/TitleVersion.cpp index 5090fec6b6..a51d9deaa5 100644 --- a/src/openrct2-ui/windows/TitleVersion.cpp +++ b/src/openrct2-ui/windows/TitleVersion.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -28,12 +29,12 @@ namespace OpenRCT2::Ui::Windows // Write name and version information const auto whiteOutline = ColourWithFlags{ Drawing::Colour::white }.withFlag(ColourFlag::withOutline, true); DrawTextBasic(rt, windowPos, gVersionInfoFull, { whiteOutline }); - width = GfxGetStringWidth(gVersionInfoFull, FontStyle::medium); + width = Drawing::GfxGetStringWidth(gVersionInfoFull, FontStyle::medium); // Write platform information constexpr const char platformInfo[] = OPENRCT2_PLATFORM " (" OPENRCT2_ARCHITECTURE ")"; DrawTextBasic(rt, windowPos + ScreenCoordsXY(0, kListRowHeight), platformInfo, { whiteOutline }); - width = std::max(width, GfxGetStringWidth(platformInfo, FontStyle::medium)) + kTextOffset; + width = std::max(width, Drawing::GfxGetStringWidth(platformInfo, FontStyle::medium)) + kTextOffset; } }; diff --git a/src/openrct2-ui/windows/Tooltip.cpp b/src/openrct2-ui/windows/Tooltip.cpp index c1ffbf5b57..d4efd4d552 100644 --- a/src/openrct2-ui/windows/Tooltip.cpp +++ b/src/openrct2-ui/windows/Tooltip.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include diff --git a/src/openrct2-ui/windows/TrackList.cpp b/src/openrct2-ui/windows/TrackList.cpp index 4406329081..f3b39032ea 100644 --- a/src/openrct2-ui/windows/TrackList.cpp +++ b/src/openrct2-ui/windows/TrackList.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include diff --git a/src/openrct2/drawing/Drawing.String.cpp b/src/openrct2/drawing/Drawing.String.cpp index fd688ce59d..c3800604fa 100644 --- a/src/openrct2/drawing/Drawing.String.cpp +++ b/src/openrct2/drawing/Drawing.String.cpp @@ -28,871 +28,873 @@ #include "../platform/Platform.h" #include "TTF.h" -using namespace OpenRCT2; -using namespace OpenRCT2::Drawing; - -static int32_t TTFGetStringWidth(std::string_view text, FontStyle fontStyle, bool noFormatting); - -/** - * - * rct2: 0x006C23B1 - */ -int32_t GfxGetStringWidthNewLined(std::string_view text, FontStyle fontStyle) +namespace OpenRCT2::Drawing { - u8string buffer; + static int32_t TTFGetStringWidth(std::string_view text, FontStyle fontStyle, bool noFormatting); - std::optional maxWidth; - FmtString fmt(text); - for (const auto& token : fmt) + /** + * + * rct2: 0x006C23B1 + */ + int32_t GfxGetStringWidthNewLined(std::string_view text, FontStyle fontStyle) { - if (token.kind == FormatToken::newline || token.kind == FormatToken::newlineSmall) + u8string buffer; + + std::optional maxWidth; + FmtString fmt(text); + for (const auto& token : fmt) { - auto width = GfxGetStringWidth(buffer, fontStyle); - if (!maxWidth.has_value() || maxWidth.value() > width) + if (token.kind == FormatToken::newline || token.kind == FormatToken::newlineSmall) { - maxWidth = width; - } - buffer.clear(); - } - else - { - buffer.append(token.text); - } - } - if (!maxWidth.has_value()) - { - maxWidth = GfxGetStringWidth(buffer, fontStyle); - } - return maxWidth.value(); -} - -/** - * Return the width of the string in buffer - * - * rct2: 0x006C2321 - * buffer (esi) - */ -int32_t GfxGetStringWidth(std::string_view text, FontStyle fontStyle) -{ - return TTFGetStringWidth(text, fontStyle, false); -} - -int32_t GfxGetStringWidthNoFormatting(std::string_view text, FontStyle fontStyle) -{ - return TTFGetStringWidth(text, fontStyle, true); -} - -/** - * Clip the text in buffer to width, add ellipsis and return the new width of the clipped string - * - * rct2: 0x006C2460 - * buffer (esi) - * width (edi) - */ -int32_t GfxClipString(utf8* text, int32_t width, FontStyle fontStyle) -{ - if (width < 6) - { - *text = 0; - return 0; - } - - // If width of the full string is less than allowed width then we don't need to clip - auto clippedWidth = GfxGetStringWidth(text, fontStyle); - if (clippedWidth <= width) - { - return clippedWidth; - } - - // Append each character 1 by 1 with an ellipsis on the end until width is exceeded - thread_local std::string buffer; - buffer.clear(); - - size_t bestLength = 0; - int32_t bestWidth = 0; - - FmtString fmt(text); - for (const auto& token : fmt) - { - CodepointView codepoints(token.text); - for (auto codepoint : codepoints) - { - // Add the ellipsis before checking the width - buffer.append("..."); - - auto currentWidth = GfxGetStringWidth(buffer, fontStyle); - if (currentWidth < width) - { - bestLength = buffer.size(); - bestWidth = currentWidth; - - // Trim the ellipsis - buffer.resize(bestLength - 3); + auto width = GfxGetStringWidth(buffer, fontStyle); + if (!maxWidth.has_value() || maxWidth.value() > width) + { + maxWidth = width; + } + buffer.clear(); } else { - // Width exceeded, rollback to best length and put ellipsis back - buffer.resize(bestLength); - for (auto i = static_cast(bestLength) - 1; i >= 0 && i >= static_cast(bestLength) - 3; i--) - { - buffer[i] = '.'; - } - - // Copy buffer back to input text buffer - std::strcpy(text, buffer.c_str()); - return bestWidth; + buffer.append(token.text); } - - char cb[8]{}; - UTF8WriteCodepoint(cb, codepoint); - buffer.append(cb); } + if (!maxWidth.has_value()) + { + maxWidth = GfxGetStringWidth(buffer, fontStyle); + } + return maxWidth.value(); } - return GfxGetStringWidth(text, fontStyle); -} -/** - * Wrap the text in buffer to width, returns width of longest line. - * - * Inserts NULL where line should break (as \n is used for something else), - * so the number of lines is returned in num_lines. font_height seems to be - * a control character for line height. - * - * rct2: 0x006C21E2 - * buffer (esi) - * width (edi) - in - * num_lines (edi) - out - * font_height (ebx) - out - */ -int32_t GfxWrapString(u8string_view text, int32_t width, FontStyle fontStyle, u8string* outWrappedText, int32_t* outNumLines) -{ - constexpr size_t kNullIndex = std::numeric_limits::max(); - u8string buffer; - - size_t currentLineIndex = 0; - size_t splitIndex = kNullIndex; - size_t bestSplitIndex = kNullIndex; - size_t numLines = 0; - int32_t maxWidth = 0; - - FmtString fmt(text); - for (const auto& token : fmt) + /** + * Return the width of the string in buffer + * + * rct2: 0x006C2321 + * buffer (esi) + */ + int32_t GfxGetStringWidth(std::string_view text, FontStyle fontStyle) { - if (token.IsLiteral()) + return TTFGetStringWidth(text, fontStyle, false); + } + + int32_t GfxGetStringWidthNoFormatting(std::string_view text, FontStyle fontStyle) + { + return TTFGetStringWidth(text, fontStyle, true); + } + + /** + * Clip the text in buffer to width, add ellipsis and return the new width of the clipped string + * + * rct2: 0x006C2460 + * buffer (esi) + * width (edi) + */ + int32_t GfxClipString(utf8* text, int32_t width, FontStyle fontStyle) + { + if (width < 6) + { + *text = 0; + return 0; + } + + // If width of the full string is less than allowed width then we don't need to clip + auto clippedWidth = GfxGetStringWidth(text, fontStyle); + if (clippedWidth <= width) + { + return clippedWidth; + } + + // Append each character 1 by 1 with an ellipsis on the end until width is exceeded + thread_local std::string buffer; + buffer.clear(); + + size_t bestLength = 0; + int32_t bestWidth = 0; + + FmtString fmt(text); + for (const auto& token : fmt) { CodepointView codepoints(token.text); for (auto codepoint : codepoints) { - char cb[8]{}; - UTF8WriteCodepoint(cb, codepoint); - buffer.append(cb); + // Add the ellipsis before checking the width + buffer.append("..."); - auto lineWidth = GfxGetStringWidth(&buffer[currentLineIndex], fontStyle); - if (lineWidth <= width || (splitIndex == kNullIndex && bestSplitIndex == kNullIndex)) + auto currentWidth = GfxGetStringWidth(buffer, fontStyle); + if (currentWidth < width) { - if (codepoint == ' ') - { - // Mark line split here - splitIndex = buffer.size() - 1; - } - else if (splitIndex == kNullIndex) - { - // Mark line split here (this is after first character of line) - bestSplitIndex = buffer.size(); - } + bestLength = buffer.size(); + bestWidth = currentWidth; + + // Trim the ellipsis + buffer.resize(bestLength - 3); } else { - // Insert new line before current word - if (splitIndex == kNullIndex) + // Width exceeded, rollback to best length and put ellipsis back + buffer.resize(bestLength); + for (auto i = static_cast(bestLength) - 1; i >= 0 && i >= static_cast(bestLength) - 3; + i--) { - splitIndex = bestSplitIndex; + buffer[i] = '.'; } - buffer.insert(buffer.begin() + splitIndex, '\0'); - // Recalculate the line length after splitting - lineWidth = GfxGetStringWidth(&buffer[currentLineIndex], fontStyle); - maxWidth = std::max(maxWidth, lineWidth); - numLines++; - - currentLineIndex = splitIndex + 1; - splitIndex = kNullIndex; - bestSplitIndex = kNullIndex; - - // Trim the beginning of the new line - while (buffer[currentLineIndex] == ' ') - { - buffer.erase(buffer.begin() + currentLineIndex); - } + // Copy buffer back to input text buffer + std::strcpy(text, buffer.c_str()); + return bestWidth; } + + char cb[8]{}; + UTF8WriteCodepoint(cb, codepoint); + buffer.append(cb); } } - else if (token.kind == FormatToken::newline) - { - buffer.push_back('\0'); - - auto lineWidth = GfxGetStringWidth(&buffer[currentLineIndex], fontStyle); - maxWidth = std::max(maxWidth, lineWidth); - numLines++; - - currentLineIndex = buffer.size(); - splitIndex = kNullIndex; - bestSplitIndex = kNullIndex; - } - else - { - buffer.append(token.text); - } - } - { - // Final line width calculation - auto lineWidth = GfxGetStringWidth(&buffer[currentLineIndex], fontStyle); - maxWidth = std::max(maxWidth, lineWidth); + return GfxGetStringWidth(text, fontStyle); } - if (outWrappedText != nullptr) + /** + * Wrap the text in buffer to width, returns width of longest line. + * + * Inserts NULL where line should break (as \n is used for something else), + * so the number of lines is returned in num_lines. font_height seems to be + * a control character for line height. + * + * rct2: 0x006C21E2 + * buffer (esi) + * width (edi) - in + * num_lines (edi) - out + * font_height (ebx) - out + */ + int32_t GfxWrapString( + u8string_view text, int32_t width, FontStyle fontStyle, u8string* outWrappedText, int32_t* outNumLines) { - *outWrappedText = std::move(buffer); - } - if (outNumLines != nullptr) - { - *outNumLines = static_cast(numLines); - } - return maxWidth; -} + constexpr size_t kNullIndex = std::numeric_limits::max(); + u8string buffer; -/** - * Draws text that is left aligned and vertically centred. - */ -void GfxDrawStringLeftCentred( - RenderTarget& rt, StringId format, void* args, ColourWithFlags colour, const ScreenCoordsXY& coords) -{ - char buffer[512]; - auto bufferPtr = buffer; - FormatStringLegacy(bufferPtr, sizeof(buffer), format, args); - int32_t height = StringGetHeightRaw(bufferPtr, FontStyle::medium); - DrawTextBasic(rt, coords - ScreenCoordsXY{ 0, (height / 2) }, bufferPtr, { colour }); -} + size_t currentLineIndex = 0; + size_t splitIndex = kNullIndex; + size_t bestSplitIndex = kNullIndex; + size_t numLines = 0; + int32_t maxWidth = 0; -/** - * Changes the palette so that the next character changes colour - */ -static void ColourCharacter(TextColour colour, bool withOutline, TextColours& textPalette) -{ - auto mapping = getTextColourMapping(colour); - - if (!withOutline) - { - mapping.sunnyOutline = PaletteIndex::transparent; - mapping.shadowOutline = PaletteIndex::transparent; - } - - textPalette = mapping; -} - -/** - * Changes the palette so that the next character changes colour - * This is specific to changing to a predefined window related colour - */ -static void ColourCharacterWindow(OpenRCT2::Drawing::Colour colour, bool withOutline, TextColours& textPalette) -{ - TextColours mapping = { - getColourMap(colour).colour11, - PaletteIndex::transparent, - PaletteIndex::transparent, - }; - - if (withOutline) - { - mapping.sunnyOutline = PaletteIndex::pi10; - mapping.shadowOutline = PaletteIndex::pi10; - } - - textPalette = mapping; -} - -/** - * - * rct2: 0x006C1DB7 - * - * left : cx - * top : dx - * numLines : bp - * text : esi - * rt : edi - */ -void DrawStringCentredRaw( - RenderTarget& rt, const ScreenCoordsXY& coords, int32_t numLines, const utf8* text, FontStyle fontStyle) -{ - ScreenCoordsXY screenCoords(rt.x, rt.y); - DrawTextBasic(rt, screenCoords, "", { Colour::black, fontStyle }); - screenCoords = coords; - - for (int32_t i = 0; i <= numLines; i++) - { - int32_t width = GfxGetStringWidth(text, fontStyle); - DrawTextBasic(rt, screenCoords - ScreenCoordsXY{ width / 2, 0 }, text, { kColourNull, fontStyle }); - - const utf8* ch = text; - const utf8* nextCh = nullptr; - - while ((UTF8GetNext(ch, &nextCh)) != 0) - { - ch = nextCh; - } - text = const_cast(ch + 1); - - screenCoords.y += FontGetLineHeight(fontStyle); - } -} - -int32_t StringGetHeightRaw(std::string_view text, FontStyle fontStyle) -{ - int32_t height = 0; - if (fontStyle <= FontStyle::medium) - height += 10; - else if (fontStyle == FontStyle::tiny) - height += 6; - - FmtString fmt(text); - for (const auto& token : fmt) - { - switch (token.kind) - { - case FormatToken::newline: - if (fontStyle == FontStyle::small || fontStyle == FontStyle::medium) - { - height += 10; - break; - } - - if (fontStyle == FontStyle::tiny) - { - height += 6; - break; - } - height += 18; - break; - case FormatToken::newlineSmall: - if (fontStyle == FontStyle::small || fontStyle == FontStyle::medium) - { - height += 5; - break; - } - - if (fontStyle == FontStyle::tiny) - { - height += 3; - break; - } - height += 9; - break; - case FormatToken::fontTiny: - fontStyle = FontStyle::tiny; - break; - case FormatToken::fontMedium: - fontStyle = FontStyle::medium; - break; - case FormatToken::fontSmall: - fontStyle = FontStyle::small; - break; - default: - break; - } - } - return height; -} - -/** - * - * rct2: 0x006C1F57 - * - * colour : al - * format : bx - * x : cx - * y : dx - * text : esi - * rt : edi - * width : bp - * ticks : ebp >> 16 - */ -void DrawNewsTicker( - RenderTarget& rt, const ScreenCoordsXY& coords, int32_t width, OpenRCT2::Drawing::Colour colour, StringId format, - u8string_view args, int32_t ticks) -{ - int32_t numLines, lineHeight, lineY; - ScreenCoordsXY screenCoords(rt.x, rt.y); - - DrawTextBasic(rt, screenCoords, "", { colour }); - - u8string wrappedString; - GfxWrapString(FormatStringID(format, args), width, FontStyle::small, &wrappedString, &numLines); - lineHeight = FontGetLineHeight(FontStyle::small); - - int32_t numCharactersDrawn = 0; - int32_t numCharactersToDraw = ticks; - - const utf8* buffer = wrappedString.data(); - lineY = coords.y - ((numLines * lineHeight) / 2); - for (int32_t line = 0; line <= numLines; line++) - { - int32_t halfWidth = GfxGetStringWidth(buffer, FontStyle::small) / 2; - - FmtString fmt(buffer); - for (const auto& token : fmt) - { - bool doubleBreak = false; - if (token.IsLiteral()) - { - CodepointView codepoints(token.text); - for (auto it = codepoints.begin(); it != codepoints.end(); it++) - { - numCharactersDrawn++; - if (numCharactersDrawn > numCharactersToDraw) - { - auto ch = const_cast(&token.text[it.GetIndex()]); - *ch = '\0'; - doubleBreak = true; - break; - } - } - } - if (doubleBreak) - break; - } - - screenCoords = { coords.x - halfWidth, lineY }; - DrawTextBasic(rt, screenCoords, buffer, { kColourNull, FontStyle::small }); - - if (numCharactersDrawn > numCharactersToDraw) - { - break; - } - - buffer = GetStringEnd(buffer) + 1; - lineY += lineHeight; - } -} - -static void TTFDrawCharacterSprite(RenderTarget& rt, int32_t codepoint, TextDrawInfo* info) -{ - int32_t characterWidth = FontSpriteGetCodepointWidth(info->fontStyle, codepoint); - auto sprite = FontSpriteGetCodepointSprite(info->fontStyle, codepoint); - - if (!info->textDrawFlags.has(TextDrawFlag::noDraw)) - { - auto screenCoords = ScreenCoordsXY{ info->x, info->y }; - if (info->textDrawFlags.has(TextDrawFlag::yOffsetEffect)) - { - screenCoords.y += *info->yOffset++; - } - - PaletteIndex palette[8]{}; - palette[1] = info->palette.fill; - palette[2] = info->palette.sunnyOutline; - palette[3] = info->palette.shadowOutline; - - PaletteMap paletteMap(palette); - GfxDrawGlyph(rt, sprite, screenCoords, paletteMap); - } - - info->x += characterWidth; -} - -static void TTFDrawStringRawSprite(RenderTarget& rt, std::string_view text, TextDrawInfo* info) -{ - CodepointView codepoints(text); - for (auto codepoint : codepoints) - { - TTFDrawCharacterSprite(rt, codepoint, info); - } -} - -#ifndef DISABLE_TTF - -static void TTFDrawStringRawTTF(RenderTarget& rt, std::string_view text, TextDrawInfo* info) -{ - if (!TTFInitialise()) - return; - - TTFFontDescriptor* fontDesc = TTFGetFontFromSpriteBase(info->fontStyle); - if (fontDesc->font == nullptr) - { - TTFDrawStringRawSprite(rt, text, info); - return; - } - - if (info->textDrawFlags.has(TextDrawFlag::noDraw)) - { - info->x += TTFGetWidthCacheGetOrAdd(fontDesc->font, text); - return; - } - - TTFSurface* surface = TTFSurfaceCacheGetOrAdd(fontDesc->font, text); - if (surface == nullptr) - return; - - auto drawingEngine = rt.DrawingEngine; - if (drawingEngine != nullptr) - { - int32_t drawX = info->x + fontDesc->offset_x; - int32_t drawY = info->y + fontDesc->offset_y; - uint8_t hintThresh = Config::Get().fonts.enableHinting ? fontDesc->hinting_threshold : 0; - IDrawingContext* dc = drawingEngine->GetDrawingContext(); - dc->DrawTTFBitmap(rt, info, surface, drawX, drawY, hintThresh); - } - info->x += surface->w; -} - -#endif // DISABLE_TTF - -static void TTFProcessFormatCode(RenderTarget& rt, const FmtString::Token& token, TextDrawInfo* info) -{ - switch (token.kind) - { - case FormatToken::move: - info->x = info->startX + token.parameter; - break; - case FormatToken::newline: - info->x = info->startX; - info->y += FontGetLineHeight(info->fontStyle); - break; - case FormatToken::newlineSmall: - info->x = info->startX; - info->y += FontGetLineHeightSmall(info->fontStyle); - break; - case FormatToken::fontTiny: - info->fontStyle = FontStyle::tiny; - break; - case FormatToken::fontSmall: - info->fontStyle = FontStyle::small; - break; - case FormatToken::fontMedium: - info->fontStyle = FontStyle::medium; - break; - case FormatToken::outlineEnable: - info->colourFlags.set(ColourFlag::withOutline); - break; - case FormatToken::outlineDisable: - info->colourFlags.unset(ColourFlag::withOutline); - break; - case FormatToken::colourWindow1: - { - ColourCharacterWindow(gCurrentWindowColours[0], info->colourFlags.has(ColourFlag::withOutline), info->palette); - break; - } - case FormatToken::colourWindow2: - { - ColourCharacterWindow(gCurrentWindowColours[1], info->colourFlags.has(ColourFlag::withOutline), info->palette); - break; - } - case FormatToken::colourWindow3: - { - ColourCharacterWindow(gCurrentWindowColours[2], info->colourFlags.has(ColourFlag::withOutline), info->palette); - break; - } - case FormatToken::inlineSprite: - { - auto imageId = ImageId(token.parameter); - auto g1 = GfxGetG1Element(imageId); - if (g1 != nullptr && g1->width <= 32 && g1->height <= 32) - { - if (!info->textDrawFlags.has(TextDrawFlag::noDraw)) - { - GfxDrawSprite(rt, imageId, { info->x, info->y }); - } - info->x += g1->width; - } - break; - } - default: - if (FormatTokenIsColour(token.kind)) - { - auto colourIndex = FormatTokenToTextColour(token.kind); - ColourCharacter(colourIndex, info->colourFlags.has(ColourFlag::withOutline), info->palette); - } - break; - } -} - -#ifndef DISABLE_TTF -static bool ShouldUseSpriteForCodepoint(char32_t codepoint) -{ - switch (codepoint) - { - case UnicodeChar::up: - case UnicodeChar::down: - case UnicodeChar::leftguillemet: - case UnicodeChar::tick: - case UnicodeChar::cross: - case UnicodeChar::right: - case UnicodeChar::rightguillemet: - case UnicodeChar::small_up: - case UnicodeChar::small_down: - case UnicodeChar::left: - case UnicodeChar::quote_open: - case UnicodeChar::quote_close: - case UnicodeChar::german_quote_open: - case UnicodeChar::plus: - case UnicodeChar::minus: - case UnicodeChar::variation_selector: - case UnicodeChar::eye: - case UnicodeChar::road: - case UnicodeChar::railway: - return true; - default: - return false; - } -} -#endif // DISABLE_TTF - -static void TTFProcessStringLiteral(RenderTarget& rt, std::string_view text, TextDrawInfo* info) -{ -#ifndef DISABLE_TTF - bool isTTF = info->textDrawFlags.has(TextDrawFlag::ttf); -#else - bool isTTF = false; -#endif // DISABLE_TTF - - if (!isTTF) - { - TTFDrawStringRawSprite(rt, text, info); - } -#ifndef DISABLE_TTF - else - { - CodepointView codepoints(text); - std::optional ttfRunIndex{}; - for (auto it = codepoints.begin(); it != codepoints.end(); it++) - { - auto codepoint = *it; - if (ShouldUseSpriteForCodepoint(codepoint)) - { - if (ttfRunIndex.has_value()) - { - // Draw the TTF run - // This error suppression abomination is here to suppress https://github.com/OpenRCT2/OpenRCT2/issues/17371. - // Additionally, we have to suppress the error for the error suppression... :'-( - // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105937 is fixed in GCC13 - #if defined(__GNUC__) && !defined(__clang__) - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" - #endif - auto len = it.GetIndex() - ttfRunIndex.value(); - TTFDrawStringRawTTF(rt, text.substr(ttfRunIndex.value(), len), info); - #if defined(__GNUC__) && !defined(__clang__) - #pragma GCC diagnostic pop - #endif - ttfRunIndex = std::nullopt; - } - - // Draw the sprite font glyph - TTFDrawCharacterSprite(rt, codepoint, info); - } - else - { - if (!ttfRunIndex.has_value()) - { - ttfRunIndex = it.GetIndex(); - } - } - } - - if (ttfRunIndex.has_value()) - { - // Final TTF run - auto len = text.size() - *ttfRunIndex; - TTFDrawStringRawTTF(rt, text.substr(ttfRunIndex.value(), len), info); - } - } -#endif // DISABLE_TTF -} - -static void TTFProcessStringCodepoint(RenderTarget& rt, codepoint_t codepoint, TextDrawInfo* info) -{ - char buffer[8]{}; - UTF8WriteCodepoint(buffer, codepoint); - TTFProcessStringLiteral(rt, buffer, info); -} - -static void TTFProcessString(RenderTarget& rt, std::string_view text, TextDrawInfo* info) -{ - if (info->textDrawFlags.has(TextDrawFlag::noFormatting)) - { - TTFProcessStringLiteral(rt, text, info); - info->maxX = std::max(info->maxX, info->x); - info->maxY = std::max(info->maxY, info->y); - } - else - { FmtString fmt(text); for (const auto& token : fmt) { if (token.IsLiteral()) { - TTFProcessStringLiteral(rt, token.text, info); + CodepointView codepoints(token.text); + for (auto codepoint : codepoints) + { + char cb[8]{}; + UTF8WriteCodepoint(cb, codepoint); + buffer.append(cb); + + auto lineWidth = GfxGetStringWidth(&buffer[currentLineIndex], fontStyle); + if (lineWidth <= width || (splitIndex == kNullIndex && bestSplitIndex == kNullIndex)) + { + if (codepoint == ' ') + { + // Mark line split here + splitIndex = buffer.size() - 1; + } + else if (splitIndex == kNullIndex) + { + // Mark line split here (this is after first character of line) + bestSplitIndex = buffer.size(); + } + } + else + { + // Insert new line before current word + if (splitIndex == kNullIndex) + { + splitIndex = bestSplitIndex; + } + buffer.insert(buffer.begin() + splitIndex, '\0'); + + // Recalculate the line length after splitting + lineWidth = GfxGetStringWidth(&buffer[currentLineIndex], fontStyle); + maxWidth = std::max(maxWidth, lineWidth); + numLines++; + + currentLineIndex = splitIndex + 1; + splitIndex = kNullIndex; + bestSplitIndex = kNullIndex; + + // Trim the beginning of the new line + while (buffer[currentLineIndex] == ' ') + { + buffer.erase(buffer.begin() + currentLineIndex); + } + } + } } - else if (token.IsCodepoint()) + else if (token.kind == FormatToken::newline) { - auto codepoint = token.GetCodepoint(); - TTFProcessStringCodepoint(rt, codepoint, info); + buffer.push_back('\0'); + + auto lineWidth = GfxGetStringWidth(&buffer[currentLineIndex], fontStyle); + maxWidth = std::max(maxWidth, lineWidth); + numLines++; + + currentLineIndex = buffer.size(); + splitIndex = kNullIndex; + bestSplitIndex = kNullIndex; } else { - TTFProcessFormatCode(rt, token, info); + buffer.append(token.text); } + } + { + // Final line width calculation + auto lineWidth = GfxGetStringWidth(&buffer[currentLineIndex], fontStyle); + maxWidth = std::max(maxWidth, lineWidth); + } + + if (outWrappedText != nullptr) + { + *outWrappedText = std::move(buffer); + } + if (outNumLines != nullptr) + { + *outNumLines = static_cast(numLines); + } + return maxWidth; + } + + /** + * Draws text that is left aligned and vertically centred. + */ + void GfxDrawStringLeftCentred( + RenderTarget& rt, StringId format, void* args, ColourWithFlags colour, const ScreenCoordsXY& coords) + { + char buffer[512]; + auto bufferPtr = buffer; + FormatStringLegacy(bufferPtr, sizeof(buffer), format, args); + int32_t height = StringGetHeightRaw(bufferPtr, FontStyle::medium); + DrawTextBasic(rt, coords - ScreenCoordsXY{ 0, (height / 2) }, bufferPtr, { colour }); + } + + /** + * Changes the palette so that the next character changes colour + */ + static void ColourCharacter(TextColour colour, bool withOutline, TextColours& textPalette) + { + auto mapping = getTextColourMapping(colour); + + if (!withOutline) + { + mapping.sunnyOutline = PaletteIndex::transparent; + mapping.shadowOutline = PaletteIndex::transparent; + } + + textPalette = mapping; + } + + /** + * Changes the palette so that the next character changes colour + * This is specific to changing to a predefined window related colour + */ + static void ColourCharacterWindow(OpenRCT2::Drawing::Colour colour, bool withOutline, TextColours& textPalette) + { + TextColours mapping = { + getColourMap(colour).colour11, + PaletteIndex::transparent, + PaletteIndex::transparent, + }; + + if (withOutline) + { + mapping.sunnyOutline = PaletteIndex::pi10; + mapping.shadowOutline = PaletteIndex::pi10; + } + + textPalette = mapping; + } + + /** + * + * rct2: 0x006C1DB7 + * + * left : cx + * top : dx + * numLines : bp + * text : esi + * rt : edi + */ + void DrawStringCentredRaw( + RenderTarget& rt, const ScreenCoordsXY& coords, int32_t numLines, const utf8* text, FontStyle fontStyle) + { + ScreenCoordsXY screenCoords(rt.x, rt.y); + DrawTextBasic(rt, screenCoords, "", { Colour::black, fontStyle }); + screenCoords = coords; + + for (int32_t i = 0; i <= numLines; i++) + { + int32_t width = GfxGetStringWidth(text, fontStyle); + DrawTextBasic(rt, screenCoords - ScreenCoordsXY{ width / 2, 0 }, text, { kColourNull, fontStyle }); + + const utf8* ch = text; + const utf8* nextCh = nullptr; + + while ((UTF8GetNext(ch, &nextCh)) != 0) + { + ch = nextCh; + } + text = const_cast(ch + 1); + + screenCoords.y += FontGetLineHeight(fontStyle); + } + } + + int32_t StringGetHeightRaw(std::string_view text, FontStyle fontStyle) + { + int32_t height = 0; + if (fontStyle <= FontStyle::medium) + height += 10; + else if (fontStyle == FontStyle::tiny) + height += 6; + + FmtString fmt(text); + for (const auto& token : fmt) + { + switch (token.kind) + { + case FormatToken::newline: + if (fontStyle == FontStyle::small || fontStyle == FontStyle::medium) + { + height += 10; + break; + } + + if (fontStyle == FontStyle::tiny) + { + height += 6; + break; + } + height += 18; + break; + case FormatToken::newlineSmall: + if (fontStyle == FontStyle::small || fontStyle == FontStyle::medium) + { + height += 5; + break; + } + + if (fontStyle == FontStyle::tiny) + { + height += 3; + break; + } + height += 9; + break; + case FormatToken::fontTiny: + fontStyle = FontStyle::tiny; + break; + case FormatToken::fontMedium: + fontStyle = FontStyle::medium; + break; + case FormatToken::fontSmall: + fontStyle = FontStyle::small; + break; + default: + break; + } + } + return height; + } + + /** + * + * rct2: 0x006C1F57 + * + * colour : al + * format : bx + * x : cx + * y : dx + * text : esi + * rt : edi + * width : bp + * ticks : ebp >> 16 + */ + void DrawNewsTicker( + RenderTarget& rt, const ScreenCoordsXY& coords, int32_t width, OpenRCT2::Drawing::Colour colour, StringId format, + u8string_view args, int32_t ticks) + { + int32_t numLines, lineHeight, lineY; + ScreenCoordsXY screenCoords(rt.x, rt.y); + + DrawTextBasic(rt, screenCoords, "", { colour }); + + u8string wrappedString; + GfxWrapString(FormatStringID(format, args), width, FontStyle::small, &wrappedString, &numLines); + lineHeight = FontGetLineHeight(FontStyle::small); + + int32_t numCharactersDrawn = 0; + int32_t numCharactersToDraw = ticks; + + const utf8* buffer = wrappedString.data(); + lineY = coords.y - ((numLines * lineHeight) / 2); + for (int32_t line = 0; line <= numLines; line++) + { + int32_t halfWidth = GfxGetStringWidth(buffer, FontStyle::small) / 2; + + FmtString fmt(buffer); + for (const auto& token : fmt) + { + bool doubleBreak = false; + if (token.IsLiteral()) + { + CodepointView codepoints(token.text); + for (auto it = codepoints.begin(); it != codepoints.end(); it++) + { + numCharactersDrawn++; + if (numCharactersDrawn > numCharactersToDraw) + { + auto ch = const_cast(&token.text[it.GetIndex()]); + *ch = '\0'; + doubleBreak = true; + break; + } + } + } + if (doubleBreak) + break; + } + + screenCoords = { coords.x - halfWidth, lineY }; + DrawTextBasic(rt, screenCoords, buffer, { kColourNull, FontStyle::small }); + + if (numCharactersDrawn > numCharactersToDraw) + { + break; + } + + buffer = GetStringEnd(buffer) + 1; + lineY += lineHeight; + } + } + + static void TTFDrawCharacterSprite(RenderTarget& rt, int32_t codepoint, TextDrawInfo* info) + { + int32_t characterWidth = FontSpriteGetCodepointWidth(info->fontStyle, codepoint); + auto sprite = FontSpriteGetCodepointSprite(info->fontStyle, codepoint); + + if (!info->textDrawFlags.has(TextDrawFlag::noDraw)) + { + auto screenCoords = ScreenCoordsXY{ info->x, info->y }; + if (info->textDrawFlags.has(TextDrawFlag::yOffsetEffect)) + { + screenCoords.y += *info->yOffset++; + } + + PaletteIndex palette[8]{}; + palette[1] = info->palette.fill; + palette[2] = info->palette.sunnyOutline; + palette[3] = info->palette.shadowOutline; + + PaletteMap paletteMap(palette); + GfxDrawGlyph(rt, sprite, screenCoords, paletteMap); + } + + info->x += characterWidth; + } + + static void TTFDrawStringRawSprite(RenderTarget& rt, std::string_view text, TextDrawInfo* info) + { + CodepointView codepoints(text); + for (auto codepoint : codepoints) + { + TTFDrawCharacterSprite(rt, codepoint, info); + } + } + +#ifndef DISABLE_TTF + + static void TTFDrawStringRawTTF(RenderTarget& rt, std::string_view text, TextDrawInfo* info) + { + if (!TTFInitialise()) + return; + + TTFFontDescriptor* fontDesc = TTFGetFontFromSpriteBase(info->fontStyle); + if (fontDesc->font == nullptr) + { + TTFDrawStringRawSprite(rt, text, info); + return; + } + + if (info->textDrawFlags.has(TextDrawFlag::noDraw)) + { + info->x += TTFGetWidthCacheGetOrAdd(fontDesc->font, text); + return; + } + + TTFSurface* surface = TTFSurfaceCacheGetOrAdd(fontDesc->font, text); + if (surface == nullptr) + return; + + auto drawingEngine = rt.DrawingEngine; + if (drawingEngine != nullptr) + { + int32_t drawX = info->x + fontDesc->offset_x; + int32_t drawY = info->y + fontDesc->offset_y; + uint8_t hintThresh = Config::Get().fonts.enableHinting ? fontDesc->hinting_threshold : 0; + IDrawingContext* dc = drawingEngine->GetDrawingContext(); + dc->DrawTTFBitmap(rt, info, surface, drawX, drawY, hintThresh); + } + info->x += surface->w; + } + +#endif // DISABLE_TTF + + static void TTFProcessFormatCode(RenderTarget& rt, const FmtString::Token& token, TextDrawInfo* info) + { + switch (token.kind) + { + case FormatToken::move: + info->x = info->startX + token.parameter; + break; + case FormatToken::newline: + info->x = info->startX; + info->y += FontGetLineHeight(info->fontStyle); + break; + case FormatToken::newlineSmall: + info->x = info->startX; + info->y += FontGetLineHeightSmall(info->fontStyle); + break; + case FormatToken::fontTiny: + info->fontStyle = FontStyle::tiny; + break; + case FormatToken::fontSmall: + info->fontStyle = FontStyle::small; + break; + case FormatToken::fontMedium: + info->fontStyle = FontStyle::medium; + break; + case FormatToken::outlineEnable: + info->colourFlags.set(ColourFlag::withOutline); + break; + case FormatToken::outlineDisable: + info->colourFlags.unset(ColourFlag::withOutline); + break; + case FormatToken::colourWindow1: + { + ColourCharacterWindow(gCurrentWindowColours[0], info->colourFlags.has(ColourFlag::withOutline), info->palette); + break; + } + case FormatToken::colourWindow2: + { + ColourCharacterWindow(gCurrentWindowColours[1], info->colourFlags.has(ColourFlag::withOutline), info->palette); + break; + } + case FormatToken::colourWindow3: + { + ColourCharacterWindow(gCurrentWindowColours[2], info->colourFlags.has(ColourFlag::withOutline), info->palette); + break; + } + case FormatToken::inlineSprite: + { + auto imageId = ImageId(token.parameter); + auto g1 = GfxGetG1Element(imageId); + if (g1 != nullptr && g1->width <= 32 && g1->height <= 32) + { + if (!info->textDrawFlags.has(TextDrawFlag::noDraw)) + { + GfxDrawSprite(rt, imageId, { info->x, info->y }); + } + info->x += g1->width; + } + break; + } + default: + if (FormatTokenIsColour(token.kind)) + { + auto colourIndex = FormatTokenToTextColour(token.kind); + ColourCharacter(colourIndex, info->colourFlags.has(ColourFlag::withOutline), info->palette); + } + break; + } + } + +#ifndef DISABLE_TTF + static bool ShouldUseSpriteForCodepoint(char32_t codepoint) + { + switch (codepoint) + { + case UnicodeChar::up: + case UnicodeChar::down: + case UnicodeChar::leftguillemet: + case UnicodeChar::tick: + case UnicodeChar::cross: + case UnicodeChar::right: + case UnicodeChar::rightguillemet: + case UnicodeChar::small_up: + case UnicodeChar::small_down: + case UnicodeChar::left: + case UnicodeChar::quote_open: + case UnicodeChar::quote_close: + case UnicodeChar::german_quote_open: + case UnicodeChar::plus: + case UnicodeChar::minus: + case UnicodeChar::variation_selector: + case UnicodeChar::eye: + case UnicodeChar::road: + case UnicodeChar::railway: + return true; + default: + return false; + } + } +#endif // DISABLE_TTF + + static void TTFProcessStringLiteral(RenderTarget& rt, std::string_view text, TextDrawInfo* info) + { +#ifndef DISABLE_TTF + bool isTTF = info->textDrawFlags.has(TextDrawFlag::ttf); +#else + bool isTTF = false; +#endif // DISABLE_TTF + + if (!isTTF) + { + TTFDrawStringRawSprite(rt, text, info); + } +#ifndef DISABLE_TTF + else + { + CodepointView codepoints(text); + std::optional ttfRunIndex{}; + for (auto it = codepoints.begin(); it != codepoints.end(); it++) + { + auto codepoint = *it; + if (ShouldUseSpriteForCodepoint(codepoint)) + { + if (ttfRunIndex.has_value()) + { + // Draw the TTF run + // This error suppression abomination is here to suppress + // https://github.com/OpenRCT2/OpenRCT2/issues/17371. Additionally, we have to suppress the error for + // the error suppression... :'-( https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105937 is fixed in GCC13 + #if defined(__GNUC__) && !defined(__clang__) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" + #endif + auto len = it.GetIndex() - ttfRunIndex.value(); + TTFDrawStringRawTTF(rt, text.substr(ttfRunIndex.value(), len), info); + #if defined(__GNUC__) && !defined(__clang__) + #pragma GCC diagnostic pop + #endif + ttfRunIndex = std::nullopt; + } + + // Draw the sprite font glyph + TTFDrawCharacterSprite(rt, codepoint, info); + } + else + { + if (!ttfRunIndex.has_value()) + { + ttfRunIndex = it.GetIndex(); + } + } + } + + if (ttfRunIndex.has_value()) + { + // Final TTF run + auto len = text.size() - *ttfRunIndex; + TTFDrawStringRawTTF(rt, text.substr(ttfRunIndex.value(), len), info); + } + } +#endif // DISABLE_TTF + } + + static void TTFProcessStringCodepoint(RenderTarget& rt, codepoint_t codepoint, TextDrawInfo* info) + { + char buffer[8]{}; + UTF8WriteCodepoint(buffer, codepoint); + TTFProcessStringLiteral(rt, buffer, info); + } + + static void TTFProcessString(RenderTarget& rt, std::string_view text, TextDrawInfo* info) + { + if (info->textDrawFlags.has(TextDrawFlag::noFormatting)) + { + TTFProcessStringLiteral(rt, text, info); info->maxX = std::max(info->maxX, info->x); info->maxY = std::max(info->maxY, info->y); } - } -} - -static void TTFProcessInitialColour(ColourWithFlags colour, TextDrawInfo* info) -{ - if (colour.colour != OpenRCT2::Drawing::kColourNull) - { - info->colourFlags = colour.flags; - if (!colour.flags.has(ColourFlag::inset)) - { - ColourCharacterWindow(colour.colour, info->colourFlags.has(ColourFlag::withOutline), info->palette); - } else { - TextColours newPalette = {}; - switch (info->darkness) + FmtString fmt(text); + for (const auto& token : fmt) { - case TextDarkness::extraDark: - newPalette.fill = getColourMap(colour.colour).dark; - newPalette.shadowOutline = getColourMap(colour.colour).midLight; - break; - - case TextDarkness::dark: - newPalette.fill = getColourMap(colour.colour).midDark; - newPalette.shadowOutline = getColourMap(colour.colour).light; - break; - - case TextDarkness::regular: - newPalette.fill = getColourMap(colour.colour).midLight; - newPalette.shadowOutline = getColourMap(colour.colour).lighter; - break; + if (token.IsLiteral()) + { + TTFProcessStringLiteral(rt, token.text, info); + } + else if (token.IsCodepoint()) + { + auto codepoint = token.GetCodepoint(); + TTFProcessStringCodepoint(rt, codepoint, info); + } + else + { + TTFProcessFormatCode(rt, token, info); + } + info->maxX = std::max(info->maxX, info->x); + info->maxY = std::max(info->maxY, info->y); } - - info->palette = newPalette; } } -} -void TTFDrawString( - RenderTarget& rt, u8string_view text, ColourWithFlags colour, const ScreenCoordsXY& coords, bool noFormatting, - FontStyle fontStyle, TextDarkness darkness) -{ - TextDrawInfo info{}; - info.fontStyle = fontStyle; - info.startX = coords.x; - info.startY = coords.y; - info.x = coords.x; - info.y = coords.y; - info.darkness = darkness; - - if (LocalisationService_UseTrueTypeFont()) + static void TTFProcessInitialColour(ColourWithFlags colour, TextDrawInfo* info) { - info.textDrawFlags.set(TextDrawFlag::ttf); - } - - if (noFormatting) - { - info.textDrawFlags.set(TextDrawFlag::noFormatting); - } - - info.palette = gTextPalette; - TTFProcessInitialColour(colour, &info); - TTFProcessString(rt, text, &info); - gTextPalette = info.palette; - - rt.lastStringPos = { info.x, info.y }; -} - -static int32_t TTFGetStringWidth(std::string_view text, FontStyle fontStyle, bool noFormatting) -{ - TextDrawInfo info{}; - info.fontStyle = fontStyle; - info.startX = 0; - info.startY = 0; - info.x = 0; - info.y = 0; - info.maxX = 0; - info.maxY = 0; - - info.textDrawFlags.set(TextDrawFlag::noDraw); - if (LocalisationService_UseTrueTypeFont()) - { - info.textDrawFlags.set(TextDrawFlag::ttf); - } - - if (noFormatting) - { - info.textDrawFlags.set(TextDrawFlag::noFormatting); - } - - RenderTarget dummy{}; - TTFProcessString(dummy, text, &info); - - return info.maxX; -} - -/** - * - * rct2: 0x00682F28 - */ -void GfxDrawStringWithYOffsets( - RenderTarget& rt, const utf8* text, ColourWithFlags colour, const ScreenCoordsXY& coords, const int8_t* yOffsets, - bool forceSpriteFont, FontStyle fontStyle) -{ - TextDrawInfo info{}; - info.fontStyle = fontStyle; - info.startX = coords.x; - info.startY = coords.y; - info.x = coords.x; - info.y = coords.y; - info.yOffset = yOffsets; - - info.textDrawFlags.set(TextDrawFlag::yOffsetEffect); - - if (!forceSpriteFont && LocalisationService_UseTrueTypeFont()) - { - info.textDrawFlags.set(TextDrawFlag::ttf); - } - - info.palette = gTextPalette; - TTFProcessInitialColour(colour, &info); - TTFProcessString(rt, text, &info); - gTextPalette = info.palette; - - rt.lastStringPos = { info.x, info.y }; -} - -u8string ShortenPath(const u8string& path, int32_t availableWidth, FontStyle fontStyle) -{ - if (GfxGetStringWidth(path, fontStyle) <= availableWidth) - { - return path; - } - - u8string shortenedPath = u8"..."; - - size_t begin = 0; - while (begin < path.size()) - { - begin = path.find_first_of(*PATH_SEPARATOR, begin + 1); - if (begin == path.npos) - break; - - shortenedPath = u8"..." + path.substr(begin); - if (GfxGetStringWidth(shortenedPath, fontStyle) <= availableWidth) + if (colour.colour != OpenRCT2::Drawing::kColourNull) { - return shortenedPath; + info->colourFlags = colour.flags; + if (!colour.flags.has(ColourFlag::inset)) + { + ColourCharacterWindow(colour.colour, info->colourFlags.has(ColourFlag::withOutline), info->palette); + } + else + { + TextColours newPalette = {}; + switch (info->darkness) + { + case TextDarkness::extraDark: + newPalette.fill = getColourMap(colour.colour).dark; + newPalette.shadowOutline = getColourMap(colour.colour).midLight; + break; + + case TextDarkness::dark: + newPalette.fill = getColourMap(colour.colour).midDark; + newPalette.shadowOutline = getColourMap(colour.colour).light; + break; + + case TextDarkness::regular: + newPalette.fill = getColourMap(colour.colour).midLight; + newPalette.shadowOutline = getColourMap(colour.colour).lighter; + break; + } + + info->palette = newPalette; + } } } - return shortenedPath; -} + void TTFDrawString( + RenderTarget& rt, u8string_view text, ColourWithFlags colour, const ScreenCoordsXY& coords, bool noFormatting, + FontStyle fontStyle, TextDarkness darkness) + { + TextDrawInfo info{}; + info.fontStyle = fontStyle; + info.startX = coords.x; + info.startY = coords.y; + info.x = coords.x; + info.y = coords.y; + info.darkness = darkness; + + if (LocalisationService_UseTrueTypeFont()) + { + info.textDrawFlags.set(TextDrawFlag::ttf); + } + + if (noFormatting) + { + info.textDrawFlags.set(TextDrawFlag::noFormatting); + } + + info.palette = gTextPalette; + TTFProcessInitialColour(colour, &info); + TTFProcessString(rt, text, &info); + gTextPalette = info.palette; + + rt.lastStringPos = { info.x, info.y }; + } + + static int32_t TTFGetStringWidth(std::string_view text, FontStyle fontStyle, bool noFormatting) + { + TextDrawInfo info{}; + info.fontStyle = fontStyle; + info.startX = 0; + info.startY = 0; + info.x = 0; + info.y = 0; + info.maxX = 0; + info.maxY = 0; + + info.textDrawFlags.set(TextDrawFlag::noDraw); + if (LocalisationService_UseTrueTypeFont()) + { + info.textDrawFlags.set(TextDrawFlag::ttf); + } + + if (noFormatting) + { + info.textDrawFlags.set(TextDrawFlag::noFormatting); + } + + RenderTarget dummy{}; + TTFProcessString(dummy, text, &info); + + return info.maxX; + } + + /** + * + * rct2: 0x00682F28 + */ + void GfxDrawStringWithYOffsets( + RenderTarget& rt, const utf8* text, ColourWithFlags colour, const ScreenCoordsXY& coords, const int8_t* yOffsets, + bool forceSpriteFont, FontStyle fontStyle) + { + TextDrawInfo info{}; + info.fontStyle = fontStyle; + info.startX = coords.x; + info.startY = coords.y; + info.x = coords.x; + info.y = coords.y; + info.yOffset = yOffsets; + + info.textDrawFlags.set(TextDrawFlag::yOffsetEffect); + + if (!forceSpriteFont && LocalisationService_UseTrueTypeFont()) + { + info.textDrawFlags.set(TextDrawFlag::ttf); + } + + info.palette = gTextPalette; + TTFProcessInitialColour(colour, &info); + TTFProcessString(rt, text, &info); + gTextPalette = info.palette; + + rt.lastStringPos = { info.x, info.y }; + } + + u8string ShortenPath(const u8string& path, int32_t availableWidth, FontStyle fontStyle) + { + if (GfxGetStringWidth(path, fontStyle) <= availableWidth) + { + return path; + } + + u8string shortenedPath = u8"..."; + + size_t begin = 0; + while (begin < path.size()) + { + begin = path.find_first_of(*PATH_SEPARATOR, begin + 1); + if (begin == path.npos) + break; + + shortenedPath = u8"..." + path.substr(begin); + if (GfxGetStringWidth(shortenedPath, fontStyle) <= availableWidth) + { + return shortenedPath; + } + } + + return shortenedPath; + } +} // namespace OpenRCT2::Drawing diff --git a/src/openrct2/drawing/Drawing.String.h b/src/openrct2/drawing/Drawing.String.h index 5ee9ec277c..05f957a980 100644 --- a/src/openrct2/drawing/Drawing.String.h +++ b/src/openrct2/drawing/Drawing.String.h @@ -10,35 +10,68 @@ #pragma once #include "../core/FlagHolder.hpp" +#include "../core/StringTypes.h" #include "../interface/ColourWithFlags.h" #include "TextColour.h" #include +using StringId = uint16_t; +struct ScreenCoordsXY; + enum class FontStyle : uint8_t; enum class TextDarkness : uint8_t; -enum class TextDrawFlag : uint8_t +namespace OpenRCT2::Drawing { - noFormatting, - yOffsetEffect, - ttf, - noDraw, -}; -using TextDrawFlags = FlagHolder; + struct RenderTarget; -struct TextDrawInfo -{ - int32_t startX{}; - int32_t startY{}; - int32_t x{}; - int32_t y{}; - int32_t maxX{}; - int32_t maxY{}; - TextDrawFlags textDrawFlags{}; - OpenRCT2::ColourFlags colourFlags{}; - TextDarkness darkness{}; - OpenRCT2::Drawing::TextColours palette{}; - FontStyle fontStyle{}; - const int8_t* yOffset{}; -}; + enum class TextDrawFlag : uint8_t + { + noFormatting, + yOffsetEffect, + ttf, + noDraw, + }; + using TextDrawFlags = FlagHolder; + + struct TextDrawInfo + { + int32_t startX{}; + int32_t startY{}; + int32_t x{}; + int32_t y{}; + int32_t maxX{}; + int32_t maxY{}; + TextDrawFlags textDrawFlags{}; + OpenRCT2::ColourFlags colourFlags{}; + TextDarkness darkness{}; + TextColours palette{}; + FontStyle fontStyle{}; + const int8_t* yOffset{}; + }; + + void GfxDrawStringLeftCentred( + RenderTarget& rt, StringId format, void* args, ColourWithFlags colour, const ScreenCoordsXY& coords); + void DrawStringCentredRaw( + RenderTarget& rt, const ScreenCoordsXY& coords, int32_t numLines, const utf8* text, FontStyle fontStyle); + void DrawNewsTicker( + RenderTarget& rt, const ScreenCoordsXY& coords, int32_t width, Colour colour, StringId format, u8string_view args, + int32_t ticks); + void GfxDrawStringWithYOffsets( + RenderTarget& rt, const utf8* text, ColourWithFlags colour, const ScreenCoordsXY& coords, const int8_t* yOffsets, + bool forceSpriteFont, FontStyle fontStyle); + + int32_t GfxWrapString( + u8string_view text, int32_t width, FontStyle fontStyle, u8string* outWrappedText, int32_t* outNumLines); + int32_t GfxGetStringWidth(std::string_view text, FontStyle fontStyle); + int32_t GfxGetStringWidthNewLined(std::string_view text, FontStyle fontStyle); + int32_t GfxGetStringWidthNoFormatting(std::string_view text, FontStyle fontStyle); + int32_t StringGetHeightRaw(std::string_view text, FontStyle fontStyle); + int32_t GfxClipString(char* buffer, int32_t width, FontStyle fontStyle); + u8string ShortenPath(const u8string& path, int32_t availableWidth, FontStyle fontStyle); + void TTFDrawString( + RenderTarget& rt, u8string_view text, ColourWithFlags colour, const ScreenCoordsXY& coords, bool noFormatting, + FontStyle fontStyle, TextDarkness darkness); + +} // namespace OpenRCT2::Drawing diff --git a/src/openrct2/drawing/Drawing.h b/src/openrct2/drawing/Drawing.h index c9f29ac517..fedc6f1d41 100644 --- a/src/openrct2/drawing/Drawing.h +++ b/src/openrct2/drawing/Drawing.h @@ -106,29 +106,6 @@ void FASTCALL GfxDrawSpriteSolid( void FASTCALL GfxDrawSpriteRawMasked( OpenRCT2::Drawing::RenderTarget& rt, const ScreenCoordsXY& coords, ImageId maskImage, ImageId colourImage); -// string -void GfxDrawStringLeftCentred( - OpenRCT2::Drawing::RenderTarget& rt, StringId format, void* args, ColourWithFlags colour, const ScreenCoordsXY& coords); -void DrawStringCentredRaw( - OpenRCT2::Drawing::RenderTarget& rt, const ScreenCoordsXY& coords, int32_t numLines, const utf8* text, FontStyle fontStyle); -void DrawNewsTicker( - OpenRCT2::Drawing::RenderTarget& rt, const ScreenCoordsXY& coords, int32_t width, OpenRCT2::Drawing::Colour colour, - StringId format, u8string_view args, int32_t ticks); -void GfxDrawStringWithYOffsets( - OpenRCT2::Drawing::RenderTarget& rt, const utf8* text, ColourWithFlags colour, const ScreenCoordsXY& coords, - const int8_t* yOffsets, bool forceSpriteFont, FontStyle fontStyle); - -int32_t GfxWrapString(u8string_view text, int32_t width, FontStyle fontStyle, u8string* outWrappedText, int32_t* outNumLines); -int32_t GfxGetStringWidth(std::string_view text, FontStyle fontStyle); -int32_t GfxGetStringWidthNewLined(std::string_view text, FontStyle fontStyle); -int32_t GfxGetStringWidthNoFormatting(std::string_view text, FontStyle fontStyle); -int32_t StringGetHeightRaw(std::string_view text, FontStyle fontStyle); -int32_t GfxClipString(char* buffer, int32_t width, FontStyle fontStyle); -u8string ShortenPath(const u8string& path, int32_t availableWidth, FontStyle fontStyle); -void TTFDrawString( - OpenRCT2::Drawing::RenderTarget& rt, u8string_view text, ColourWithFlags colour, const ScreenCoordsXY& coords, - bool noFormatting, FontStyle fontStyle, TextDarkness darkness); - void MaskSse4_1( int32_t width, int32_t height, const uint8_t* RESTRICT maskSrc, const uint8_t* RESTRICT colourSrc, OpenRCT2::Drawing::PaletteIndex* RESTRICT dst, int32_t maskWrap, int32_t colourWrap, int32_t dstWrap); diff --git a/src/openrct2/drawing/IDrawingContext.h b/src/openrct2/drawing/IDrawingContext.h index e42ce4e6c8..e6bc3296e3 100644 --- a/src/openrct2/drawing/IDrawingContext.h +++ b/src/openrct2/drawing/IDrawingContext.h @@ -14,13 +14,12 @@ #include "PaletteIndex.h" #include "TTF.h" -struct TextDrawInfo; - namespace OpenRCT2::Drawing { struct IDrawingEngine; struct PaletteMap; struct RenderTarget; + struct TextDrawInfo; struct IDrawingContext { diff --git a/src/openrct2/drawing/ScrollingText.cpp b/src/openrct2/drawing/ScrollingText.cpp index 43a4b85a75..af7790eb5b 100644 --- a/src/openrct2/drawing/ScrollingText.cpp +++ b/src/openrct2/drawing/ScrollingText.cpp @@ -20,6 +20,7 @@ #include "../localisation/LocalisationService.h" #include "../paint/Paint.h" #include "BlendColourMap.h" +#include "Drawing.String.h" #include "Drawing.h" #include "TTF.h" diff --git a/src/openrct2/drawing/Text.cpp b/src/openrct2/drawing/Text.cpp index 46dd993c3c..62cb5c5a59 100644 --- a/src/openrct2/drawing/Text.cpp +++ b/src/openrct2/drawing/Text.cpp @@ -14,6 +14,7 @@ #include "../localisation/Formatter.h" #include "../localisation/Formatting.h" #include "../localisation/Language.h" +#include "Drawing.String.h" #include "Drawing.h" using namespace OpenRCT2; diff --git a/src/openrct2/drawing/X8DrawingEngine.h b/src/openrct2/drawing/X8DrawingEngine.h index dfb8d5116e..553fda1596 100644 --- a/src/openrct2/drawing/X8DrawingEngine.h +++ b/src/openrct2/drawing/X8DrawingEngine.h @@ -16,8 +16,6 @@ #include -struct TextDrawInfo; - namespace OpenRCT2 { namespace Ui @@ -27,6 +25,7 @@ namespace OpenRCT2 namespace Drawing { + struct TextDrawInfo; class X8DrawingContext; class X8WeatherDrawer final : public IWeatherDrawer diff --git a/src/openrct2/entity/MoneyEffect.cpp b/src/openrct2/entity/MoneyEffect.cpp index d8129cd112..898aa36493 100644 --- a/src/openrct2/entity/MoneyEffect.cpp +++ b/src/openrct2/entity/MoneyEffect.cpp @@ -14,6 +14,7 @@ #include "../OpenRCT2.h" #include "../config/Config.h" #include "../core/DataSerialiser.h" +#include "../drawing/Drawing.String.h" #include "../drawing/Drawing.h" #include "../interface/Viewport.h" #include "../interface/Window.h" @@ -108,7 +109,7 @@ namespace OpenRCT2 auto [stringId, newValue] = GetStringId(); char buffer[128]; FormatStringLegacy(buffer, 128, stringId, &newValue); - offsetX = -(GfxGetStringWidth(buffer, FontStyle::medium) / 2); + offsetX = -(Drawing::GfxGetStringWidth(buffer, FontStyle::medium) / 2); } OffsetX = offsetX; Wiggle = 0; diff --git a/src/openrct2/interface/Chat.cpp b/src/openrct2/interface/Chat.cpp index f1338108dd..1599a306f5 100644 --- a/src/openrct2/interface/Chat.cpp +++ b/src/openrct2/interface/Chat.cpp @@ -14,6 +14,7 @@ #include "../audio/Audio.h" #include "../audio/AudioMixer.h" #include "../core/UTF8.h" +#include "../drawing/Drawing.String.h" #include "../drawing/Drawing.h" #include "../drawing/Rectangle.h" #include "../drawing/Text.h" diff --git a/src/openrct2/paint/Paint.cpp b/src/openrct2/paint/Paint.cpp index 20f9271fe3..685712a32b 100644 --- a/src/openrct2/paint/Paint.cpp +++ b/src/openrct2/paint/Paint.cpp @@ -14,6 +14,7 @@ #include "../core/Guard.hpp" #include "../core/Money.hpp" #include "../core/Numerics.hpp" +#include "../drawing/Drawing.String.h" #include "../drawing/Drawing.h" #include "../interface/Viewport.h" #include "../localisation/Currency.h" diff --git a/src/openrct2/paint/Painter.cpp b/src/openrct2/paint/Painter.cpp index b2ee660c53..1882c1a3f2 100644 --- a/src/openrct2/paint/Painter.cpp +++ b/src/openrct2/paint/Painter.cpp @@ -14,6 +14,7 @@ #include "../ReplayManager.h" #include "../config/Config.h" #include "../core/Guard.hpp" +#include "../drawing/Drawing.String.h" #include "../drawing/Drawing.h" #include "../drawing/IDrawingEngine.h" #include "../drawing/Text.h"