Reduce usage of gCurrentFontSpriteBase

This commit is contained in:
Gymnasiast 2021-02-27 17:43:23 +01:00
parent 3e536e2711
commit 826f6c7442
No known key found for this signature in database
GPG key ID: DBFFF47AB2CA3EDD
10 changed files with 24 additions and 38 deletions

View file

@ -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 });

View file

@ -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;

View file

@ -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);
}

View file

@ -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;

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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<size_t>::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<int32_t>(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<char*>(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;

View file

@ -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(

View file

@ -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)

View file

@ -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)