From 826f6c7442d0486ce3fe489fe6295eeedb79ef56 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sat, 27 Feb 2021 17:43:23 +0100 Subject: [PATCH] Reduce usage of gCurrentFontSpriteBase --- src/openrct2-ui/interface/Widget.cpp | 5 ++--- src/openrct2-ui/windows/Error.cpp | 3 +-- src/openrct2-ui/windows/Multiplayer.cpp | 5 ++--- src/openrct2-ui/windows/News.cpp | 4 ++-- src/openrct2-ui/windows/TextInput.cpp | 6 ++---- src/openrct2-ui/windows/Tooltip.cpp | 3 +-- src/openrct2/drawing/Drawing.String.cpp | 16 ++++++---------- src/openrct2/drawing/Drawing.h | 4 ++-- src/openrct2/drawing/Text.cpp | 6 ++---- src/openrct2/interface/Chat.cpp | 10 ++++------ 10 files changed, 24 insertions(+), 38 deletions(-) diff --git a/src/openrct2-ui/interface/Widget.cpp b/src/openrct2-ui/interface/Widget.cpp index 0005d6fae3..684dbf8653 100644 --- a/src/openrct2-ui/interface/Widget.cpp +++ b/src/openrct2-ui/interface/Widget.cpp @@ -1087,7 +1087,6 @@ void WidgetSetCheckboxValue(rct_window* w, rct_widgetindex widgetIndex, int32_t static void WidgetTextBoxDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex) { int32_t no_lines = 0; - FontSpriteBase font_height = FontSpriteBase::SMALL; char wrapped_string[TEXT_INPUT_SIZE]; // Get the widget @@ -1116,7 +1115,7 @@ static void WidgetTextBoxDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgeti if (w->widgets[widgetIndex].text != 0) { safe_strcpy(wrapped_string, w->widgets[widgetIndex].string, 512); - gfx_wrap_string(wrapped_string, bottomRight.x - topLeft.x - 5, &no_lines, &font_height); + gfx_wrap_string(wrapped_string, bottomRight.x - topLeft.x - 5, &no_lines); gfx_draw_string_no_formatting(dpi, wrapped_string, w->colours[1], { topLeft.x + 2, topLeft.y }); } return; @@ -1126,7 +1125,7 @@ static void WidgetTextBoxDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgeti // String length needs to add 12 either side of box // +13 for cursor when max length. - gfx_wrap_string(wrapped_string, bottomRight.x - topLeft.x - 5 - 6, &no_lines, &font_height); + gfx_wrap_string(wrapped_string, bottomRight.x - topLeft.x - 5 - 6, &no_lines); gfx_draw_string_no_formatting(dpi, wrapped_string, w->colours[1], { topLeft.x + 2, topLeft.y }); diff --git a/src/openrct2-ui/windows/Error.cpp b/src/openrct2-ui/windows/Error.cpp index 1281f6f9ce..de7ae68677 100644 --- a/src/openrct2-ui/windows/Error.cpp +++ b/src/openrct2-ui/windows/Error.cpp @@ -57,7 +57,6 @@ rct_window* window_error_open(rct_string_id title, rct_string_id message, const rct_window* window_error_open(std::string_view title, std::string_view message) { int32_t numLines, width, height, maxY; - FontSpriteBase fontHeight; rct_window* w; window_close_by_class(WC_ERROR); @@ -89,7 +88,7 @@ rct_window* window_error_open(std::string_view title, std::string_view message) width = std::clamp(width, 64, 196); gCurrentFontSpriteBase = FontSpriteBase::MEDIUM; - gfx_wrap_string(buffer.data(), width + 1, &numLines, &fontHeight); + gfx_wrap_string(buffer.data(), width + 1, &numLines); _window_error_num_lines = numLines; width = width + 3; diff --git a/src/openrct2-ui/windows/Multiplayer.cpp b/src/openrct2-ui/windows/Multiplayer.cpp index 9624fbc519..4f77bafcb8 100644 --- a/src/openrct2-ui/windows/Multiplayer.cpp +++ b/src/openrct2-ui/windows/Multiplayer.cpp @@ -344,12 +344,11 @@ static ScreenCoordsXY window_multiplayer_information_get_size() const int32_t width = 450; int32_t height = 55; int32_t numLines; - FontSpriteBase fontSpriteBase; // Server name is displayed word-wrapped, so figure out how high it will be. { utf8* buffer = _strdup(network_get_server_name()); - gfx_wrap_string(buffer, width, &numLines, &fontSpriteBase); + gfx_wrap_string(buffer, width, &numLines); free(buffer); height += ++numLines * lineHeight + (LIST_ROW_HEIGHT / 2); } @@ -359,7 +358,7 @@ static ScreenCoordsXY window_multiplayer_information_get_size() if (!str_is_null_or_empty(descString)) { utf8* buffer = _strdup(descString); - gfx_wrap_string(buffer, width, &numLines, &fontSpriteBase); + gfx_wrap_string(buffer, width, &numLines); free(buffer); height += ++numLines * lineHeight + (LIST_ROW_HEIGHT / 2); } diff --git a/src/openrct2-ui/windows/News.cpp b/src/openrct2-ui/windows/News.cpp index 71553c13f9..0171c6fe1a 100644 --- a/src/openrct2-ui/windows/News.cpp +++ b/src/openrct2-ui/windows/News.cpp @@ -92,7 +92,7 @@ rct_window* window_news_open() static int32_t window_news_get_item_height() { - return 4 * font_get_line_height(gCurrentFontSpriteBase) + 2; + return 4 * font_get_line_height(FontSpriteBase::SMALL) + 2; } /** @@ -218,7 +218,7 @@ static void window_news_paint(rct_window* w, rct_drawpixelinfo* dpi) */ static void window_news_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, int32_t scrollIndex) { - int32_t lineHeight = font_get_line_height(gCurrentFontSpriteBase); + int32_t lineHeight = font_get_line_height(FontSpriteBase::SMALL); int32_t itemHeight = window_news_get_item_height(); int32_t y = 0; diff --git a/src/openrct2-ui/windows/TextInput.cpp b/src/openrct2-ui/windows/TextInput.cpp index 4cb0537d3b..11261fa7dd 100644 --- a/src/openrct2-ui/windows/TextInput.cpp +++ b/src/openrct2-ui/windows/TextInput.cpp @@ -199,7 +199,6 @@ public: screenCoords.y = windowPos.y + 25; int32_t no_lines = 0; - FontSpriteBase font_height = FontSpriteBase::SMALL; if (_descriptionStringId == STR_NONE) { @@ -223,7 +222,7 @@ public: // String length needs to add 12 either side of box // +13 for cursor when max length. - gfx_wrap_string(wrapped_string, WW - (24 + 13), &no_lines, &font_height); + gfx_wrap_string(wrapped_string, WW - (24 + 13), &no_lines); gfx_fill_rect_inset( &dpi, { { windowPos.x + 10, screenCoords.y }, { windowPos.x + WW - 10, screenCoords.y + 10 * (no_lines + 1) + 3 } }, @@ -310,8 +309,7 @@ public: // String length needs to add 12 either side of box +13 for cursor when max length. int32_t numLines{}; - FontSpriteBase fontHeight = FontSpriteBase::SMALL; - gfx_wrap_string(wrappedString.data(), WW - (24 + 13), &numLines, &fontHeight); + gfx_wrap_string(wrappedString.data(), WW - (24 + 13), &numLines); return numLines * 10 + WH; } diff --git a/src/openrct2-ui/windows/Tooltip.cpp b/src/openrct2-ui/windows/Tooltip.cpp index c7df4d8c84..c620a08540 100644 --- a/src/openrct2-ui/windows/Tooltip.cpp +++ b/src/openrct2-ui/windows/Tooltip.cpp @@ -64,8 +64,7 @@ static int32_t FormatTextForTooltip(const OpenRCT2String& message) gCurrentFontSpriteBase = FontSpriteBase::MEDIUM; int32_t numLines; - FontSpriteBase fontSpriteBase; - textWidth = gfx_wrap_string(_tooltipText, textWidth + 1, &numLines, &fontSpriteBase); + textWidth = gfx_wrap_string(_tooltipText, textWidth + 1, &numLines); _tooltipNumLines = numLines; return textWidth; } diff --git a/src/openrct2/drawing/Drawing.String.cpp b/src/openrct2/drawing/Drawing.String.cpp index d739f2e111..53a21ff31c 100644 --- a/src/openrct2/drawing/Drawing.String.cpp +++ b/src/openrct2/drawing/Drawing.String.cpp @@ -170,7 +170,7 @@ int32_t gfx_clip_string(utf8* text, int32_t width) * num_lines (edi) - out * font_height (ebx) - out */ -int32_t gfx_wrap_string(utf8* text, int32_t width, int32_t* outNumLines, FontSpriteBase* outFontHeight) +int32_t gfx_wrap_string(utf8* text, int32_t width, int32_t* outNumLines) { constexpr size_t NULL_INDEX = std::numeric_limits::max(); thread_local std::string buffer; @@ -259,7 +259,6 @@ int32_t gfx_wrap_string(utf8* text, int32_t width, int32_t* outNumLines, FontSpr std::memcpy(text, buffer.data(), buffer.size() + 1); *outNumLines = static_cast(numLines); - *outFontHeight = gCurrentFontSpriteBase; return maxWidth; } @@ -272,7 +271,7 @@ void gfx_draw_string_left_centred( gCurrentFontSpriteBase = FontSpriteBase::MEDIUM; char* buffer = gCommonStringFormatBuffer; format_string(buffer, 256, format, args); - int32_t height = string_get_height_raw(buffer); + int32_t height = string_get_height_raw(buffer, FontSpriteBase::MEDIUM); gfx_draw_string(dpi, buffer, colour, coords - ScreenCoordsXY{ 0, (height / 2) }); } @@ -352,14 +351,12 @@ void draw_string_centred_raw(rct_drawpixelinfo* dpi, const ScreenCoordsXY& coord } text = const_cast(ch + 1); - screenCoords.y += font_get_line_height(gCurrentFontSpriteBase); + screenCoords.y += font_get_line_height(FontSpriteBase::MEDIUM); } } -int32_t string_get_height_raw(std::string_view text) +int32_t string_get_height_raw(std::string_view text, FontSpriteBase fontBase) { - auto fontBase = gCurrentFontSpriteBase; - int32_t height = 0; if (fontBase <= FontSpriteBase::MEDIUM) height += 10; @@ -431,7 +428,6 @@ void gfx_draw_string_centred_wrapped_partial( int32_t ticks) { int32_t numLines, lineHeight, lineY; - FontSpriteBase fontSpriteBase; utf8* buffer = gCommonStringFormatBuffer; ScreenCoordsXY screenCoords(dpi->x, dpi->y); @@ -440,8 +436,8 @@ void gfx_draw_string_centred_wrapped_partial( format_string(buffer, 256, format, args); gCurrentFontSpriteBase = FontSpriteBase::MEDIUM; - gfx_wrap_string(buffer, width, &numLines, &fontSpriteBase); - lineHeight = font_get_line_height(fontSpriteBase); + gfx_wrap_string(buffer, width, &numLines); + lineHeight = font_get_line_height(FontSpriteBase::MEDIUM); int32_t numCharactersDrawn = 0; int32_t numCharactersToDraw = ticks; diff --git a/src/openrct2/drawing/Drawing.h b/src/openrct2/drawing/Drawing.h index 56929b4265..b14c43495a 100644 --- a/src/openrct2/drawing/Drawing.h +++ b/src/openrct2/drawing/Drawing.h @@ -749,11 +749,11 @@ void gfx_draw_string_with_y_offsets( rct_drawpixelinfo* dpi, const utf8* text, int32_t colour, const ScreenCoordsXY& coords, const int8_t* yOffsets, bool forceSpriteFont); -int32_t gfx_wrap_string(char* buffer, int32_t width, int32_t* num_lines, FontSpriteBase* font_height); +int32_t gfx_wrap_string(char* buffer, int32_t width, int32_t* num_lines); int32_t gfx_get_string_width(std::string_view text); int32_t gfx_get_string_width_new_lined(std::string_view text); int32_t gfx_get_string_width_no_formatting(std::string_view text); -int32_t string_get_height_raw(std::string_view text); +int32_t string_get_height_raw(std::string_view text, FontSpriteBase fontBase); int32_t gfx_clip_string(char* buffer, int32_t width); void shorten_path(utf8* buffer, size_t bufferSize, const utf8* path, int32_t availableWidth); void ttf_draw_string( diff --git a/src/openrct2/drawing/Text.cpp b/src/openrct2/drawing/Text.cpp index a887a9fee3..d7d6532d86 100644 --- a/src/openrct2/drawing/Text.cpp +++ b/src/openrct2/drawing/Text.cpp @@ -23,12 +23,10 @@ StaticLayout::StaticLayout(utf8string source, const TextPaint& paint, int32_t wi Buffer = source; Paint = paint; - FontSpriteBase fontSpriteBase; - gCurrentFontSpriteBase = paint.SpriteBase; - MaxWidth = gfx_wrap_string(Buffer, width, &LineCount, &fontSpriteBase); + MaxWidth = gfx_wrap_string(Buffer, width, &LineCount); LineCount += 1; - LineHeight = font_get_line_height(fontSpriteBase); + LineHeight = font_get_line_height(gCurrentFontSpriteBase); } void StaticLayout::Draw(rct_drawpixelinfo* dpi, const ScreenCoordsXY& coords) diff --git a/src/openrct2/interface/Chat.cpp b/src/openrct2/interface/Chat.cpp index 4c8c80493c..9af4d47af0 100644 --- a/src/openrct2/interface/Chat.cpp +++ b/src/openrct2/interface/Chat.cpp @@ -275,10 +275,9 @@ static int32_t chat_history_draw_string( FormatStringToBuffer(gCommonStringFormatBuffer, sizeof(gCommonStringFormatBuffer), "{OUTLINE}{WHITE}{STRING}", text); int32_t numLines; - FontSpriteBase fontSpriteBase; gCurrentFontSpriteBase = FontSpriteBase::MEDIUM; - gfx_wrap_string(buffer, width, &numLines, &fontSpriteBase); - auto lineHeight = font_get_line_height(fontSpriteBase); + gfx_wrap_string(buffer, width, &numLines); + auto lineHeight = font_get_line_height(FontSpriteBase::MEDIUM); int32_t expectedY = screenCoords.y - (numLines * lineHeight); if (expectedY < 50) @@ -301,7 +300,6 @@ static int32_t chat_history_draw_string( int32_t chat_string_wrapped_get_height(void* args, int32_t width) { int32_t lineHeight, lineY, numLines; - FontSpriteBase fontSpriteBase; gCurrentFontSpriteBase = FontSpriteBase::MEDIUM; @@ -309,8 +307,8 @@ int32_t chat_string_wrapped_get_height(void* args, int32_t width) format_string(buffer, 256, STR_STRING, args); gCurrentFontSpriteBase = FontSpriteBase::MEDIUM; - gfx_wrap_string(buffer, width, &numLines, &fontSpriteBase); - lineHeight = font_get_line_height(fontSpriteBase); + gfx_wrap_string(buffer, width, &numLines); + lineHeight = font_get_line_height(FontSpriteBase::MEDIUM); lineY = 0; for (int32_t line = 0; line <= numLines; ++line)