From 9ca941220588829c53742646440cef58a94e6209 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Wed, 12 Oct 2022 18:27:05 +0200 Subject: [PATCH 1/2] Refactor Dark/ExtraDark into its own structure --- .../windows/EditorInventionsList.cpp | 11 +++++---- .../windows/EditorObjectSelection.cpp | 15 ++++++------ .../windows/EditorObjectiveOptions.cpp | 5 ++-- src/openrct2-ui/windows/ScenarioSelect.cpp | 6 +++-- src/openrct2-ui/windows/Themes.cpp | 2 +- src/openrct2/drawing/Drawing.String.cpp | 23 +++++++++---------- src/openrct2/drawing/Drawing.h | 2 +- src/openrct2/drawing/Font.cpp | 5 ---- src/openrct2/drawing/Font.h | 3 --- src/openrct2/drawing/Text.cpp | 2 +- src/openrct2/drawing/Text.h | 21 +++++++++++++++++ 11 files changed, 55 insertions(+), 40 deletions(-) diff --git a/src/openrct2-ui/windows/EditorInventionsList.cpp b/src/openrct2-ui/windows/EditorInventionsList.cpp index 34e28960a2..3befe9ba53 100644 --- a/src/openrct2-ui/windows/EditorInventionsList.cpp +++ b/src/openrct2-ui/windows/EditorInventionsList.cpp @@ -295,13 +295,14 @@ public: // It needs a {BLACK} token in the string to work properly. colour_t colour = COLOUR_BLACK; FontSpriteBase fontSpriteBase = FontSpriteBase::MEDIUM; + auto darkness = TextDarkness::Regular; if (researchItem.IsAlwaysResearched()) { if (_selectedResearchItem == &researchItem && dragItem == nullptr) - fontSpriteBase = FontSpriteBase::MEDIUM_EXTRA_DARK; + darkness = TextDarkness::ExtraDark; else - fontSpriteBase = FontSpriteBase::MEDIUM_DARK; + darkness = TextDarkness::Dark; colour = colours[1] | COLOUR_FLAG_INSET; } @@ -318,21 +319,21 @@ public: ft.Add(rideTypeName); DrawTextEllipsised( &dpi, { 1, itemY }, columnSplitOffset - 11, STR_INVENTIONS_LIST_RIDE_AND_VEHICLE_NAME, ft, - { colour, fontSpriteBase }); + { colour, fontSpriteBase, darkness }); // Draw vehicle name ft = Formatter(); ft.Add(itemNameId); DrawTextEllipsised( &dpi, { columnSplitOffset + 1, itemY }, columnSplitOffset - 11, STR_BLACK_STRING, ft, - { colour, fontSpriteBase }); + { colour, fontSpriteBase, darkness }); } else { // Scenery group, flat ride or shop auto ft = Formatter(); ft.Add(itemNameId); - DrawTextEllipsised(&dpi, { 1, itemY }, boxWidth, STR_BLACK_STRING, ft, { colour, fontSpriteBase }); + DrawTextEllipsised(&dpi, { 1, itemY }, boxWidth, STR_BLACK_STRING, ft, { colour, fontSpriteBase, darkness }); } } } diff --git a/src/openrct2-ui/windows/EditorObjectSelection.cpp b/src/openrct2-ui/windows/EditorObjectSelection.cpp index fba7befd4f..e7276f40cb 100644 --- a/src/openrct2-ui/windows/EditorObjectSelection.cpp +++ b/src/openrct2-ui/windows/EditorObjectSelection.cpp @@ -721,15 +721,14 @@ public: if (!(gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER) && (*listItem.flags & ObjectSelectionFlags::Selected)) { screenCoords.x = 2; - FontSpriteBase fontSpriteBase = highlighted ? FontSpriteBase::MEDIUM_EXTRA_DARK - : FontSpriteBase::MEDIUM_DARK; + auto darkness = highlighted ? TextDarkness::ExtraDark : TextDarkness::Dark; colour_t colour2 = NOT_TRANSLUCENT(colours[1]); if (*listItem.flags & (ObjectSelectionFlags::InUse | ObjectSelectionFlags::AlwaysRequired)) colour2 |= COLOUR_FLAG_INSET; gfx_draw_string( &dpi, screenCoords, static_cast(CheckBoxMarkString), - { static_cast(colour2), fontSpriteBase }); + { static_cast(colour2), FontSpriteBase::MEDIUM, darkness }); } screenCoords.x = gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER ? 0 : 15; @@ -738,11 +737,11 @@ public: auto buffer = strchr(bufferWithColour, '\0'); colour_t colour = COLOUR_BLACK; - FontSpriteBase fontSpriteBase = FontSpriteBase::MEDIUM; + auto darkness = TextDarkness::Regular; if (*listItem.flags & ObjectSelectionFlags::Flag6) { colour = colours[1] & 0x7F; - fontSpriteBase = FontSpriteBase::MEDIUM_DARK; + darkness = TextDarkness::Dark; } int32_t width_limit = widgets[WIDX_LIST].width() - screenCoords.x; @@ -755,7 +754,8 @@ public: safe_strcpy(buffer, language_get_string(rideTypeStringId), 256 - (buffer - bufferWithColour)); auto ft = Formatter(); ft.Add(gCommonStringFormatBuffer); - DrawTextEllipsised(&dpi, screenCoords, width_limit - 15, STR_STRING, ft, { colour, fontSpriteBase }); + DrawTextEllipsised( + &dpi, screenCoords, width_limit - 15, STR_STRING, ft, { colour, FontSpriteBase::MEDIUM, darkness }); screenCoords.x = widgets[WIDX_LIST_SORT_RIDE].left - widgets[WIDX_LIST].left; } @@ -770,7 +770,8 @@ public: } auto ft = Formatter(); ft.Add(gCommonStringFormatBuffer); - DrawTextEllipsised(&dpi, screenCoords, width_limit, STR_STRING, ft, { colour, fontSpriteBase }); + DrawTextEllipsised( + &dpi, screenCoords, width_limit, STR_STRING, ft, { colour, FontSpriteBase::MEDIUM, darkness }); } screenCoords.y += SCROLLABLE_ROW_HEIGHT; } diff --git a/src/openrct2-ui/windows/EditorObjectiveOptions.cpp b/src/openrct2-ui/windows/EditorObjectiveOptions.cpp index a4f1355dfe..7714f04ab9 100644 --- a/src/openrct2-ui/windows/EditorObjectiveOptions.cpp +++ b/src/openrct2-ui/windows/EditorObjectiveOptions.cpp @@ -1084,11 +1084,10 @@ static void WindowEditorObjectiveOptionsRidesScrollpaint(rct_window* w, rct_draw { if (ride->lifecycle_flags & RIDE_LIFECYCLE_INDESTRUCTIBLE) { - FontSpriteBase fontSpriteBase = stringId == STR_WINDOW_COLOUR_2_STRINGID ? FontSpriteBase::MEDIUM_EXTRA_DARK - : FontSpriteBase::MEDIUM_DARK; + auto darkness = stringId == STR_WINDOW_COLOUR_2_STRINGID ? TextDarkness::ExtraDark : TextDarkness::Dark; gfx_draw_string( dpi, { 2, y }, static_cast(CheckBoxMarkString), - { static_cast(w->colours[1] & 0x7F), fontSpriteBase }); + { static_cast(w->colours[1] & 0x7F), FontSpriteBase::MEDIUM, darkness }); } // Ride name diff --git a/src/openrct2-ui/windows/ScenarioSelect.cpp b/src/openrct2-ui/windows/ScenarioSelect.cpp index aa64c4c870..9a9c6c6b56 100644 --- a/src/openrct2-ui/windows/ScenarioSelect.cpp +++ b/src/openrct2-ui/windows/ScenarioSelect.cpp @@ -613,10 +613,12 @@ static void WindowScenarioselectScrollpaint(rct_window* w, rct_drawpixelinfo* dp ft.Add(STR_STRING); ft.Add(buffer); colour_t colour = isDisabled ? w->colours[1] | COLOUR_FLAG_INSET : COLOUR_BLACK; - FontSpriteBase fontSpriteBase = isDisabled ? FontSpriteBase::MEDIUM_DARK : FontSpriteBase::MEDIUM; + auto darkness = isDisabled ? TextDarkness::Dark : TextDarkness::Regular; const auto scrollCentre = window_scenarioselect_widgets[WIDX_SCENARIOLIST].width() / 2; - DrawTextBasic(dpi, { scrollCentre, y + 1 }, format, ft, { colour, fontSpriteBase, TextAlignment::CENTRE }); + DrawTextBasic( + dpi, { scrollCentre, y + 1 }, format, ft, + { colour, FontSpriteBase::MEDIUM, TextAlignment::CENTRE, darkness }); // Check if scenario is completed if (isCompleted) diff --git a/src/openrct2-ui/windows/Themes.cpp b/src/openrct2-ui/windows/Themes.cpp index a3ae54fb12..1a5ea60b2e 100644 --- a/src/openrct2-ui/windows/Themes.cpp +++ b/src/openrct2-ui/windows/Themes.cpp @@ -823,7 +823,7 @@ public: { gfx_draw_string( &dpi, topLeft, static_cast(CheckBoxMarkString), - { static_cast(colours[1] & 0x7F), FontSpriteBase::MEDIUM_DARK }); + { static_cast(colours[1] & 0x7F), FontSpriteBase::MEDIUM, TextDarkness::Dark }); } } } diff --git a/src/openrct2/drawing/Drawing.String.cpp b/src/openrct2/drawing/Drawing.String.cpp index fd0bc9a4c1..284b7fc94c 100644 --- a/src/openrct2/drawing/Drawing.String.cpp +++ b/src/openrct2/drawing/Drawing.String.cpp @@ -917,17 +917,7 @@ static void ttf_process_initial_colour(int32_t colour, text_draw_info* info) { if (colour != TEXT_COLOUR_254 && colour != TEXT_COLOUR_255) { - info->flags &= ~(TEXT_DRAW_FLAG_INSET | TEXT_DRAW_FLAG_OUTLINE | TEXT_DRAW_FLAG_DARK | TEXT_DRAW_FLAG_EXTRA_DARK); - if (info->font_sprite_base == FontSpriteBase::MEDIUM_DARK - || info->font_sprite_base == FontSpriteBase::MEDIUM_EXTRA_DARK) - { - info->flags |= TEXT_DRAW_FLAG_DARK; - if (info->font_sprite_base == FontSpriteBase::MEDIUM_EXTRA_DARK) - { - info->flags |= TEXT_DRAW_FLAG_EXTRA_DARK; - } - info->font_sprite_base = FontSpriteBase::MEDIUM; - } + info->flags &= ~(TEXT_DRAW_FLAG_INSET | TEXT_DRAW_FLAG_OUTLINE); if (colour & COLOUR_FLAG_OUTLINE) { info->flags |= TEXT_DRAW_FLAG_OUTLINE; @@ -980,7 +970,7 @@ static void ttf_process_initial_colour(int32_t colour, text_draw_info* info) void ttf_draw_string( rct_drawpixelinfo* dpi, const_utf8string text, int32_t colour, const ScreenCoordsXY& coords, bool noFormatting, - FontSpriteBase fontSpriteBase) + FontSpriteBase fontSpriteBase, TextDarkness darkness) { if (text == nullptr) return; @@ -1003,6 +993,15 @@ void ttf_draw_string( info.flags |= TEXT_DRAW_FLAG_NO_FORMATTING; } + if (darkness == TextDarkness::Dark) + { + info.flags |= TEXT_DRAW_FLAG_DARK; + } + else if (darkness == TextDarkness::ExtraDark) + { + info.flags |= (TEXT_DRAW_FLAG_DARK | TEXT_DRAW_FLAG_EXTRA_DARK); + } + std::memcpy(info.palette, gTextPalette, sizeof(info.palette)); ttf_process_initial_colour(colour, &info); ttf_process_string(dpi, text, &info); diff --git a/src/openrct2/drawing/Drawing.h b/src/openrct2/drawing/Drawing.h index 11d54dac20..3ca8103ea8 100644 --- a/src/openrct2/drawing/Drawing.h +++ b/src/openrct2/drawing/Drawing.h @@ -562,7 +562,7 @@ int32_t gfx_clip_string(char* buffer, int32_t width, FontSpriteBase fontSpriteBa void shorten_path(utf8* buffer, size_t bufferSize, const utf8* path, int32_t availableWidth, FontSpriteBase fontSpriteBase); void ttf_draw_string( rct_drawpixelinfo* dpi, const_utf8string text, int32_t colour, const ScreenCoordsXY& coords, bool noFormatting, - FontSpriteBase fontSpriteBase); + FontSpriteBase fontSpriteBase, TextDarkness darkness); // scrolling text void scrolling_text_initialise_bitmaps(); diff --git a/src/openrct2/drawing/Font.cpp b/src/openrct2/drawing/Font.cpp index 62c8395863..facebb658a 100644 --- a/src/openrct2/drawing/Font.cpp +++ b/src/openrct2/drawing/Font.cpp @@ -298,11 +298,6 @@ int32_t font_sprite_get_codepoint_offset(int32_t codepoint) int32_t font_sprite_get_codepoint_width(FontSpriteBase fontSpriteBase, int32_t codepoint) { - if (fontSpriteBase == FontSpriteBase::MEDIUM_DARK || fontSpriteBase == FontSpriteBase::MEDIUM_EXTRA_DARK) - { - fontSpriteBase = FontSpriteBase::MEDIUM; - } - int32_t glyphIndex = font_sprite_get_codepoint_offset(codepoint); int32_t baseFontIndex = font_get_font_index_from_sprite_base(fontSpriteBase); if (glyphIndex >= FONT_SPRITE_GLYPH_COUNT) diff --git a/src/openrct2/drawing/Font.h b/src/openrct2/drawing/Font.h index 7476a78780..36f4a51151 100644 --- a/src/openrct2/drawing/Font.h +++ b/src/openrct2/drawing/Font.h @@ -25,9 +25,6 @@ enum enum class FontSpriteBase : int16_t { - MEDIUM_EXTRA_DARK = -2, - MEDIUM_DARK = -1, - TINY = FONT_SIZE_TINY * FONT_SPRITE_GLYPH_COUNT, SMALL = FONT_SIZE_SMALL * FONT_SPRITE_GLYPH_COUNT, MEDIUM = FONT_SIZE_MEDIUM * FONT_SPRITE_GLYPH_COUNT, diff --git a/src/openrct2/drawing/Text.cpp b/src/openrct2/drawing/Text.cpp index 7ee8637ad1..1bd21d93a9 100644 --- a/src/openrct2/drawing/Text.cpp +++ b/src/openrct2/drawing/Text.cpp @@ -100,7 +100,7 @@ static void DrawText( break; } - ttf_draw_string(dpi, text, paint.Colour, alignedCoords, noFormatting, paint.SpriteBase); + ttf_draw_string(dpi, text, paint.Colour, alignedCoords, noFormatting, paint.SpriteBase, paint.Darkness); if (paint.UnderlineText == TextUnderline::On) { diff --git a/src/openrct2/drawing/Text.h b/src/openrct2/drawing/Text.h index 56ed92d062..e544a1c4cd 100644 --- a/src/openrct2/drawing/Text.h +++ b/src/openrct2/drawing/Text.h @@ -30,12 +30,20 @@ enum class TextUnderline On, }; +enum class TextDarkness +{ + Regular = 0, + Dark = 1, + ExtraDark = 2, +}; + struct TextPaint { colour_t Colour = COLOUR_BLACK; FontSpriteBase SpriteBase = FontSpriteBase::MEDIUM; TextUnderline UnderlineText = TextUnderline::Off; TextAlignment Alignment = TextAlignment::LEFT; + TextDarkness Darkness = TextDarkness::Regular; TextPaint() = default; TextPaint(colour_t colour) @@ -99,6 +107,12 @@ struct TextPaint , Alignment(alignment) { } + TextPaint(colour_t colour, FontSpriteBase spriteBase, TextDarkness darkness) + : Colour(colour) + , SpriteBase(spriteBase) + , Darkness(darkness) + { + } TextPaint(colour_t colour, TextUnderline underlineText, TextAlignment alignment) : Colour(colour) , UnderlineText(underlineText) @@ -119,6 +133,13 @@ struct TextPaint , Alignment(alignment) { } + TextPaint(colour_t colour, FontSpriteBase spriteBase, TextAlignment alignment, TextDarkness darkness) + : Colour(colour) + , SpriteBase(spriteBase) + , Alignment(alignment) + , Darkness(darkness) + { + } }; void DrawTextBasic(rct_drawpixelinfo* dpi, const ScreenCoordsXY& coords, StringId format); From 14f9a75e0ae680c9aeb9fa121d9000717558ba95 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Wed, 12 Oct 2022 22:40:59 +0200 Subject: [PATCH 2/2] Refactor FontSpriteBase and font size into FontStyle --- src/openrct2-ui/interface/Graph.cpp | 4 +- src/openrct2-ui/interface/InGameConsole.cpp | 12 +- src/openrct2-ui/interface/Widget.cpp | 14 +-- src/openrct2-ui/scripting/CustomListView.cpp | 2 +- .../scripting/ScGraphicsContext.hpp | 4 +- src/openrct2-ui/windows/About.cpp | 4 +- src/openrct2-ui/windows/Changelog.cpp | 6 +- src/openrct2-ui/windows/DebugPaint.cpp | 2 +- src/openrct2-ui/windows/Dropdown.cpp | 2 +- .../windows/EditorInventionsList.cpp | 10 +- .../windows/EditorObjectSelection.cpp | 7 +- .../windows/EditorObjectiveOptions.cpp | 2 +- src/openrct2-ui/windows/Error.cpp | 8 +- src/openrct2-ui/windows/Finances.cpp | 6 +- src/openrct2-ui/windows/GameBottomToolbar.cpp | 10 +- src/openrct2-ui/windows/Guest.cpp | 6 +- src/openrct2-ui/windows/GuestList.cpp | 4 +- src/openrct2-ui/windows/LoadSave.cpp | 8 +- src/openrct2-ui/windows/Multiplayer.cpp | 10 +- src/openrct2-ui/windows/NetworkStatus.cpp | 4 +- src/openrct2-ui/windows/NewRide.cpp | 2 +- src/openrct2-ui/windows/News.cpp | 8 +- src/openrct2-ui/windows/Options.cpp | 2 +- src/openrct2-ui/windows/Park.cpp | 4 +- src/openrct2-ui/windows/Ride.cpp | 6 +- src/openrct2-ui/windows/ScenarioSelect.cpp | 19 ++- src/openrct2-ui/windows/ServerList.cpp | 2 +- src/openrct2-ui/windows/TextInput.cpp | 12 +- src/openrct2-ui/windows/Themes.cpp | 2 +- src/openrct2-ui/windows/TileInspector.cpp | 2 +- src/openrct2-ui/windows/Tooltip.cpp | 8 +- src/openrct2-ui/windows/TrackList.cpp | 2 +- src/openrct2/drawing/Drawing.String.cpp | 110 +++++++++--------- src/openrct2/drawing/Drawing.h | 20 ++-- src/openrct2/drawing/Font.cpp | 77 ++++-------- src/openrct2/drawing/Font.h | 35 +++--- src/openrct2/drawing/ScrollingText.cpp | 10 +- src/openrct2/drawing/TTF.cpp | 10 +- src/openrct2/drawing/TTF.h | 2 +- src/openrct2/drawing/Text.cpp | 12 +- src/openrct2/drawing/Text.h | 42 +++---- src/openrct2/entity/MoneyEffect.cpp | 2 +- src/openrct2/interface/Chat.cpp | 12 +- src/openrct2/interface/Fonts.cpp | 47 ++++---- src/openrct2/localisation/Formatting.cpp | 2 +- src/openrct2/paint/Paint.cpp | 2 +- src/openrct2/paint/Painter.cpp | 4 +- .../paint/tile_element/Paint.Banner.cpp | 2 +- .../paint/tile_element/Paint.Entrance.cpp | 4 +- .../paint/tile_element/Paint.LargeScenery.cpp | 2 +- .../paint/tile_element/Paint.Path.cpp | 2 +- .../paint/tile_element/Paint.Wall.cpp | 2 +- src/openrct2/title/TitleScreen.cpp | 2 +- 53 files changed, 282 insertions(+), 313 deletions(-) diff --git a/src/openrct2-ui/interface/Graph.cpp b/src/openrct2-ui/interface/Graph.cpp index b3aeba5d69..da4c5a4dc8 100644 --- a/src/openrct2-ui/interface/Graph.cpp +++ b/src/openrct2-ui/interface/Graph.cpp @@ -30,7 +30,7 @@ namespace Graph ft.Add(DateGameShortMonthNames[date_get_month((yearOver32 / 4) + MONTH_COUNT)]); DrawTextBasic( dpi, screenCoords - ScreenCoordsXY{ 0, 10 }, STR_GRAPH_LABEL, ft, - { FontSpriteBase::SMALL, TextAlignment::CENTRE }); + { FontStyle::Small, TextAlignment::CENTRE }); // Draw month mark gfx_fill_rect(dpi, { screenCoords, screenCoords + ScreenCoordsXY{ 0, 3 } }, PALETTE_INDEX_10); @@ -167,7 +167,7 @@ namespace Graph ft.Add(DateGameShortMonthNames[date_get_month((yearOver32 / 4) + MONTH_COUNT)]); DrawTextBasic( dpi, screenCoords - ScreenCoordsXY{ 0, 10 }, STR_GRAPH_LABEL, ft, - { FontSpriteBase::SMALL, TextAlignment::CENTRE }); + { FontStyle::Small, TextAlignment::CENTRE }); // Draw month mark gfx_fill_rect(dpi, { screenCoords, screenCoords + ScreenCoordsXY{ 0, 3 } }, PALETTE_INDEX_10); diff --git a/src/openrct2-ui/interface/InGameConsole.cpp b/src/openrct2-ui/interface/InGameConsole.cpp index 39d8602728..a0368dae8f 100644 --- a/src/openrct2-ui/interface/InGameConsole.cpp +++ b/src/openrct2-ui/interface/InGameConsole.cpp @@ -26,14 +26,14 @@ using namespace OpenRCT2::Ui; static InGameConsole _inGameConsole; -static FontSpriteBase InGameConsoleGetFontSpriteBase() +static FontStyle InGameConsoleGetFontStyle() { - return (gConfigInterface.ConsoleSmallFont ? FontSpriteBase::SMALL : FontSpriteBase::MEDIUM); + return (gConfigInterface.ConsoleSmallFont ? FontStyle::Small : FontStyle::Medium); } static int32_t InGameConsoleGetLineHeight() { - return font_get_line_height(InGameConsoleGetFontSpriteBase()); + return font_get_line_height(InGameConsoleGetFontStyle()); } InGameConsole::InGameConsole() @@ -150,7 +150,7 @@ void InGameConsole::RefreshCaret(size_t position) _selectionStart = position; char tempString[TEXT_INPUT_SIZE] = { 0 }; std::memcpy(tempString, &_consoleCurrentLine, _selectionStart); - _caretScreenPosX = gfx_get_string_width_no_formatting(tempString, InGameConsoleGetFontSpriteBase()); + _caretScreenPosX = gfx_get_string_width_no_formatting(tempString, InGameConsoleGetFontStyle()); } void InGameConsole::Scroll(int32_t linesToScroll) @@ -318,7 +318,7 @@ void InGameConsole::Draw(rct_drawpixelinfo* dpi) const { const size_t index = i + _consoleScrollPos; lineBuffer = _colourFormatStr + _consoleLines[index]; - gfx_draw_string(dpi, screenCoords, lineBuffer.c_str(), { textColour, InGameConsoleGetFontSpriteBase() }); + gfx_draw_string(dpi, screenCoords, lineBuffer.c_str(), { textColour, InGameConsoleGetFontStyle() }); screenCoords.y += lineHeight; } @@ -326,7 +326,7 @@ void InGameConsole::Draw(rct_drawpixelinfo* dpi) const // Draw current line lineBuffer = _colourFormatStr + _consoleCurrentLine; - gfx_draw_string_no_formatting(dpi, screenCoords, lineBuffer.c_str(), { TEXT_COLOUR_255, InGameConsoleGetFontSpriteBase() }); + gfx_draw_string_no_formatting(dpi, screenCoords, lineBuffer.c_str(), { TEXT_COLOUR_255, InGameConsoleGetFontStyle() }); // Draw caret if (_consoleCaretTicks < CONSOLE_CARET_FLASH_THRESHOLD) diff --git a/src/openrct2-ui/interface/Widget.cpp b/src/openrct2-ui/interface/Widget.cpp index 763eafcb29..ccd9c9bc3c 100644 --- a/src/openrct2-ui/interface/Widget.cpp +++ b/src/openrct2-ui/interface/Widget.cpp @@ -490,7 +490,7 @@ static void WidgetGroupboxDraw(rct_drawpixelinfo* dpi, rct_window& w, WidgetInde auto ft = Formatter(); ft.Add(buffer); DrawTextBasic(dpi, { l, t }, STR_STRING, ft, { colour }); - textRight = l + gfx_get_string_width(buffer, FontSpriteBase::MEDIUM) + 1; + textRight = l + gfx_get_string_width(buffer, FontStyle::Medium) + 1; } // Border @@ -1147,9 +1147,9 @@ static void WidgetTextBoxDraw(rct_drawpixelinfo* dpi, rct_window& w, WidgetIndex if (widget.text != 0) { safe_strcpy(wrapped_string, widget.string, 512); - gfx_wrap_string(wrapped_string, bottomRight.x - topLeft.x - 5, FontSpriteBase::MEDIUM, &no_lines); + gfx_wrap_string(wrapped_string, bottomRight.x - topLeft.x - 5, FontStyle::Medium, &no_lines); gfx_draw_string_no_formatting( - dpi, { topLeft.x + 2, topLeft.y }, wrapped_string, { w.colours[1], FontSpriteBase::MEDIUM }); + dpi, { topLeft.x + 2, topLeft.y }, wrapped_string, { w.colours[1], FontStyle::Medium }); } return; } @@ -1158,16 +1158,16 @@ static void WidgetTextBoxDraw(rct_drawpixelinfo* dpi, rct_window& w, WidgetIndex // 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, FontSpriteBase::MEDIUM, &no_lines); + gfx_wrap_string(wrapped_string, bottomRight.x - topLeft.x - 5 - 6, FontStyle::Medium, &no_lines); - gfx_draw_string_no_formatting(dpi, { topLeft.x + 2, topLeft.y }, wrapped_string, { w.colours[1], FontSpriteBase::MEDIUM }); + gfx_draw_string_no_formatting(dpi, { topLeft.x + 2, topLeft.y }, wrapped_string, { w.colours[1], FontStyle::Medium }); size_t string_length = get_string_size(wrapped_string) - 1; // Make a copy of the string for measuring the width. char temp_string[TEXT_INPUT_SIZE] = { 0 }; std::memcpy(temp_string, wrapped_string, std::min(string_length, gTextInput->SelectionStart)); - int32_t cur_x = topLeft.x + gfx_get_string_width_no_formatting(temp_string, FontSpriteBase::MEDIUM) + 3; + int32_t cur_x = topLeft.x + gfx_get_string_width_no_formatting(temp_string, FontStyle::Medium) + 3; int32_t width = 6; if (static_cast(gTextInput->SelectionStart) < strlen(gTextBoxInput)) @@ -1176,7 +1176,7 @@ static void WidgetTextBoxDraw(rct_drawpixelinfo* dpi, rct_window& w, WidgetIndex // of the character that the cursor is under. temp_string[1] = '\0'; temp_string[0] = gTextBoxInput[gTextInput->SelectionStart]; - width = std::max(gfx_get_string_width_no_formatting(temp_string, FontSpriteBase::MEDIUM) - 2, 4); + width = std::max(gfx_get_string_width_no_formatting(temp_string, FontStyle::Medium) - 2, 4); } if (gTextBoxFrameNo <= 15) diff --git a/src/openrct2-ui/scripting/CustomListView.cpp b/src/openrct2-ui/scripting/CustomListView.cpp index 44f43e9fe2..6acb41247a 100644 --- a/src/openrct2-ui/scripting/CustomListView.cpp +++ b/src/openrct2-ui/scripting/CustomListView.cpp @@ -715,7 +715,7 @@ void CustomListView::PaintSeperator( // Get string dimensions format_string(gCommonStringFormatBuffer, sizeof(gCommonStringFormatBuffer), STR_STRING, ft.Data()); - int32_t categoryStringHalfWidth = (gfx_get_string_width(gCommonStringFormatBuffer, FontSpriteBase::MEDIUM) / 2) + 4; + int32_t categoryStringHalfWidth = (gfx_get_string_width(gCommonStringFormatBuffer, FontStyle::Medium) / 2) + 4; int32_t strLeft = centreX - categoryStringHalfWidth; int32_t strRight = centreX + categoryStringHalfWidth; diff --git a/src/openrct2-ui/scripting/ScGraphicsContext.hpp b/src/openrct2-ui/scripting/ScGraphicsContext.hpp index 2be85832ec..a8bb99c7c6 100644 --- a/src/openrct2-ui/scripting/ScGraphicsContext.hpp +++ b/src/openrct2-ui/scripting/ScGraphicsContext.hpp @@ -156,8 +156,8 @@ namespace OpenRCT2::Scripting DukValue measureText(const std::string& text) { - auto width = gfx_get_string_width(text, FontSpriteBase::MEDIUM); - auto height = string_get_height_raw(text.c_str(), FontSpriteBase::MEDIUM); + auto width = gfx_get_string_width(text, FontStyle::Medium); + auto height = string_get_height_raw(text.c_str(), FontStyle::Medium); return ToDuk(_ctx, { width, height }); } diff --git a/src/openrct2-ui/windows/About.cpp b/src/openrct2-ui/windows/About.cpp index 58027ca718..99593c1e6d 100644 --- a/src/openrct2-ui/windows/About.cpp +++ b/src/openrct2-ui/windows/About.cpp @@ -194,7 +194,7 @@ private: auto const& versionPlaceholder = widgets[WIDX_VERSION]; auto versionPlaceHolderWidth = versionPlaceholder.right - versionPlaceholder.left; auto centreX = versionPlaceholder.left + versionPlaceHolderWidth / 2; - auto centreY = (versionPlaceholder.top + versionPlaceholder.bottom - font_get_line_height(FontSpriteBase::MEDIUM)) / 2; + auto centreY = (versionPlaceholder.top + versionPlaceholder.bottom - font_get_line_height(FontStyle::Medium)) / 2; auto centrePos = windowPos + ScreenCoordsXY(centreX, centreY); DrawTextWrapped(&dpi, centrePos, versionPlaceHolderWidth, STR_STRING, ft, { colours[1], TextAlignment::CENTRE }); @@ -215,7 +215,7 @@ private: auto screenCoords = ScreenCoordsXY{ windowPos.x + 200, yPage + 5 }; - int32_t lineHeight = font_get_line_height(FontSpriteBase::MEDIUM); + int32_t lineHeight = font_get_line_height(FontStyle::Medium); // Credits DrawTextBasic(&dpi, screenCoords, STR_COPYRIGHT_CS, {}, { TextAlignment::CENTRE }); diff --git a/src/openrct2-ui/windows/Changelog.cpp b/src/openrct2-ui/windows/Changelog.cpp index b20e594eef..1a70012ed2 100644 --- a/src/openrct2-ui/windows/Changelog.cpp +++ b/src/openrct2-ui/windows/Changelog.cpp @@ -182,7 +182,7 @@ public: void OnScrollDraw(int32_t scrollIndex, rct_drawpixelinfo& dpi) override { - const int32_t lineHeight = font_get_line_height(FontSpriteBase::MEDIUM); + const int32_t lineHeight = font_get_line_height(FontStyle::Medium); ScreenCoordsXY screenCoords(3, 3 - lineHeight); for (const auto& line : _changelogLines) @@ -199,7 +199,7 @@ public: { return ScreenSize( _changelogLongestLineWidth + 4, - static_cast(_changelogLines.size()) * font_get_line_height(FontSpriteBase::MEDIUM)); + static_cast(_changelogLines.size()) * font_get_line_height(FontStyle::Medium)); } // TODO: This probably should be a utility function defined elsewhere for reusability @@ -301,7 +301,7 @@ private: _changelogLongestLineWidth = 0; for (const auto& line : _changelogLines) { - int32_t linewidth = gfx_get_string_width(line.c_str(), FontSpriteBase::MEDIUM); + int32_t linewidth = gfx_get_string_width(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 4ffc933358..26903dc635 100644 --- a/src/openrct2-ui/windows/DebugPaint.cpp +++ b/src/openrct2-ui/windows/DebugPaint.cpp @@ -110,7 +110,7 @@ public: const auto& stringIdx = widgets[widgetIndex].text; auto string = ls.GetString(stringIdx); Guard::ArgumentNotNull(string); - const auto strWidth = gfx_get_string_width(string, FontSpriteBase::MEDIUM); + const auto strWidth = gfx_get_string_width(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 2f2c3f624d..5e76773961 100644 --- a/src/openrct2-ui/windows/Dropdown.cpp +++ b/src/openrct2-ui/windows/Dropdown.cpp @@ -354,7 +354,7 @@ void WindowDropdownShowText(const ScreenCoordsXY& screenPos, int32_t extray, uin for (size_t i = 0; i < num_items; i++) { format_string(buffer, 256, gDropdownItems[i].Format, static_cast(&gDropdownItems[i].Args)); - string_width = gfx_get_string_width(buffer, FontSpriteBase::MEDIUM); + string_width = gfx_get_string_width(buffer, FontStyle::Medium); max_string_width = std::max(string_width, max_string_width); } diff --git a/src/openrct2-ui/windows/EditorInventionsList.cpp b/src/openrct2-ui/windows/EditorInventionsList.cpp index 3befe9ba53..ea2a1e1ae7 100644 --- a/src/openrct2-ui/windows/EditorInventionsList.cpp +++ b/src/openrct2-ui/windows/EditorInventionsList.cpp @@ -294,7 +294,7 @@ public: // TODO: this parameter by itself produces very light text. // It needs a {BLACK} token in the string to work properly. colour_t colour = COLOUR_BLACK; - FontSpriteBase fontSpriteBase = FontSpriteBase::MEDIUM; + FontStyle fontStyle = FontStyle::Medium; auto darkness = TextDarkness::Regular; if (researchItem.IsAlwaysResearched()) @@ -319,21 +319,21 @@ public: ft.Add(rideTypeName); DrawTextEllipsised( &dpi, { 1, itemY }, columnSplitOffset - 11, STR_INVENTIONS_LIST_RIDE_AND_VEHICLE_NAME, ft, - { colour, fontSpriteBase, darkness }); + { colour, fontStyle, darkness }); // Draw vehicle name ft = Formatter(); ft.Add(itemNameId); DrawTextEllipsised( &dpi, { columnSplitOffset + 1, itemY }, columnSplitOffset - 11, STR_BLACK_STRING, ft, - { colour, fontSpriteBase, darkness }); + { colour, fontStyle, darkness }); } else { // Scenery group, flat ride or shop auto ft = Formatter(); ft.Add(itemNameId); - DrawTextEllipsised(&dpi, { 1, itemY }, boxWidth, STR_BLACK_STRING, ft, { colour, fontSpriteBase, darkness }); + DrawTextEllipsised(&dpi, { 1, itemY }, boxWidth, STR_BLACK_STRING, ft, { colour, fontStyle, darkness }); } } } @@ -665,7 +665,7 @@ public: format_string(buffer, 256, stringId, nullptr); } - auto stringWidth = gfx_get_string_width(buffer, FontSpriteBase::MEDIUM); + auto stringWidth = gfx_get_string_width(buffer, FontStyle::Medium); widgets[0].right = stringWidth; Invalidate(); diff --git a/src/openrct2-ui/windows/EditorObjectSelection.cpp b/src/openrct2-ui/windows/EditorObjectSelection.cpp index e7276f40cb..54b6c788e3 100644 --- a/src/openrct2-ui/windows/EditorObjectSelection.cpp +++ b/src/openrct2-ui/windows/EditorObjectSelection.cpp @@ -728,7 +728,7 @@ public: gfx_draw_string( &dpi, screenCoords, static_cast(CheckBoxMarkString), - { static_cast(colour2), FontSpriteBase::MEDIUM, darkness }); + { static_cast(colour2), FontStyle::Medium, darkness }); } screenCoords.x = gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER ? 0 : 15; @@ -755,7 +755,7 @@ public: auto ft = Formatter(); ft.Add(gCommonStringFormatBuffer); DrawTextEllipsised( - &dpi, screenCoords, width_limit - 15, STR_STRING, ft, { colour, FontSpriteBase::MEDIUM, darkness }); + &dpi, screenCoords, width_limit - 15, STR_STRING, ft, { colour, FontStyle::Medium, darkness }); screenCoords.x = widgets[WIDX_LIST_SORT_RIDE].left - widgets[WIDX_LIST].left; } @@ -770,8 +770,7 @@ public: } auto ft = Formatter(); ft.Add(gCommonStringFormatBuffer); - DrawTextEllipsised( - &dpi, screenCoords, width_limit, STR_STRING, ft, { colour, FontSpriteBase::MEDIUM, darkness }); + DrawTextEllipsised(&dpi, screenCoords, width_limit, STR_STRING, ft, { colour, FontStyle::Medium, darkness }); } screenCoords.y += SCROLLABLE_ROW_HEIGHT; } diff --git a/src/openrct2-ui/windows/EditorObjectiveOptions.cpp b/src/openrct2-ui/windows/EditorObjectiveOptions.cpp index 7714f04ab9..5f0591ac56 100644 --- a/src/openrct2-ui/windows/EditorObjectiveOptions.cpp +++ b/src/openrct2-ui/windows/EditorObjectiveOptions.cpp @@ -1087,7 +1087,7 @@ static void WindowEditorObjectiveOptionsRidesScrollpaint(rct_window* w, rct_draw auto darkness = stringId == STR_WINDOW_COLOUR_2_STRINGID ? TextDarkness::ExtraDark : TextDarkness::Dark; gfx_draw_string( dpi, { 2, y }, static_cast(CheckBoxMarkString), - { static_cast(w->colours[1] & 0x7F), FontSpriteBase::MEDIUM, darkness }); + { static_cast(w->colours[1] & 0x7F), FontStyle::Medium, darkness }); } // Ride name diff --git a/src/openrct2-ui/windows/Error.cpp b/src/openrct2-ui/windows/Error.cpp index ea8516621b..74c707eb44 100644 --- a/src/openrct2-ui/windows/Error.cpp +++ b/src/openrct2-ui/windows/Error.cpp @@ -84,14 +84,14 @@ rct_window* WindowErrorOpen(std::string_view title, std::string_view message) if (buffer.size() <= 1) return nullptr; - width = gfx_get_string_width_new_lined(buffer.data(), FontSpriteBase::MEDIUM); + width = gfx_get_string_width_new_lined(buffer.data(), FontStyle::Medium); width = std::clamp(width, 64, 196); - gfx_wrap_string(buffer.data(), width + 1, FontSpriteBase::MEDIUM, &numLines); + gfx_wrap_string(buffer.data(), width + 1, FontStyle::Medium, &numLines); _window_error_num_lines = numLines; width = width + 3; - height = (numLines + 1) * font_get_line_height(FontSpriteBase::MEDIUM) + 4; + height = (numLines + 1) * font_get_line_height(FontStyle::Medium) + 4; window_error_widgets[WIDX_BACKGROUND].right = width; window_error_widgets[WIDX_BACKGROUND].bottom = height; @@ -175,5 +175,5 @@ static void WindowErrorPaint(rct_window* w, rct_drawpixelinfo* dpi) draw_string_centred_raw( dpi, { leftTop + ScreenCoordsXY{ (w->width + 1) / 2 - 1, 1 } }, _window_error_num_lines, _window_error_text.data(), - FontSpriteBase::MEDIUM); + FontStyle::Medium); } diff --git a/src/openrct2-ui/windows/Finances.cpp b/src/openrct2-ui/windows/Finances.cpp index 0530020732..6914144b5c 100644 --- a/src/openrct2-ui/windows/Finances.cpp +++ b/src/openrct2-ui/windows/Finances.cpp @@ -632,7 +632,7 @@ public: ft.Add(axisValue); DrawTextBasic( &dpi, coords + ScreenCoordsXY{ 70, 0 }, STR_FINANCES_FINANCIAL_GRAPH_CASH_VALUE, ft, - { FontSpriteBase::SMALL, TextAlignment::RIGHT }); + { FontStyle::Small, TextAlignment::RIGHT }); gfx_fill_rect_inset( &dpi, { coords + ScreenCoordsXY{ 70, 5 }, { graphTopLeft.x + 482, coords.y + 5 } }, colours[2], INSET_RECT_FLAG_BORDER_INSET); @@ -689,7 +689,7 @@ public: ft.Add(axisValue); DrawTextBasic( &dpi, coords + ScreenCoordsXY{ 70, 0 }, STR_FINANCES_FINANCIAL_GRAPH_CASH_VALUE, ft, - { FontSpriteBase::SMALL, TextAlignment::RIGHT }); + { FontStyle::Small, TextAlignment::RIGHT }); gfx_fill_rect_inset( &dpi, { coords + ScreenCoordsXY{ 70, 5 }, { graphTopLeft.x + 482, coords.y + 5 } }, colours[2], INSET_RECT_FLAG_BORDER_INSET); @@ -748,7 +748,7 @@ public: ft.Add(axisValue); DrawTextBasic( &dpi, screenPos + ScreenCoordsXY{ 70, 0 }, STR_FINANCES_FINANCIAL_GRAPH_CASH_VALUE, ft, - { FontSpriteBase::SMALL, TextAlignment::RIGHT }); + { FontStyle::Small, TextAlignment::RIGHT }); gfx_fill_rect_inset( &dpi, { screenPos + ScreenCoordsXY{ 70, 5 }, { graphTopLeft.x + 482, screenPos.y + 5 } }, colours[2], INSET_RECT_FLAG_BORDER_INSET); diff --git a/src/openrct2-ui/windows/GameBottomToolbar.cpp b/src/openrct2-ui/windows/GameBottomToolbar.cpp index 7c4f9cf604..61307d6a7f 100644 --- a/src/openrct2-ui/windows/GameBottomToolbar.cpp +++ b/src/openrct2-ui/windows/GameBottomToolbar.cpp @@ -111,7 +111,7 @@ rct_window* WindowGameBottomToolbarOpen() int32_t screenHeight = context_get_height(); // Figure out how much line height we have to work with. - uint32_t line_height = font_get_line_height(FontSpriteBase::MEDIUM); + uint32_t line_height = font_get_line_height(FontStyle::Medium); uint32_t toolbar_height = line_height * 2 + 12; rct_window* window = WindowCreate( @@ -220,7 +220,7 @@ static OpenRCT2String WindowGameBottomToolbarTooltip(rct_window* w, const Widget static void WindowGameBottomToolbarInvalidate(rct_window* w) { // Figure out how much line height we have to work with. - uint32_t line_height = font_get_line_height(FontSpriteBase::MEDIUM); + uint32_t line_height = font_get_line_height(FontStyle::Medium); // Reset dimensions as appropriate -- in case we're switching languages. w->height = line_height * 2 + 12; @@ -396,7 +396,7 @@ static void WindowGameBottomToolbarDrawLeftPanel(rct_drawpixelinfo* dpi, rct_win gfx_fill_rect_inset(dpi, { topLeft, bottomRight }, w->colours[1], INSET_RECT_F_30); // Figure out how much line height we have to work with. - uint32_t line_height = font_get_line_height(FontSpriteBase::MEDIUM); + uint32_t line_height = font_get_line_height(FontStyle::Medium); // Draw money if (!(gParkFlags & PARK_FLAGS_NO_MONEY)) @@ -513,7 +513,7 @@ static void WindowGameBottomToolbarDrawRightPanel(rct_drawpixelinfo* dpi, rct_wi DrawTextBasic(dpi, screenCoords, stringId, ft, { colour, TextAlignment::CENTRE }); // Figure out how much line height we have to work with. - uint32_t line_height = font_get_line_height(FontSpriteBase::MEDIUM); + uint32_t line_height = font_get_line_height(FontStyle::Medium); // Temperature screenCoords = { w->windowPos.x + window_game_bottom_toolbar_widgets[WIDX_RIGHT_OUTSET].left + 15, @@ -662,7 +662,7 @@ static void WindowGameBottomToolbarDrawMiddlePanel(rct_drawpixelinfo* dpi, rct_w w->colours[1], INSET_RECT_F_30); // Figure out how much line height we have to work with. - uint32_t line_height = font_get_line_height(FontSpriteBase::MEDIUM); + uint32_t line_height = font_get_line_height(FontStyle::Medium); ScreenCoordsXY middleWidgetCoords( w->windowPos.x + middleOutsetWidget->midX(), w->windowPos.y + middleOutsetWidget->top + line_height + 1); diff --git a/src/openrct2-ui/windows/Guest.cpp b/src/openrct2-ui/windows/Guest.cpp index e3da506b69..0eb1b0d89a 100644 --- a/src/openrct2-ui/windows/Guest.cpp +++ b/src/openrct2-ui/windows/Guest.cpp @@ -816,7 +816,7 @@ private: { auto ft = Formatter(); peep_thought_set_format_args(&peep->Thoughts[i], ft); - DrawTextBasic(&dpiMarquee, { screenPos.x, 0 }, STR_WINDOW_COLOUR_2_STRINGID, ft, { FontSpriteBase::SMALL }); + DrawTextBasic(&dpiMarquee, { screenPos.x, 0 }, STR_WINDOW_COLOUR_2_STRINGID, ft, { FontStyle::Small }); } } @@ -1040,7 +1040,7 @@ private: void StatsBarsDraw(int32_t value, const ScreenCoordsXY& origCoords, rct_drawpixelinfo& dpi, int32_t colour, bool blinkFlag) { auto coords = origCoords; - if (font_get_line_height(FontSpriteBase::MEDIUM) > 10) + if (font_get_line_height(FontStyle::Medium) > 10) { coords.y += 1; } @@ -1594,7 +1594,7 @@ private: auto ft = Formatter(); peep_thought_set_format_args(&thought, ft); - screenCoords.y += DrawTextWrapped(&dpi, screenCoords, widgWidth, STR_BLACK_STRING, ft, { FontSpriteBase::SMALL }); + screenCoords.y += DrawTextWrapped(&dpi, screenCoords, widgWidth, STR_BLACK_STRING, ft, { FontStyle::Small }); // If this is the last visible line end drawing. if (screenCoords.y > windowPos.y + widgets[WIDX_PAGE_BACKGROUND].bottom - 32) diff --git a/src/openrct2-ui/windows/GuestList.cpp b/src/openrct2-ui/windows/GuestList.cpp index 8f8a62660b..3a21cb95c3 100644 --- a/src/openrct2-ui/windows/GuestList.cpp +++ b/src/openrct2-ui/windows/GuestList.cpp @@ -716,7 +716,7 @@ private: ft = Formatter(); peep_thought_set_format_args(&thought, ft); - DrawTextEllipsised(&dpi, { 118, y }, 329, format, ft, { FontSpriteBase::SMALL }); + DrawTextEllipsised(&dpi, { 118, y }, 329, format, ft, { FontStyle::Small }); break; } break; @@ -761,7 +761,7 @@ private: // Draw small font if displaying guests if (_selectedView == GuestViewType::Thoughts) { - DrawTextEllipsised(&dpi, { 0, y }, 414, format, ft, { FontSpriteBase::SMALL }); + DrawTextEllipsised(&dpi, { 0, y }, 414, format, ft, { FontStyle::Small }); } else { diff --git a/src/openrct2-ui/windows/LoadSave.cpp b/src/openrct2-ui/windows/LoadSave.cpp index 6f9495c26e..2d0367dce6 100644 --- a/src/openrct2-ui/windows/LoadSave.cpp +++ b/src/openrct2-ui/windows/LoadSave.cpp @@ -647,7 +647,7 @@ static void WindowLoadsaveComputeMaxDateWidth() // Check how this date is represented (e.g. 2000-02-20, or 00/02/20) std::string date = Platform::FormatShortDate(long_time); - maxDateWidth = gfx_get_string_width(date.c_str(), FontSpriteBase::MEDIUM) + DATE_TIME_GAP; + maxDateWidth = gfx_get_string_width(date.c_str(), FontStyle::Medium) + DATE_TIME_GAP; // Some locales do not use leading zeros for months and days, so let's try October, too. tm.tm_mon = 10; @@ -656,11 +656,11 @@ static void WindowLoadsaveComputeMaxDateWidth() // Again, check how this date is represented (e.g. 2000-10-20, or 00/10/20) date = Platform::FormatShortDate(long_time); - maxDateWidth = std::max(maxDateWidth, gfx_get_string_width(date.c_str(), FontSpriteBase::MEDIUM) + DATE_TIME_GAP); + maxDateWidth = std::max(maxDateWidth, gfx_get_string_width(date.c_str(), FontStyle::Medium) + DATE_TIME_GAP); // Time appears to be universally represented with two digits for minutes, so 12:00 or 00:00 should be representable. std::string time = Platform::FormatTime(long_time); - maxTimeWidth = gfx_get_string_width(time.c_str(), FontSpriteBase::MEDIUM) + DATE_TIME_GAP; + maxTimeWidth = gfx_get_string_width(time.c_str(), FontStyle::Medium) + DATE_TIME_GAP; } static void WindowLoadsaveInvalidate(rct_window* w) @@ -696,7 +696,7 @@ static void WindowLoadsavePaint(rct_window* w, rct_drawpixelinfo* dpi) if (_shortenedDirectory[0] == '\0') { - shorten_path(_shortenedDirectory, sizeof(_shortenedDirectory), _directory, w->width - 8, FontSpriteBase::MEDIUM); + shorten_path(_shortenedDirectory, sizeof(_shortenedDirectory), _directory, w->width - 8, FontStyle::Medium); } // Format text diff --git a/src/openrct2-ui/windows/Multiplayer.cpp b/src/openrct2-ui/windows/Multiplayer.cpp index bb084a6460..f8f718c3e6 100644 --- a/src/openrct2-ui/windows/Multiplayer.cpp +++ b/src/openrct2-ui/windows/Multiplayer.cpp @@ -340,7 +340,7 @@ static ScreenCoordsXY WindowMultiplayerInformationGetSize() return _windowInformationSize; } - int32_t lineHeight = font_get_line_height(FontSpriteBase::MEDIUM); + int32_t lineHeight = font_get_line_height(FontStyle::Medium); // Base dimensions. const int32_t width = 450; @@ -350,7 +350,7 @@ static ScreenCoordsXY WindowMultiplayerInformationGetSize() // Server name is displayed word-wrapped, so figure out how high it will be. { u8string buffer = network_get_server_name(); - gfx_wrap_string(buffer.data(), width, FontSpriteBase::MEDIUM, &numLines); + gfx_wrap_string(buffer.data(), width, FontStyle::Medium, &numLines); height += ++numLines * lineHeight + (LIST_ROW_HEIGHT / 2); } @@ -359,7 +359,7 @@ static ScreenCoordsXY WindowMultiplayerInformationGetSize() if (!str_is_null_or_empty(descString)) { u8string buffer = descString; - gfx_wrap_string(buffer.data(), width, FontSpriteBase::MEDIUM, &numLines); + gfx_wrap_string(buffer.data(), width, FontStyle::Medium, &numLines); height += ++numLines * lineHeight + (LIST_ROW_HEIGHT / 2); } @@ -623,7 +623,7 @@ static void WindowMultiplayerPlayersScrollpaint(rct_window* w, rct_drawpixelinfo _buffer += network_get_player_name(player); } screenCoords.x = 0; - gfx_clip_string(_buffer.data(), 230, FontSpriteBase::MEDIUM); + gfx_clip_string(_buffer.data(), 230, FontStyle::Medium); gfx_draw_string(dpi, screenCoords, _buffer.c_str(), { colour }); // Draw group name @@ -634,7 +634,7 @@ static void WindowMultiplayerPlayersScrollpaint(rct_window* w, rct_drawpixelinfo _buffer += "{BLACK}"; screenCoords.x = 173; _buffer += network_get_group_name(group); - gfx_clip_string(_buffer.data(), 80, FontSpriteBase::MEDIUM); + gfx_clip_string(_buffer.data(), 80, FontStyle::Medium); gfx_draw_string(dpi, screenCoords, _buffer.c_str(), { colour }); } diff --git a/src/openrct2-ui/windows/NetworkStatus.cpp b/src/openrct2-ui/windows/NetworkStatus.cpp index f7bfef672c..9ff0452a78 100644 --- a/src/openrct2-ui/windows/NetworkStatus.cpp +++ b/src/openrct2-ui/windows/NetworkStatus.cpp @@ -107,9 +107,9 @@ public: thread_local std::string _buffer; _buffer.assign("{BLACK}"); _buffer += _windowNetworkStatusText; - gfx_clip_string(_buffer.data(), widgets[WIDX_BACKGROUND].right - 50, FontSpriteBase::MEDIUM); + gfx_clip_string(_buffer.data(), widgets[WIDX_BACKGROUND].right - 50, FontStyle::Medium); ScreenCoordsXY screenCoords(windowPos.x + (width / 2), windowPos.y + (height / 2)); - screenCoords.x -= gfx_get_string_width(_buffer, FontSpriteBase::MEDIUM) / 2; + screenCoords.x -= gfx_get_string_width(_buffer, FontStyle::Medium) / 2; gfx_draw_string(&dpi, screenCoords, _buffer.c_str()); } diff --git a/src/openrct2-ui/windows/NewRide.cpp b/src/openrct2-ui/windows/NewRide.cpp index fd18564f0d..3a4c274fd2 100644 --- a/src/openrct2-ui/windows/NewRide.cpp +++ b/src/openrct2-ui/windows/NewRide.cpp @@ -386,7 +386,7 @@ public: const auto& ls = OpenRCT2::GetContext()->GetLocalisationService(); auto string = ls.GetString(STR_GROUP_BY_TRACK_TYPE); - auto strWidth = gfx_get_string_width(string, FontSpriteBase::MEDIUM); + auto strWidth = gfx_get_string_width(string, FontStyle::Medium); auto localizedGroupByTrackTypeWidth = strWidth + 14; widgets[WIDX_GROUP_BY_TRACK_TYPE].left = width - 8 - localizedGroupByTrackTypeWidth; } diff --git a/src/openrct2-ui/windows/News.cpp b/src/openrct2-ui/windows/News.cpp index 519880ee8d..5988abf2a3 100644 --- a/src/openrct2-ui/windows/News.cpp +++ b/src/openrct2-ui/windows/News.cpp @@ -50,7 +50,7 @@ private: int32_t _pressedNewsItemIndex{}, _pressedButtonIndex{}, _suspendUpdateTicks{}; static int32_t CalculateItemHeight() { - return 4 * font_get_line_height(FontSpriteBase::SMALL) + 2; + return 4 * font_get_line_height(FontStyle::Small) + 2; } public: @@ -173,7 +173,7 @@ public: void OnScrollDraw(int32_t scrollIndex, rct_drawpixelinfo& dpi) override { - int32_t lineHeight = font_get_line_height(FontSpriteBase::SMALL); + int32_t lineHeight = font_get_line_height(FontStyle::Small); int32_t itemHeight = CalculateItemHeight(); int32_t y = 0; int32_t i = 0; @@ -199,13 +199,13 @@ public: auto ft = Formatter(); ft.Add(DateDayNames[newsItem.Day - 1]); ft.Add(DateGameMonthNames[date_get_month(newsItem.MonthYear)]); - DrawTextBasic(&dpi, { 2, y }, STR_NEWS_DATE_FORMAT, ft, { COLOUR_WHITE, FontSpriteBase::SMALL }); + DrawTextBasic(&dpi, { 2, y }, STR_NEWS_DATE_FORMAT, ft, { COLOUR_WHITE, FontStyle::Small }); } // Item text { auto ft = Formatter(); ft.Add(newsItem.Text.c_str()); - DrawTextWrapped(&dpi, { 2, y + lineHeight }, 325, STR_BOTTOM_TOOLBAR_NEWS_TEXT, ft, { FontSpriteBase::SMALL }); + DrawTextWrapped(&dpi, { 2, y + lineHeight }, 325, STR_BOTTOM_TOOLBAR_NEWS_TEXT, ft, { FontStyle::Small }); } // Subject button if ((newsItem.TypeHasSubject()) && !(newsItem.HasButton())) diff --git a/src/openrct2-ui/windows/Options.cpp b/src/openrct2-ui/windows/Options.cpp index 7e86c07b7f..ace56b2ce1 100644 --- a/src/openrct2-ui/windows/Options.cpp +++ b/src/openrct2-ui/windows/Options.cpp @@ -2013,7 +2013,7 @@ private: // Apply vertical alignment if appropriate. int32_t widgetHeight = pathWidget.bottom - pathWidget.top; - int32_t lineHeight = font_get_line_height(FontSpriteBase::MEDIUM); + int32_t lineHeight = font_get_line_height(FontStyle::Medium); uint32_t padding = widgetHeight > lineHeight ? (widgetHeight - lineHeight) / 2 : 0; ScreenCoordsXY screenCoords = { windowPos.x + pathWidget.left + 1, windowPos.y + pathWidget.top + static_cast(padding) }; diff --git a/src/openrct2-ui/windows/Park.cpp b/src/openrct2-ui/windows/Park.cpp index a12dd41e8b..5874d8f50a 100644 --- a/src/openrct2-ui/windows/Park.cpp +++ b/src/openrct2-ui/windows/Park.cpp @@ -713,7 +713,7 @@ private: ft.Add(axisValue); DrawTextBasic( &dpi, screenPos + ScreenCoordsXY{ 10, 0 }, STR_GRAPH_AXIS_LABEL, ft, - { FontSpriteBase::SMALL, TextAlignment::RIGHT }); + { FontStyle::Small, TextAlignment::RIGHT }); gfx_fill_rect_inset( &dpi, { screenPos + ScreenCoordsXY{ 15, 5 }, screenPos + ScreenCoordsXY{ width - 32, 5 } }, colours[2], INSET_RECT_FLAG_BORDER_INSET); @@ -786,7 +786,7 @@ private: ft.Add(axisValue); DrawTextBasic( &dpi, screenPos + ScreenCoordsXY{ 10, 0 }, STR_GRAPH_AXIS_LABEL, ft, - { FontSpriteBase::SMALL, TextAlignment::RIGHT }); + { FontStyle::Small, TextAlignment::RIGHT }); gfx_fill_rect_inset( &dpi, { screenPos + ScreenCoordsXY{ 15, 5 }, screenPos + ScreenCoordsXY{ width - 32, 5 } }, colours[2], INSET_RECT_FLAG_BORDER_INSET); diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index 2c09e4ff64..2022bb194a 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -2907,7 +2907,7 @@ static void WindowRideVehiclePaint(rct_window* w, rct_drawpixelinfo* dpi) // Intensity Factor if (rideEntry->intensity_multiplier > 0) { - int32_t lineHeight = font_get_line_height(FontSpriteBase::MEDIUM); + int32_t lineHeight = font_get_line_height(FontStyle::Medium); if (lineHeight != 10) screenCoords.x += 150; else @@ -6183,7 +6183,7 @@ static void WindowRideGraphsScrollpaint(rct_window* w, rct_drawpixelinfo* dpi, i auto ft = Formatter(); ft.Add(scaled_yUnit); - DrawTextBasic(dpi, { w->scrolls[0].h_left + 1, y - 4 }, stringID, ft, { FontSpriteBase::SMALL }); + DrawTextBasic(dpi, { w->scrolls[0].h_left + 1, y - 4 }, stringID, ft, { FontStyle::Small }); } // Time marks @@ -6193,7 +6193,7 @@ static void WindowRideGraphsScrollpaint(rct_window* w, rct_drawpixelinfo* dpi, i auto ft = Formatter(); ft.Add(time); if (x + 80 >= dpi->x) - DrawTextBasic(dpi, { x + 2, 1 }, STR_RIDE_STATS_TIME, ft, { FontSpriteBase::SMALL }); + DrawTextBasic(dpi, { x + 2, 1 }, STR_RIDE_STATS_TIME, ft, { FontStyle::Small }); time += 5; } diff --git a/src/openrct2-ui/windows/ScenarioSelect.cpp b/src/openrct2-ui/windows/ScenarioSelect.cpp index 9a9c6c6b56..a949b23361 100644 --- a/src/openrct2-ui/windows/ScenarioSelect.cpp +++ b/src/openrct2-ui/windows/ScenarioSelect.cpp @@ -288,10 +288,10 @@ static int32_t GetScenarioListItemSize() return 24; // Scenario title - int32_t lineHeight = font_get_line_height(FontSpriteBase::MEDIUM); + int32_t lineHeight = font_get_line_height(FontStyle::Medium); // 'Completed by' line - lineHeight += font_get_line_height(FontSpriteBase::SMALL); + lineHeight += font_get_line_height(FontStyle::Small); return lineHeight; } @@ -436,7 +436,7 @@ static void WindowScenarioselectPaint(rct_window* w, rct_drawpixelinfo* dpi) WindowDrawWidgets(*w, dpi); format = ScenarioSelectUseSmallFont() ? STR_SMALL_WINDOW_COLOUR_2_STRINGID : STR_WINDOW_COLOUR_2_STRINGID; - FontSpriteBase fontSpriteBase = ScenarioSelectUseSmallFont() ? FontSpriteBase::SMALL : FontSpriteBase::MEDIUM; + FontStyle fontStyle = ScenarioSelectUseSmallFont() ? FontStyle::Small : FontStyle::Medium; // Text for each tab for (uint32_t i = 0; i < std::size(ScenarioOriginStringIds); i++) @@ -456,7 +456,7 @@ static void WindowScenarioselectPaint(rct_window* w, rct_drawpixelinfo* dpi) } ScreenCoordsXY stringCoords(widget->midX() + w->windowPos.x, widget->midY() + w->windowPos.y - 3); - DrawTextWrapped(dpi, stringCoords, 87, format, ft, { COLOUR_AQUAMARINE, fontSpriteBase, TextAlignment::CENTRE }); + DrawTextWrapped(dpi, stringCoords, 87, format, ft, { COLOUR_AQUAMARINE, fontStyle, TextAlignment::CENTRE }); } // Return if no scenario highlighted @@ -490,7 +490,7 @@ static void WindowScenarioselectPaint(rct_window* w, rct_drawpixelinfo* dpi) { utf8 path[MAX_PATH]; - shorten_path(path, sizeof(path), scenario->path, w->width - 6 - TabWidth, FontSpriteBase::MEDIUM); + shorten_path(path, sizeof(path), scenario->path, w->width - 6 - TabWidth, FontStyle::Medium); const utf8* pathPtr = path; auto ft = Formatter(); @@ -571,7 +571,7 @@ static void WindowScenarioselectScrollpaint(rct_window* w, rct_drawpixelinfo* dp const int32_t scenarioItemHeight = GetScenarioListItemSize(); // Scenario title - int32_t scenarioTitleHeight = font_get_line_height(FontSpriteBase::MEDIUM); + int32_t scenarioTitleHeight = font_get_line_height(FontStyle::Medium); int32_t y = 0; for (const auto& listItem : _listItems) @@ -617,8 +617,7 @@ static void WindowScenarioselectScrollpaint(rct_window* w, rct_drawpixelinfo* dp const auto scrollCentre = window_scenarioselect_widgets[WIDX_SCENARIOLIST].width() / 2; DrawTextBasic( - dpi, { scrollCentre, y + 1 }, format, ft, - { colour, FontSpriteBase::MEDIUM, TextAlignment::CENTRE, darkness }); + dpi, { scrollCentre, y + 1 }, format, ft, { colour, FontStyle::Medium, TextAlignment::CENTRE, darkness }); // Check if scenario is completed if (isCompleted) @@ -641,7 +640,7 @@ static void WindowScenarioselectScrollpaint(rct_window* w, rct_drawpixelinfo* dp ft.Add(buffer); DrawTextBasic( dpi, { scrollCentre, y + scenarioTitleHeight + 1 }, format, ft, - { FontSpriteBase::SMALL, TextAlignment::CENTRE }); + { FontStyle::Small, TextAlignment::CENTRE }); } y += scenarioItemHeight; @@ -665,7 +664,7 @@ static void DrawCategoryHeading( // Get string dimensions utf8* buffer = gCommonStringFormatBuffer; format_string(buffer, 256, stringId, nullptr); - int32_t categoryStringHalfWidth = (gfx_get_string_width(buffer, FontSpriteBase::MEDIUM) / 2) + 4; + int32_t categoryStringHalfWidth = (gfx_get_string_width(buffer, FontStyle::Medium) / 2) + 4; int32_t strLeft = centreX - categoryStringHalfWidth; int32_t strRight = centreX + categoryStringHalfWidth; diff --git a/src/openrct2-ui/windows/ServerList.cpp b/src/openrct2-ui/windows/ServerList.cpp index 8fad0b25aa..a36320720c 100644 --- a/src/openrct2-ui/windows/ServerList.cpp +++ b/src/openrct2-ui/windows/ServerList.cpp @@ -441,7 +441,7 @@ static void WindowServerListScrollpaint(rct_window* w, rct_drawpixelinfo* dpi, i { snprintf(players, sizeof(players), "%d/%d", serverDetails.Players, serverDetails.MaxPlayers); } - const int16_t numPlayersStringWidth = gfx_get_string_width(players, FontSpriteBase::MEDIUM); + const int16_t numPlayersStringWidth = gfx_get_string_width(players, FontStyle::Medium); // How much space we have for the server info depends on the size of everything rendered after. const int16_t spaceAvailableForInfo = width - numPlayersStringWidth - SCROLLBAR_WIDTH - 35; diff --git a/src/openrct2-ui/windows/TextInput.cpp b/src/openrct2-ui/windows/TextInput.cpp index 2cba21cc0d..6bc98d5683 100644 --- a/src/openrct2-ui/windows/TextInput.cpp +++ b/src/openrct2-ui/windows/TextInput.cpp @@ -223,7 +223,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), FontSpriteBase::MEDIUM, &no_lines); + gfx_wrap_string(wrapped_string, WW - (24 + 13), FontStyle::Medium, &no_lines); gfx_fill_rect_inset( &dpi, { { windowPos.x + 10, screenCoords.y }, { windowPos.x + WW - 10, screenCoords.y + 10 * (no_lines + 1) + 3 } }, @@ -240,7 +240,7 @@ public: for (int32_t line = 0; line <= no_lines; line++) { screenCoords.x = windowPos.x + 12; - gfx_draw_string_no_formatting(&dpi, screenCoords, wrap_pointer, { colours[1], FontSpriteBase::MEDIUM }); + gfx_draw_string_no_formatting(&dpi, screenCoords, wrap_pointer, { colours[1], FontStyle::Medium }); size_t string_length = get_string_size(wrap_pointer) - 1; @@ -249,7 +249,7 @@ public: // Make a copy of the string for measuring the width. char temp_string[TEXT_INPUT_SIZE] = { 0 }; std::memcpy(temp_string, wrap_pointer, gTextInput->SelectionStart - char_count); - cursorX = windowPos.x + 13 + gfx_get_string_width_no_formatting(temp_string, FontSpriteBase::MEDIUM); + cursorX = windowPos.x + 13 + gfx_get_string_width_no_formatting(temp_string, FontStyle::Medium); cursorY = screenCoords.y; int32_t textWidth = 6; @@ -260,7 +260,7 @@ public: utf8 tmp[5] = { 0 }; // This is easier than setting temp_string[0..5] uint32_t codepoint = utf8_get_next(_buffer.data() + gTextInput->SelectionStart, nullptr); utf8_write_codepoint(tmp, codepoint); - textWidth = std::max(gfx_get_string_width_no_formatting(tmp, FontSpriteBase::MEDIUM) - 2, 4); + textWidth = std::max(gfx_get_string_width_no_formatting(tmp, FontStyle::Medium) - 2, 4); } if (_cursorBlink > 15) @@ -310,14 +310,14 @@ public: // String length needs to add 12 either side of box +13 for cursor when max length. int32_t numLines{}; - gfx_wrap_string(wrappedString.data(), WW - (24 + 13), FontSpriteBase::MEDIUM, &numLines); + gfx_wrap_string(wrappedString.data(), WW - (24 + 13), FontStyle::Medium, &numLines); return numLines * 10 + WH; } private: static void DrawIMEComposition(rct_drawpixelinfo& dpi, int32_t cursorX, int32_t cursorY) { - int compositionWidth = gfx_get_string_width(gTextInput->ImeBuffer, FontSpriteBase::MEDIUM); + int compositionWidth = gfx_get_string_width(gTextInput->ImeBuffer, FontStyle::Medium); ScreenCoordsXY screenCoords(cursorX - (compositionWidth / 2), cursorY + 13); int width = compositionWidth; int height = 10; diff --git a/src/openrct2-ui/windows/Themes.cpp b/src/openrct2-ui/windows/Themes.cpp index 1a5ea60b2e..dbb29c0696 100644 --- a/src/openrct2-ui/windows/Themes.cpp +++ b/src/openrct2-ui/windows/Themes.cpp @@ -823,7 +823,7 @@ public: { gfx_draw_string( &dpi, topLeft, static_cast(CheckBoxMarkString), - { static_cast(colours[1] & 0x7F), FontSpriteBase::MEDIUM, TextDarkness::Dark }); + { static_cast(colours[1] & 0x7F), FontStyle::Medium, TextDarkness::Dark }); } } } diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index d07a370223..2370f486d1 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -1539,7 +1539,7 @@ public: { auto& listWidget = widgets[WIDX_LIST]; auto centrePos = ScreenCoordsXY{ listWidget.width() / 2, - (listWidget.height() - font_get_line_height(FontSpriteBase::MEDIUM)) / 2 }; + (listWidget.height() - font_get_line_height(FontStyle::Medium)) / 2 }; auto ft = Formatter{}; auto textPaint = TextPaint{ colours[1], TextAlignment::CENTRE }; DrawTextWrapped(&dpi, centrePos, listWidth, STR_TILE_INSPECTOR_SELECT_TILE_HINT, ft, textPaint); diff --git a/src/openrct2-ui/windows/Tooltip.cpp b/src/openrct2-ui/windows/Tooltip.cpp index a3f2c56e19..3b1ade74f2 100644 --- a/src/openrct2-ui/windows/Tooltip.cpp +++ b/src/openrct2-ui/windows/Tooltip.cpp @@ -58,11 +58,11 @@ static int32_t FormatTextForTooltip(const OpenRCT2String& message) formattedMessage.args.Add(tempBuffer); format_string(_tooltipText, sizeof(_tooltipText), formattedMessage.str, formattedMessage.args.Data()); - auto textWidth = gfx_get_string_width_new_lined(_tooltipText, FontSpriteBase::SMALL); + auto textWidth = gfx_get_string_width_new_lined(_tooltipText, FontStyle::Small); textWidth = std::min(textWidth, 196); int32_t numLines; - textWidth = gfx_wrap_string(_tooltipText, textWidth + 1, FontSpriteBase::SMALL, &numLines); + textWidth = gfx_wrap_string(_tooltipText, textWidth + 1, FontStyle::Small, &numLines); _tooltipNumLines = numLines; return textWidth; } @@ -75,7 +75,7 @@ void WindowTooltipShow(const OpenRCT2String& message, ScreenCoordsXY screenCoord int32_t textWidth = FormatTextForTooltip(message); int32_t width = textWidth + 3; - int32_t height = ((_tooltipNumLines + 1) * font_get_line_height(FontSpriteBase::SMALL)) + 4; + int32_t height = ((_tooltipNumLines + 1) * font_get_line_height(FontStyle::Small)) + 4; window_tooltip_widgets[WIDX_BACKGROUND].right = width; window_tooltip_widgets[WIDX_BACKGROUND].bottom = height; @@ -195,5 +195,5 @@ static void WindowTooltipPaint(rct_window* w, rct_drawpixelinfo* dpi) // Text left = w->windowPos.x + ((w->width + 1) / 2) - 1; top = w->windowPos.y + 1; - draw_string_centred_raw(dpi, { left, top }, _tooltipNumLines, _tooltipText, FontSpriteBase::SMALL); + draw_string_centred_raw(dpi, { left, top }, _tooltipNumLines, _tooltipText, FontStyle::Small); } diff --git a/src/openrct2-ui/windows/TrackList.cpp b/src/openrct2-ui/windows/TrackList.cpp index 1ee85662c8..1e4c599560 100644 --- a/src/openrct2-ui/windows/TrackList.cpp +++ b/src/openrct2-ui/windows/TrackList.cpp @@ -465,7 +465,7 @@ public: { utf8 pathBuffer[MAX_PATH]; const utf8* pathPtr = pathBuffer; - shorten_path(pathBuffer, sizeof(pathBuffer), path.c_str(), width, FontSpriteBase::MEDIUM); + shorten_path(pathBuffer, sizeof(pathBuffer), path.c_str(), width, FontStyle::Medium); auto ft = Formatter(); ft.Add(pathPtr); DrawTextBasic( diff --git a/src/openrct2/drawing/Drawing.String.cpp b/src/openrct2/drawing/Drawing.String.cpp index 284b7fc94c..cd23bdf4c3 100644 --- a/src/openrct2/drawing/Drawing.String.cpp +++ b/src/openrct2/drawing/Drawing.String.cpp @@ -40,13 +40,13 @@ enum : uint32_t TEXT_DRAW_FLAG_NO_DRAW = 1u << 31 }; -static int32_t ttf_get_string_width(std::string_view text, FontSpriteBase fontSpriteBase, bool noFormatting); +static int32_t ttf_get_string_width(std::string_view text, FontStyle fontStyle, bool noFormatting); /** * * rct2: 0x006C23B1 */ -int32_t gfx_get_string_width_new_lined(std::string_view text, FontSpriteBase fontSpriteBase) +int32_t gfx_get_string_width_new_lined(std::string_view text, FontStyle fontStyle) { thread_local std::string buffer; buffer.clear(); @@ -57,7 +57,7 @@ int32_t gfx_get_string_width_new_lined(std::string_view text, FontSpriteBase fon { if (token.kind == FormatToken::Newline || token.kind == FormatToken::NewlineSmall) { - auto width = gfx_get_string_width(buffer, fontSpriteBase); + auto width = gfx_get_string_width(buffer, fontStyle); if (!maxWidth.has_value() || maxWidth.value() > width) { maxWidth = width; @@ -71,7 +71,7 @@ int32_t gfx_get_string_width_new_lined(std::string_view text, FontSpriteBase fon } if (!maxWidth.has_value()) { - maxWidth = gfx_get_string_width(buffer, fontSpriteBase); + maxWidth = gfx_get_string_width(buffer, fontStyle); } return maxWidth.value(); } @@ -82,14 +82,14 @@ int32_t gfx_get_string_width_new_lined(std::string_view text, FontSpriteBase fon * rct2: 0x006C2321 * buffer (esi) */ -int32_t gfx_get_string_width(std::string_view text, FontSpriteBase fontSpriteBase) +int32_t gfx_get_string_width(std::string_view text, FontStyle fontStyle) { - return ttf_get_string_width(text, fontSpriteBase, false); + return ttf_get_string_width(text, fontStyle, false); } -int32_t gfx_get_string_width_no_formatting(std::string_view text, FontSpriteBase fontSpriteBase) +int32_t gfx_get_string_width_no_formatting(std::string_view text, FontStyle fontStyle) { - return ttf_get_string_width(text, fontSpriteBase, true); + return ttf_get_string_width(text, fontStyle, true); } /** @@ -99,7 +99,7 @@ int32_t gfx_get_string_width_no_formatting(std::string_view text, FontSpriteBase * buffer (esi) * width (edi) */ -int32_t gfx_clip_string(utf8* text, int32_t width, FontSpriteBase fontSpriteBase) +int32_t gfx_clip_string(utf8* text, int32_t width, FontStyle fontStyle) { if (width < 6) { @@ -108,7 +108,7 @@ int32_t gfx_clip_string(utf8* text, int32_t width, FontSpriteBase fontSpriteBase } // If width of the full string is less than allowed width then we don't need to clip - auto clippedWidth = gfx_get_string_width(text, fontSpriteBase); + auto clippedWidth = gfx_get_string_width(text, fontStyle); if (clippedWidth <= width) { return clippedWidth; @@ -130,7 +130,7 @@ int32_t gfx_clip_string(utf8* text, int32_t width, FontSpriteBase fontSpriteBase // Add the ellipsis before checking the width buffer.append("..."); - auto currentWidth = gfx_get_string_width(buffer, fontSpriteBase); + auto currentWidth = gfx_get_string_width(buffer, fontStyle); if (currentWidth < width) { bestLength = buffer.size(); @@ -158,7 +158,7 @@ int32_t gfx_clip_string(utf8* text, int32_t width, FontSpriteBase fontSpriteBase buffer.append(cb); } } - return gfx_get_string_width(text, fontSpriteBase); + return gfx_get_string_width(text, fontStyle); } /** @@ -174,7 +174,7 @@ int32_t gfx_clip_string(utf8* text, int32_t width, FontSpriteBase fontSpriteBase * num_lines (edi) - out * font_height (ebx) - out */ -int32_t gfx_wrap_string(utf8* text, int32_t width, FontSpriteBase fontSpriteBase, int32_t* outNumLines) +int32_t gfx_wrap_string(utf8* text, int32_t width, FontStyle fontStyle, int32_t* outNumLines) { constexpr size_t NULL_INDEX = std::numeric_limits::max(); thread_local std::string buffer; @@ -198,7 +198,7 @@ int32_t gfx_wrap_string(utf8* text, int32_t width, FontSpriteBase fontSpriteBase utf8_write_codepoint(cb, codepoint); buffer.append(cb); - auto lineWidth = gfx_get_string_width(&buffer[currentLineIndex], fontSpriteBase); + auto lineWidth = gfx_get_string_width(&buffer[currentLineIndex], fontStyle); if (lineWidth <= width || (splitIndex == NULL_INDEX && bestSplitIndex == NULL_INDEX)) { if (codepoint == ' ') @@ -222,7 +222,7 @@ int32_t gfx_wrap_string(utf8* text, int32_t width, FontSpriteBase fontSpriteBase buffer.insert(buffer.begin() + splitIndex, '\0'); // Recalculate the line length after splitting - lineWidth = gfx_get_string_width(&buffer[currentLineIndex], fontSpriteBase); + lineWidth = gfx_get_string_width(&buffer[currentLineIndex], fontStyle); maxWidth = std::max(maxWidth, lineWidth); numLines++; @@ -242,7 +242,7 @@ int32_t gfx_wrap_string(utf8* text, int32_t width, FontSpriteBase fontSpriteBase { buffer.push_back('\0'); - auto lineWidth = gfx_get_string_width(&buffer[currentLineIndex], fontSpriteBase); + auto lineWidth = gfx_get_string_width(&buffer[currentLineIndex], fontStyle); maxWidth = std::max(maxWidth, lineWidth); numLines++; @@ -257,7 +257,7 @@ int32_t gfx_wrap_string(utf8* text, int32_t width, FontSpriteBase fontSpriteBase } { // Final line width calculation - auto lineWidth = gfx_get_string_width(&buffer[currentLineIndex], fontSpriteBase); + auto lineWidth = gfx_get_string_width(&buffer[currentLineIndex], fontStyle); maxWidth = std::max(maxWidth, lineWidth); } @@ -274,7 +274,7 @@ void gfx_draw_string_left_centred( { char* buffer = gCommonStringFormatBuffer; format_string(buffer, 256, format, args); - int32_t height = string_get_height_raw(buffer, FontSpriteBase::MEDIUM); + int32_t height = string_get_height_raw(buffer, FontStyle::Medium); gfx_draw_string(dpi, coords - ScreenCoordsXY{ 0, (height / 2) }, buffer, { colour }); } @@ -334,16 +334,16 @@ static void colour_char_window(uint8_t colour, const uint16_t* current_font_flag * dpi : edi */ void draw_string_centred_raw( - rct_drawpixelinfo* dpi, const ScreenCoordsXY& coords, int32_t numLines, char* text, FontSpriteBase fontSpriteBase) + rct_drawpixelinfo* dpi, const ScreenCoordsXY& coords, int32_t numLines, char* text, FontStyle fontStyle) { ScreenCoordsXY screenCoords(dpi->x, dpi->y); - gfx_draw_string(dpi, screenCoords, "", { COLOUR_BLACK, fontSpriteBase }); + gfx_draw_string(dpi, screenCoords, "", { COLOUR_BLACK, fontStyle }); screenCoords = coords; for (int32_t i = 0; i <= numLines; i++) { - int32_t width = gfx_get_string_width(text, fontSpriteBase); - gfx_draw_string(dpi, screenCoords - ScreenCoordsXY{ width / 2, 0 }, text, { TEXT_COLOUR_254, fontSpriteBase }); + int32_t width = gfx_get_string_width(text, fontStyle); + gfx_draw_string(dpi, screenCoords - ScreenCoordsXY{ width / 2, 0 }, text, { TEXT_COLOUR_254, fontStyle }); const utf8* ch = text; const utf8* nextCh = nullptr; @@ -354,16 +354,16 @@ void draw_string_centred_raw( } text = const_cast(ch + 1); - screenCoords.y += font_get_line_height(fontSpriteBase); + screenCoords.y += font_get_line_height(fontStyle); } } -int32_t string_get_height_raw(std::string_view text, FontSpriteBase fontBase) +int32_t string_get_height_raw(std::string_view text, FontStyle fontStyle) { int32_t height = 0; - if (fontBase <= FontSpriteBase::MEDIUM) + if (fontStyle <= FontStyle::Medium) height += 10; - else if (fontBase == FontSpriteBase::TINY) + else if (fontStyle == FontStyle::Tiny) height += 6; FmtString fmt(text); @@ -372,13 +372,13 @@ int32_t string_get_height_raw(std::string_view text, FontSpriteBase fontBase) switch (token.kind) { case FormatToken::Newline: - if (fontBase == FontSpriteBase::SMALL || fontBase == FontSpriteBase::MEDIUM) + if (fontStyle == FontStyle::Small || fontStyle == FontStyle::Medium) { height += 10; break; } - if (fontBase == FontSpriteBase::TINY) + if (fontStyle == FontStyle::Tiny) { height += 6; break; @@ -386,13 +386,13 @@ int32_t string_get_height_raw(std::string_view text, FontSpriteBase fontBase) height += 18; break; case FormatToken::NewlineSmall: - if (fontBase == FontSpriteBase::SMALL || fontBase == FontSpriteBase::MEDIUM) + if (fontStyle == FontStyle::Small || fontStyle == FontStyle::Medium) { height += 5; break; } - if (fontBase == FontSpriteBase::TINY) + if (fontStyle == FontStyle::Tiny) { height += 3; break; @@ -400,13 +400,13 @@ int32_t string_get_height_raw(std::string_view text, FontSpriteBase fontBase) height += 9; break; case FormatToken::FontTiny: - fontBase = FontSpriteBase::TINY; + fontStyle = FontStyle::Tiny; break; case FormatToken::FontMedium: - fontBase = FontSpriteBase::MEDIUM; + fontStyle = FontStyle::Medium; break; case FormatToken::FontSmall: - fontBase = FontSpriteBase::SMALL; + fontStyle = FontStyle::Small; break; default: break; @@ -439,8 +439,8 @@ void DrawNewsTicker( gfx_draw_string(dpi, screenCoords, "", { colour }); format_string(buffer, 256, format, args); - gfx_wrap_string(buffer, width, FontSpriteBase::SMALL, &numLines); - lineHeight = font_get_line_height(FontSpriteBase::SMALL); + gfx_wrap_string(buffer, width, FontStyle::Small, &numLines); + lineHeight = font_get_line_height(FontStyle::Small); int32_t numCharactersDrawn = 0; int32_t numCharactersToDraw = ticks; @@ -448,7 +448,7 @@ void DrawNewsTicker( lineY = coords.y - ((numLines * lineHeight) / 2); for (int32_t line = 0; line <= numLines; line++) { - int32_t halfWidth = gfx_get_string_width(buffer, FontSpriteBase::SMALL) / 2; + int32_t halfWidth = gfx_get_string_width(buffer, FontStyle::Small) / 2; FmtString fmt(buffer); for (const auto& token : fmt) @@ -474,7 +474,7 @@ void DrawNewsTicker( } screenCoords = { coords.x - halfWidth, lineY }; - gfx_draw_string(dpi, screenCoords, buffer, { TEXT_COLOUR_254, FontSpriteBase::SMALL }); + gfx_draw_string(dpi, screenCoords, buffer, { TEXT_COLOUR_254, FontStyle::Small }); if (numCharactersDrawn > numCharactersToDraw) { @@ -496,14 +496,14 @@ struct text_draw_info int32_t maxY; int32_t flags; uint8_t palette[8]; - FontSpriteBase font_sprite_base; + ::FontStyle FontStyle; const int8_t* y_offset; }; static void ttf_draw_character_sprite(rct_drawpixelinfo* dpi, int32_t codepoint, text_draw_info* info) { - int32_t characterWidth = font_sprite_get_codepoint_width(info->font_sprite_base, codepoint); - auto sprite = font_sprite_get_codepoint_sprite(info->font_sprite_base, codepoint); + int32_t characterWidth = font_sprite_get_codepoint_width(info->FontStyle, codepoint); + auto sprite = font_sprite_get_codepoint_sprite(info->FontStyle, codepoint); if (!(info->flags & TEXT_DRAW_FLAG_NO_DRAW)) { @@ -537,7 +537,7 @@ static void ttf_draw_string_raw_ttf(rct_drawpixelinfo* dpi, std::string_view tex if (!ttf_initialise()) return; - TTFFontDescriptor* fontDesc = ttf_get_font_from_sprite_base(info->font_sprite_base); + TTFFontDescriptor* fontDesc = ttf_get_font_from_sprite_base(info->FontStyle); if (fontDesc->font == nullptr) { ttf_draw_string_raw_sprite(dpi, text, info); @@ -717,20 +717,20 @@ static void ttf_process_format_code(rct_drawpixelinfo* dpi, const FmtString::tok break; case FormatToken::Newline: info->x = info->startX; - info->y += font_get_line_height(info->font_sprite_base); + info->y += font_get_line_height(info->FontStyle); break; case FormatToken::NewlineSmall: info->x = info->startX; - info->y += font_get_line_height_small(info->font_sprite_base); + info->y += font_get_line_height_small(info->FontStyle); break; case FormatToken::FontTiny: - info->font_sprite_base = FontSpriteBase::TINY; + info->FontStyle = FontStyle::Tiny; break; case FormatToken::FontSmall: - info->font_sprite_base = FontSpriteBase::SMALL; + info->FontStyle = FontStyle::Small; break; case FormatToken::FontMedium: - info->font_sprite_base = FontSpriteBase::MEDIUM; + info->FontStyle = FontStyle::Medium; break; case FormatToken::OutlineEnable: info->flags |= TEXT_DRAW_FLAG_OUTLINE; @@ -970,13 +970,13 @@ static void ttf_process_initial_colour(int32_t colour, text_draw_info* info) void ttf_draw_string( rct_drawpixelinfo* dpi, const_utf8string text, int32_t colour, const ScreenCoordsXY& coords, bool noFormatting, - FontSpriteBase fontSpriteBase, TextDarkness darkness) + FontStyle fontStyle, TextDarkness darkness) { if (text == nullptr) return; text_draw_info info; - info.font_sprite_base = fontSpriteBase; + info.FontStyle = fontStyle; info.flags = 0; info.startX = coords.x; info.startY = coords.y; @@ -1010,10 +1010,10 @@ void ttf_draw_string( dpi->lastStringPos = { info.x, info.y }; } -static int32_t ttf_get_string_width(std::string_view text, FontSpriteBase fontSpriteBase, bool noFormatting) +static int32_t ttf_get_string_width(std::string_view text, FontStyle fontStyle, bool noFormatting) { text_draw_info info; - info.font_sprite_base = fontSpriteBase; + info.FontStyle = fontStyle; info.flags = 0; info.startX = 0; info.startY = 0; @@ -1044,10 +1044,10 @@ static int32_t ttf_get_string_width(std::string_view text, FontSpriteBase fontSp */ 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, FontSpriteBase fontSpriteBase) + bool forceSpriteFont, FontStyle fontStyle) { text_draw_info info; - info.font_sprite_base = fontSpriteBase; + info.FontStyle = fontStyle; info.flags = 0; info.startX = coords.x; info.startY = coords.y; @@ -1070,12 +1070,12 @@ void gfx_draw_string_with_y_offsets( dpi->lastStringPos = { info.x, info.y }; } -void shorten_path(utf8* buffer, size_t bufferSize, const utf8* path, int32_t availableWidth, FontSpriteBase fontSpriteBase) +void shorten_path(utf8* buffer, size_t bufferSize, const utf8* path, int32_t availableWidth, FontStyle fontStyle) { size_t length = strlen(path); // Return full string if it fits - if (gfx_get_string_width(const_cast(path), fontSpriteBase) <= availableWidth) + if (gfx_get_string_width(const_cast(path), fontStyle) <= availableWidth) { safe_strcpy(buffer, path, bufferSize); return; @@ -1104,7 +1104,7 @@ void shorten_path(utf8* buffer, size_t bufferSize, const utf8* path, int32_t ava } while (path[begin] != *PATH_SEPARATOR && path[begin] != '/'); safe_strcpy(buffer + 3, path + begin, bufferSize - 3); - if (gfx_get_string_width(buffer, fontSpriteBase) <= availableWidth) + if (gfx_get_string_width(buffer, fontStyle) <= availableWidth) { return; } diff --git a/src/openrct2/drawing/Drawing.h b/src/openrct2/drawing/Drawing.h index 3ca8103ea8..40e97a5633 100644 --- a/src/openrct2/drawing/Drawing.h +++ b/src/openrct2/drawing/Drawing.h @@ -545,24 +545,24 @@ void gfx_draw_string_no_formatting( void gfx_draw_string_left_centred( rct_drawpixelinfo* dpi, StringId format, void* args, colour_t colour, const ScreenCoordsXY& coords); void draw_string_centred_raw( - rct_drawpixelinfo* dpi, const ScreenCoordsXY& coords, int32_t numLines, char* text, FontSpriteBase fontSpriteBase); + rct_drawpixelinfo* dpi, const ScreenCoordsXY& coords, int32_t numLines, char* text, FontStyle fontStyle); void DrawNewsTicker( rct_drawpixelinfo* dpi, const ScreenCoordsXY& coords, int32_t width, colour_t colour, StringId format, void* args, int32_t ticks); 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, FontSpriteBase fontSpriteBase); + bool forceSpriteFont, FontStyle fontStyle); -int32_t gfx_wrap_string(char* buffer, int32_t width, FontSpriteBase fontSpriteBase, int32_t* num_lines); -int32_t gfx_get_string_width(std::string_view text, FontSpriteBase fontSpriteBase); -int32_t gfx_get_string_width_new_lined(std::string_view text, FontSpriteBase fontSpriteBase); -int32_t gfx_get_string_width_no_formatting(std::string_view text, FontSpriteBase fontSpriteBase); -int32_t string_get_height_raw(std::string_view text, FontSpriteBase fontBase); -int32_t gfx_clip_string(char* buffer, int32_t width, FontSpriteBase fontSpriteBase); -void shorten_path(utf8* buffer, size_t bufferSize, const utf8* path, int32_t availableWidth, FontSpriteBase fontSpriteBase); +int32_t gfx_wrap_string(char* buffer, int32_t width, FontStyle fontStyle, int32_t* num_lines); +int32_t gfx_get_string_width(std::string_view text, FontStyle fontStyle); +int32_t gfx_get_string_width_new_lined(std::string_view text, FontStyle fontStyle); +int32_t gfx_get_string_width_no_formatting(std::string_view text, FontStyle fontStyle); +int32_t string_get_height_raw(std::string_view text, FontStyle fontStyle); +int32_t gfx_clip_string(char* buffer, int32_t width, FontStyle fontStyle); +void shorten_path(utf8* buffer, size_t bufferSize, const utf8* path, int32_t availableWidth, FontStyle fontStyle); void ttf_draw_string( rct_drawpixelinfo* dpi, const_utf8string text, int32_t colour, const ScreenCoordsXY& coords, bool noFormatting, - FontSpriteBase fontSpriteBase, TextDarkness darkness); + FontStyle fontStyle, TextDarkness darkness); // scrolling text void scrolling_text_initialise_bitmaps(); diff --git a/src/openrct2/drawing/Font.cpp b/src/openrct2/drawing/Font.cpp index facebb658a..04dc86a7f7 100644 --- a/src/openrct2/drawing/Font.cpp +++ b/src/openrct2/drawing/Font.cpp @@ -13,6 +13,7 @@ #include "../localisation/Language.h" #include "../localisation/LocalisationService.h" #include "../sprites.h" +#include "../util/Util.h" #include "Drawing.h" #include "TTF.h" @@ -20,14 +21,14 @@ #include #include -static constexpr const int32_t SpriteFontLineHeight[FONT_SIZE_COUNT] = { +static constexpr const int32_t SpriteFontLineHeight[FontStyleCount] = { + 10, + 10, 6, - 10, - 10, }; -static uint8_t _spriteFontCharacterWidths[FONT_SIZE_COUNT][FONT_SPRITE_GLYPH_COUNT]; -static uint8_t _additionalSpriteFontCharacterWidth[FONT_SIZE_COUNT][SPR_G2_GLYPH_COUNT] = {}; +static uint8_t _spriteFontCharacterWidths[FontStyleCount][FONT_SPRITE_GLYPH_COUNT]; +static uint8_t _additionalSpriteFontCharacterWidth[FontStyleCount][SPR_G2_GLYPH_COUNT] = {}; #ifndef NO_TTF TTFFontSetDescriptor* gCurrentTTFFontSet; @@ -244,9 +245,9 @@ void font_sprite_initialise_characters() _biggestCodepointValue = std::max(_biggestCodepointValue, entry.first); } - for (int32_t fontSize = 0; fontSize < FONT_SIZE_COUNT; fontSize++) + for (const auto& fontStyle : FontStyles) { - int32_t glyphOffset = fontSize * FONT_SPRITE_GLYPH_COUNT; + int32_t glyphOffset = EnumValue(fontStyle) * FONT_SPRITE_GLYPH_COUNT; for (uint8_t glyphIndex = 0; glyphIndex < FONT_SPRITE_GLYPH_COUNT; glyphIndex++) { const rct_g1_element* g1 = gfx_get_g1_element(glyphIndex + SPR_CHAR_START + glyphOffset); @@ -256,13 +257,13 @@ void font_sprite_initialise_characters() width = g1->width + (2 * g1->x_offset) - 1; } - _spriteFontCharacterWidths[fontSize][glyphIndex] = static_cast(width); + _spriteFontCharacterWidths[EnumValue(fontStyle)][glyphIndex] = static_cast(width); } } - for (uint8_t fontSize : { FONT_SIZE_SMALL, FONT_SIZE_MEDIUM, FONT_SIZE_TINY }) + for (const auto& fontStyle : FontStyles) { - int32_t glyphOffset = fontSize * SPR_G2_GLYPH_COUNT; + int32_t glyphOffset = EnumValue(fontStyle) * SPR_G2_GLYPH_COUNT; for (int32_t glyphIndex = 0; glyphIndex < SPR_G2_GLYPH_COUNT; glyphIndex++) { const rct_g1_element* g1 = gfx_get_g1_element(glyphIndex + SPR_G2_CHAR_BEGIN + glyphOffset); @@ -272,7 +273,7 @@ void font_sprite_initialise_characters() width = g1->width + (2 * g1->x_offset) - 1; } - _additionalSpriteFontCharacterWidth[fontSize][glyphIndex] = static_cast(width); + _additionalSpriteFontCharacterWidth[EnumValue(fontStyle)][glyphIndex] = static_cast(width); } } @@ -296,10 +297,10 @@ int32_t font_sprite_get_codepoint_offset(int32_t codepoint) return codepoint - 32; } -int32_t font_sprite_get_codepoint_width(FontSpriteBase fontSpriteBase, int32_t codepoint) +int32_t font_sprite_get_codepoint_width(FontStyle fontStyle, int32_t codepoint) { int32_t glyphIndex = font_sprite_get_codepoint_offset(codepoint); - int32_t baseFontIndex = font_get_font_index_from_sprite_base(fontSpriteBase); + auto baseFontIndex = EnumValue(fontStyle); if (glyphIndex >= FONT_SPRITE_GLYPH_COUNT) { glyphIndex = (SPR_CHAR_START + glyphIndex) - SPR_G2_CHAR_BEGIN; @@ -320,49 +321,21 @@ int32_t font_sprite_get_codepoint_width(FontSpriteBase fontSpriteBase, int32_t c return _spriteFontCharacterWidths[baseFontIndex][glyphIndex]; } -ImageId font_sprite_get_codepoint_sprite(FontSpriteBase fontSpriteBase, int32_t codepoint) +ImageId font_sprite_get_codepoint_sprite(FontStyle fontStyle, int32_t codepoint) { - int32_t offset = static_cast(fontSpriteBase); + int32_t offset = EnumValue(fontStyle) * FONT_SPRITE_GLYPH_COUNT; auto codePointOffset = font_sprite_get_codepoint_offset(codepoint); if (codePointOffset > FONT_SPRITE_GLYPH_COUNT) { - offset = font_get_font_index_from_sprite_base(fontSpriteBase) * SPR_G2_GLYPH_COUNT; + offset = EnumValue(fontStyle) * SPR_G2_GLYPH_COUNT; } return ImageId(SPR_CHAR_START + offset + codePointOffset, COLOUR_BLACK); } -int32_t font_get_font_index_from_sprite_base(FontSpriteBase spriteBase) +int32_t font_get_line_height(FontStyle fontStyle) { - switch (spriteBase) - { - case FontSpriteBase::TINY: - return FONT_SIZE_TINY; - case FontSpriteBase::SMALL: - return FONT_SIZE_SMALL; - default: - case FontSpriteBase::MEDIUM: - return FONT_SIZE_MEDIUM; - } -} - -int32_t font_get_size_from_sprite_base(FontSpriteBase spriteBase) -{ - switch (spriteBase) - { - case FontSpriteBase::TINY: - return 0; - case FontSpriteBase::SMALL: - return 1; - default: - case FontSpriteBase::MEDIUM: - return 2; - } -} - -int32_t font_get_line_height(FontSpriteBase fontSpriteBase) -{ - int32_t fontSize = font_get_size_from_sprite_base(fontSpriteBase); + auto fontSize = EnumValue(fontStyle); #ifndef NO_TTF if (LocalisationService_UseTrueTypeFont()) { @@ -372,9 +345,9 @@ int32_t font_get_line_height(FontSpriteBase fontSpriteBase) return SpriteFontLineHeight[fontSize]; } -int32_t font_get_line_height_small(FontSpriteBase fontSpriteBase) +int32_t font_get_line_height_small(FontStyle fontStyle) { - return font_get_line_height(fontSpriteBase) / 2; + return font_get_line_height(fontStyle) / 2; } bool font_supports_string_sprite(const utf8* text) @@ -404,11 +377,11 @@ bool font_supports_string_sprite(const utf8* text) return true; } -bool font_supports_string_ttf(const utf8* text, int32_t fontSize) +bool font_supports_string_ttf(const utf8* text, FontStyle fontStyle) { #ifndef NO_TTF const utf8* src = text; - const TTF_Font* font = gCurrentTTFFontSet->size[fontSize].font; + const TTF_Font* font = gCurrentTTFFontSet->size[EnumValue(fontStyle)].font; if (font == nullptr) { return false; @@ -429,11 +402,11 @@ bool font_supports_string_ttf(const utf8* text, int32_t fontSize) #endif // NO_TTF } -bool font_supports_string(const utf8* text, int32_t fontSize) +bool font_supports_string(const utf8* text, FontStyle fontStyle) { if (LocalisationService_UseTrueTypeFont()) { - return font_supports_string_ttf(text, fontSize); + return font_supports_string_ttf(text, fontStyle); } return font_supports_string_sprite(text); diff --git a/src/openrct2/drawing/Font.h b/src/openrct2/drawing/Font.h index 36f4a51151..e5e527334e 100644 --- a/src/openrct2/drawing/Font.h +++ b/src/openrct2/drawing/Font.h @@ -13,22 +13,19 @@ #include "../core/String.hpp" #include "../drawing/ImageId.hpp" +#include + constexpr const uint16_t FONT_SPRITE_GLYPH_COUNT = 224; -enum +enum class FontStyle : uint8_t { - FONT_SIZE_TINY = 2, - FONT_SIZE_SMALL = 0, - FONT_SIZE_MEDIUM = 1, - FONT_SIZE_COUNT = 3 + Small = 0, + Medium = 1, + Tiny = 2, }; -enum class FontSpriteBase : int16_t -{ - TINY = FONT_SIZE_TINY * FONT_SPRITE_GLYPH_COUNT, - SMALL = FONT_SIZE_SMALL * FONT_SPRITE_GLYPH_COUNT, - MEDIUM = FONT_SIZE_MEDIUM * FONT_SPRITE_GLYPH_COUNT, -}; +constexpr const uint8_t FontStyleCount = 3; +constexpr const std::array FontStyles = { FontStyle::Small, FontStyle::Medium, FontStyle::Tiny }; #ifndef NO_TTF @@ -48,7 +45,7 @@ struct TTFFontDescriptor struct TTFFontSetDescriptor { - TTFFontDescriptor size[FONT_SIZE_COUNT]; + TTFFontDescriptor size[FontStyleCount]; }; extern TTFFontSetDescriptor* gCurrentTTFFontSet; @@ -57,12 +54,10 @@ extern TTFFontSetDescriptor* gCurrentTTFFontSet; void font_sprite_initialise_characters(); int32_t font_sprite_get_codepoint_offset(int32_t codepoint); -int32_t font_sprite_get_codepoint_width(FontSpriteBase fontSpriteBase, int32_t codepoint); -ImageId font_sprite_get_codepoint_sprite(FontSpriteBase fontSpriteBase, int32_t codepoint); -int32_t font_get_font_index_from_sprite_base(FontSpriteBase spriteBase); -int32_t font_get_size_from_sprite_base(FontSpriteBase spriteBase); -int32_t font_get_line_height(FontSpriteBase fontSpriteBase); -int32_t font_get_line_height_small(FontSpriteBase fontSpriteBase); +int32_t font_sprite_get_codepoint_width(FontStyle fontStyle, int32_t codepoint); +ImageId font_sprite_get_codepoint_sprite(FontStyle fontStyle, int32_t codepoint); +int32_t font_get_line_height(FontStyle fontStyle); +int32_t font_get_line_height_small(FontStyle fontStyle); bool font_supports_string_sprite(const utf8* text); -bool font_supports_string_ttf(const utf8* text, int32_t fontSize); -bool font_supports_string(const utf8* text, int32_t fontSize); +bool font_supports_string_ttf(const utf8* text, FontStyle fontStyle); +bool font_supports_string(const utf8* text, FontStyle fontStyle); diff --git a/src/openrct2/drawing/ScrollingText.cpp b/src/openrct2/drawing/ScrollingText.cpp index 2f81a00104..6056fd3108 100644 --- a/src/openrct2/drawing/ScrollingText.cpp +++ b/src/openrct2/drawing/ScrollingText.cpp @@ -58,7 +58,8 @@ void scrolling_text_initialise_bitmaps() for (int32_t i = 0; i < FONT_SPRITE_GLYPH_COUNT; i++) { std::fill_n(drawingSurface, sizeof(drawingSurface), 0x00); - gfx_draw_sprite_software(&dpi, ImageId(SPR_CHAR_START + static_cast(FontSpriteBase::TINY) + i), { -1, 0 }); + gfx_draw_sprite_software( + &dpi, ImageId(SPR_CHAR_START + (EnumValue(FontStyle::Tiny) * FONT_SPRITE_GLYPH_COUNT) + i), { -1, 0 }); for (int32_t x = 0; x < 8; x++) { @@ -79,7 +80,8 @@ void scrolling_text_initialise_bitmaps() for (int32_t i = 0; i < SPR_G2_GLYPH_COUNT; i++) { std::fill_n(drawingSurface, sizeof(drawingSurface), 0x00); - gfx_draw_sprite_software(&dpi, ImageId(SPR_G2_CHAR_BEGIN + (FONT_SIZE_TINY * SPR_G2_GLYPH_COUNT) + i), { -1, 0 }); + gfx_draw_sprite_software( + &dpi, ImageId(SPR_G2_CHAR_BEGIN + (EnumValue(FontStyle::Tiny) * SPR_G2_GLYPH_COUNT) + i), { -1, 0 }); for (int32_t x = 0; x < 8; x++) { @@ -1508,7 +1510,7 @@ static void scrolling_text_set_bitmap_for_sprite( CodepointView codepoints(token.text); for (auto codepoint : codepoints) { - auto characterWidth = font_sprite_get_codepoint_width(FontSpriteBase::TINY, codepoint); + auto characterWidth = font_sprite_get_codepoint_width(FontStyle::Tiny, codepoint); auto characterBitmap = font_sprite_get_codepoint_bitmap(codepoint); for (; characterWidth != 0; characterWidth--, characterBitmap++) { @@ -1556,7 +1558,7 @@ static void scrolling_text_set_bitmap_for_ttf( std::string_view text, int32_t scroll, uint8_t* bitmap, const int16_t* scrollPositionOffsets, colour_t colour) { #ifndef NO_TTF - auto fontDesc = ttf_get_font_from_sprite_base(FontSpriteBase::TINY); + auto fontDesc = ttf_get_font_from_sprite_base(FontStyle::Tiny); if (fontDesc->font == nullptr) { scrolling_text_set_bitmap_for_sprite(text, scroll, bitmap, scrollPositionOffsets, colour); diff --git a/src/openrct2/drawing/TTF.cpp b/src/openrct2/drawing/TTF.cpp index 5f923e8924..5b5403afdf 100644 --- a/src/openrct2/drawing/TTF.cpp +++ b/src/openrct2/drawing/TTF.cpp @@ -95,7 +95,7 @@ static void ttf_toggle_hinting(bool) return; } - for (int32_t i = 0; i < FONT_SIZE_COUNT; i++) + for (int32_t i = 0; i < FontStyleCount; i++) { TTFFontDescriptor* fontDesc = &(gCurrentTTFFontSet->size[i]); bool use_hinting = gConfigFonts.EnableHinting && fontDesc->hinting_threshold; @@ -121,7 +121,7 @@ bool ttf_initialise() return false; } - for (int32_t i = 0; i < FONT_SIZE_COUNT; i++) + for (int32_t i = 0; i < FontStyleCount; i++) { TTFFontDescriptor* fontDesc = &(gCurrentTTFFontSet->size[i]); @@ -157,7 +157,7 @@ void ttf_dispose() ttf_surface_cache_dispose_all(); ttf_getwidth_cache_dispose_all(); - for (int32_t i = 0; i < FONT_SIZE_COUNT; i++) + for (int32_t i = 0; i < FontStyleCount; i++) { TTFFontDescriptor* fontDesc = &(gCurrentTTFFontSet->size[i]); if (fontDesc->font != nullptr) @@ -347,10 +347,10 @@ uint32_t ttf_getwidth_cache_get_or_add(TTF_Font* font, std::string_view text) return entry->width; } -TTFFontDescriptor* ttf_get_font_from_sprite_base(FontSpriteBase spriteBase) +TTFFontDescriptor* ttf_get_font_from_sprite_base(FontStyle fontStyle) { FontLockHelper lock(_mutex); - return &gCurrentTTFFontSet->size[font_get_size_from_sprite_base(spriteBase)]; + return &gCurrentTTFFontSet->size[EnumValue(fontStyle)]; } bool ttf_provides_glyph(const TTF_Font* font, codepoint_t codepoint) diff --git a/src/openrct2/drawing/TTF.h b/src/openrct2/drawing/TTF.h index 40c72148c4..cc59baac54 100644 --- a/src/openrct2/drawing/TTF.h +++ b/src/openrct2/drawing/TTF.h @@ -26,7 +26,7 @@ struct TTFSurface int32_t pitch; }; -TTFFontDescriptor* ttf_get_font_from_sprite_base(FontSpriteBase spriteBase); +TTFFontDescriptor* ttf_get_font_from_sprite_base(FontStyle fontStyle); void ttf_toggle_hinting(); TTFSurface* ttf_surface_cache_get_or_add(TTF_Font* font, std::string_view text); uint32_t ttf_getwidth_cache_get_or_add(TTF_Font* font, std::string_view text); diff --git a/src/openrct2/drawing/Text.cpp b/src/openrct2/drawing/Text.cpp index 1bd21d93a9..13f58850a4 100644 --- a/src/openrct2/drawing/Text.cpp +++ b/src/openrct2/drawing/Text.cpp @@ -34,9 +34,9 @@ public: Buffer = source; Paint = paint; - MaxWidth = gfx_wrap_string(Buffer, width, paint.SpriteBase, &LineCount); + MaxWidth = gfx_wrap_string(Buffer, width, paint.FontStyle, &LineCount); LineCount += 1; - LineHeight = font_get_line_height(paint.SpriteBase); + LineHeight = font_get_line_height(paint.FontStyle); } void Draw(rct_drawpixelinfo* dpi, const ScreenCoordsXY& coords) @@ -84,8 +84,8 @@ public: static void DrawText( rct_drawpixelinfo* dpi, const ScreenCoordsXY& coords, const TextPaint& paint, const_utf8string text, bool noFormatting) { - int32_t width = noFormatting ? gfx_get_string_width_no_formatting(text, paint.SpriteBase) - : gfx_get_string_width(text, paint.SpriteBase); + int32_t width = noFormatting ? gfx_get_string_width_no_formatting(text, paint.FontStyle) + : gfx_get_string_width(text, paint.FontStyle); auto alignedCoords = coords; switch (paint.Alignment) @@ -100,7 +100,7 @@ static void DrawText( break; } - ttf_draw_string(dpi, text, paint.Colour, alignedCoords, noFormatting, paint.SpriteBase, paint.Darkness); + ttf_draw_string(dpi, text, paint.Colour, alignedCoords, noFormatting, paint.FontStyle, paint.Darkness); if (paint.UnderlineText == TextUnderline::On) { @@ -150,7 +150,7 @@ void DrawTextEllipsised( { utf8 buffer[512]; format_string(buffer, sizeof(buffer), format, ft.Data()); - gfx_clip_string(buffer, width, textPaint.SpriteBase); + gfx_clip_string(buffer, width, textPaint.FontStyle); DrawText(dpi, coords, textPaint, buffer); } diff --git a/src/openrct2/drawing/Text.h b/src/openrct2/drawing/Text.h index e544a1c4cd..2430a76823 100644 --- a/src/openrct2/drawing/Text.h +++ b/src/openrct2/drawing/Text.h @@ -40,7 +40,7 @@ enum class TextDarkness struct TextPaint { colour_t Colour = COLOUR_BLACK; - FontSpriteBase SpriteBase = FontSpriteBase::MEDIUM; + ::FontStyle FontStyle = FontStyle::Medium; TextUnderline UnderlineText = TextUnderline::Off; TextAlignment Alignment = TextAlignment::LEFT; TextDarkness Darkness = TextDarkness::Regular; @@ -50,8 +50,8 @@ struct TextPaint : Colour(colour) { } - TextPaint(FontSpriteBase spriteBase) - : SpriteBase(spriteBase) + TextPaint(::FontStyle fontStyle) + : FontStyle(fontStyle) { } TextPaint(TextUnderline underlineText) @@ -63,9 +63,9 @@ struct TextPaint { } - TextPaint(colour_t colour, FontSpriteBase spriteBase) + TextPaint(colour_t colour, ::FontStyle fontStyle) : Colour(colour) - , SpriteBase(spriteBase) + , FontStyle(fontStyle) { } TextPaint(colour_t colour, TextUnderline underlineText) @@ -79,13 +79,13 @@ struct TextPaint { } - TextPaint(FontSpriteBase spriteBase, TextUnderline underlineText) - : SpriteBase(spriteBase) + TextPaint(::FontStyle fontStyle, TextUnderline underlineText) + : FontStyle(fontStyle) , UnderlineText(underlineText) { } - TextPaint(FontSpriteBase spriteBase, TextAlignment alignment) - : SpriteBase(spriteBase) + TextPaint(::FontStyle fontStyle, TextAlignment alignment) + : FontStyle(fontStyle) , Alignment(alignment) { } @@ -95,21 +95,21 @@ struct TextPaint { } - TextPaint(colour_t colour, FontSpriteBase spriteBase, TextUnderline underlineText) + TextPaint(colour_t colour, ::FontStyle fontStyle, TextUnderline underlineText) : Colour(colour) - , SpriteBase(spriteBase) + , FontStyle(fontStyle) , UnderlineText(underlineText) { } - TextPaint(colour_t colour, FontSpriteBase spriteBase, TextAlignment alignment) + TextPaint(colour_t colour, ::FontStyle fontStyle, TextAlignment alignment) : Colour(colour) - , SpriteBase(spriteBase) + , FontStyle(fontStyle) , Alignment(alignment) { } - TextPaint(colour_t colour, FontSpriteBase spriteBase, TextDarkness darkness) + TextPaint(colour_t colour, ::FontStyle fontStyle, TextDarkness darkness) : Colour(colour) - , SpriteBase(spriteBase) + , FontStyle(fontStyle) , Darkness(darkness) { } @@ -119,23 +119,23 @@ struct TextPaint , Alignment(alignment) { } - TextPaint(FontSpriteBase spriteBase, TextUnderline underlineText, TextAlignment alignment) - : SpriteBase(spriteBase) + TextPaint(::FontStyle fontStyle, TextUnderline underlineText, TextAlignment alignment) + : FontStyle(fontStyle) , UnderlineText(underlineText) , Alignment(alignment) { } - TextPaint(colour_t colour, FontSpriteBase spriteBase, TextUnderline underlineText, TextAlignment alignment) + TextPaint(colour_t colour, ::FontStyle fontStyle, TextUnderline underlineText, TextAlignment alignment) : Colour(colour) - , SpriteBase(spriteBase) + , FontStyle(fontStyle) , UnderlineText(underlineText) , Alignment(alignment) { } - TextPaint(colour_t colour, FontSpriteBase spriteBase, TextAlignment alignment, TextDarkness darkness) + TextPaint(colour_t colour, ::FontStyle fontStyle, TextAlignment alignment, TextDarkness darkness) : Colour(colour) - , SpriteBase(spriteBase) + , FontStyle(fontStyle) , Alignment(alignment) , Darkness(darkness) { diff --git a/src/openrct2/entity/MoneyEffect.cpp b/src/openrct2/entity/MoneyEffect.cpp index 76e8b3510c..67778888b4 100644 --- a/src/openrct2/entity/MoneyEffect.cpp +++ b/src/openrct2/entity/MoneyEffect.cpp @@ -60,7 +60,7 @@ void MoneyEffect::CreateAt(money64 value, const CoordsXYZ& effectPos, bool verti auto [stringId, newValue] = moneyEffect->GetStringId(); char buffer[128]; format_string(buffer, 128, stringId, &newValue); - offsetX = -(gfx_get_string_width(buffer, FontSpriteBase::MEDIUM) / 2); + offsetX = -(gfx_get_string_width(buffer, FontStyle::Medium) / 2); } moneyEffect->OffsetX = offsetX; moneyEffect->Wiggle = 0; diff --git a/src/openrct2/interface/Chat.cpp b/src/openrct2/interface/Chat.cpp index 9d7e6a8312..382ffd8300 100644 --- a/src/openrct2/interface/Chat.cpp +++ b/src/openrct2/interface/Chat.cpp @@ -198,10 +198,10 @@ void chat_draw(rct_drawpixelinfo* dpi, uint8_t chatBackgroundColor) gfx_set_dirty_blocks({ screenCoords, { screenCoords + ScreenCoordsXY{ _chatWidth, inputLineHeight + 15 } } }); // TODO: Show caret if the input text has multiple lines - if (_chatCaretTicks < 15 && gfx_get_string_width(lineBuffer, FontSpriteBase::MEDIUM) < (_chatWidth - 10)) + if (_chatCaretTicks < 15 && gfx_get_string_width(lineBuffer, FontStyle::Medium) < (_chatWidth - 10)) { lineBuffer.assign(_chatCurrentLine, _chatTextInputSession->SelectionStart); - int32_t caretX = screenCoords.x + gfx_get_string_width(lineBuffer, FontSpriteBase::MEDIUM); + int32_t caretX = screenCoords.x + gfx_get_string_width(lineBuffer, FontStyle::Medium); int32_t caretY = screenCoords.y + 14; gfx_fill_rect(dpi, { { caretX, caretY }, { caretX + 6, caretY + 1 } }, PALETTE_INDEX_56); @@ -278,8 +278,8 @@ static int32_t chat_history_draw_string( FormatStringToBuffer(gCommonStringFormatBuffer, sizeof(gCommonStringFormatBuffer), "{OUTLINE}{WHITE}{STRING}", text); int32_t numLines; - gfx_wrap_string(buffer, width, FontSpriteBase::MEDIUM, &numLines); - auto lineHeight = font_get_line_height(FontSpriteBase::MEDIUM); + gfx_wrap_string(buffer, width, FontStyle::Medium, &numLines); + auto lineHeight = font_get_line_height(FontStyle::Medium); int32_t expectedY = screenCoords.y - (numLines * lineHeight); if (expectedY < 50) @@ -305,8 +305,8 @@ int32_t chat_string_wrapped_get_height(void* args, int32_t width) format_string(buffer, 256, STR_STRING, args); int32_t numLines; - gfx_wrap_string(buffer, width, FontSpriteBase::MEDIUM, &numLines); - int32_t lineHeight = font_get_line_height(FontSpriteBase::MEDIUM); + gfx_wrap_string(buffer, width, FontStyle::Medium, &numLines); + int32_t lineHeight = font_get_line_height(FontStyle::Medium); int32_t lineY = 0; for (int32_t line = 0; line <= numLines; ++line) diff --git a/src/openrct2/interface/Fonts.cpp b/src/openrct2/interface/Fonts.cpp index 9d3ac4dabf..14b7a69248 100644 --- a/src/openrct2/interface/Fonts.cpp +++ b/src/openrct2/interface/Fonts.cpp @@ -14,6 +14,7 @@ #include "../drawing/TTF.h" #include "../localisation/Language.h" #include "../localisation/LocalisationService.h" +#include "../util/Util.h" #include "FontFamilies.h" using namespace OpenRCT2::Localisation; @@ -25,81 +26,81 @@ uint8_t const HINTING_THRESHOLD_MEDIUM = 60; // clang-format off TTFFontSetDescriptor TTFFontMSGothic = { { + { "msgothic.ttc", "MS PGothic", 12, 1, 0, 14, HINTING_THRESHOLD_MEDIUM, nullptr }, + { "msgothic.ttc", "MS PGothic", 12, 1, 0, 14, HINTING_THRESHOLD_MEDIUM, nullptr }, { "msgothic.ttc", "MS PGothic", 9, 1, 1, 9, HINTING_THRESHOLD_MEDIUM, nullptr }, - { "msgothic.ttc", "MS PGothic", 12, 1, 0, 14, HINTING_THRESHOLD_MEDIUM, nullptr }, - { "msgothic.ttc", "MS PGothic", 12, 1, 0, 14, HINTING_THRESHOLD_MEDIUM, nullptr }, } }; TTFFontSetDescriptor TTFFontNotoSansMono = { { + { "NotoSansCJK-Regular.ttc", "Noto Sans Mono CJK JP", 12, 1, -3, 14, HINTING_THRESHOLD_MEDIUM, nullptr }, + { "NotoSansCJK-Regular.ttc", "Noto Sans Mono CJK JP", 12, 1, -3, 14, HINTING_THRESHOLD_MEDIUM, nullptr }, { "NotoSansCJK-Regular.ttc", "Noto Sans Mono CJK JP", 9, 1, -2, 9, HINTING_THRESHOLD_MEDIUM, nullptr }, - { "NotoSansCJK-Regular.ttc", "Noto Sans Mono CJK JP", 12, 1, -3, 14, HINTING_THRESHOLD_MEDIUM, nullptr }, - { "NotoSansCJK-Regular.ttc", "Noto Sans Mono CJK JP", 12, 1, -3, 14, HINTING_THRESHOLD_MEDIUM, nullptr }, } }; TTFFontSetDescriptor TTFFontHiragano = { { + { u8"ヒラギノ丸ゴ ProN W4.ttc", "Hiragino Maru Gothic ProN", 11, 1, 0, 13, HINTING_THRESHOLD_MEDIUM, nullptr }, + { u8"ヒラギノ丸ゴ ProN W4.ttc", "Hiragino Maru Gothic ProN", 11, 1, 0, 13, HINTING_THRESHOLD_MEDIUM, nullptr }, { u8"ヒラギノ丸ゴ ProN W4.ttc", "Hiragino Maru Gothic ProN", 9, 1, 1, 9, HINTING_THRESHOLD_MEDIUM, nullptr }, - { u8"ヒラギノ丸ゴ ProN W4.ttc", "Hiragino Maru Gothic ProN", 11, 1, 0, 13, HINTING_THRESHOLD_MEDIUM, nullptr }, - { u8"ヒラギノ丸ゴ ProN W4.ttc", "Hiragino Maru Gothic ProN", 11, 1, 0, 13, HINTING_THRESHOLD_MEDIUM, nullptr }, } }; TTFFontSetDescriptor TTFFontMingLiu = { { - { "msjh.ttc", "JhengHei", 9, -1, -1, 9, HINTING_THRESHOLD_MEDIUM, nullptr }, { "mingliu.ttc", "MingLiU", 11, 1, 1, 14, HINTING_THRESHOLD_MEDIUM, nullptr }, { "mingliu.ttc", "MingLiU", 12, 1, 0, 15, HINTING_THRESHOLD_MEDIUM, nullptr }, + { "msjh.ttc", "JhengHei", 9, -1, -1, 9, HINTING_THRESHOLD_MEDIUM, nullptr }, } }; TTFFontSetDescriptor TTFFontHeiti = { { - { u8"华文黑体.ttf", "STHeiti", 9, -1, -1, 9, HINTING_THRESHOLD_MEDIUM, nullptr }, { u8"华文黑体.ttf", "STHeiti", 11, 1, 1, 14, HINTING_THRESHOLD_MEDIUM, nullptr }, { u8"华文黑体.ttf", "STHeiti", 12, 1, 0, 15, HINTING_THRESHOLD_MEDIUM, nullptr }, + { u8"华文黑体.ttf", "STHeiti", 9, -1, -1, 9, HINTING_THRESHOLD_MEDIUM, nullptr }, } }; TTFFontSetDescriptor TTFFontSimSun = { { - { "msyh.ttc", "Microsoft YaHei", 9, -1, -1, 9, HINTING_THRESHOLD_MEDIUM, nullptr }, { "simsun.ttc", "SimSun", 11, 1, -1, 14, HINTING_THRESHOLD_MEDIUM, nullptr }, { "simsun.ttc", "SimSun", 12, 1, -2, 15, HINTING_THRESHOLD_MEDIUM, nullptr }, + { "msyh.ttc", "Microsoft YaHei", 9, -1, -1, 9, HINTING_THRESHOLD_MEDIUM, nullptr }, } }; TTFFontSetDescriptor TTFFontLiHeiPro = { { - { u8"儷黑 Pro.ttf", "LiHei Pro", 9, 1, -1, 9, HINTING_THRESHOLD_MEDIUM, nullptr }, { u8"儷黑 Pro.ttf", "LiHei Pro", 11, 1, 0, 14, HINTING_THRESHOLD_MEDIUM, nullptr }, { u8"儷黑 Pro.ttf", "LiHei Pro", 12, 1, 0, 15, HINTING_THRESHOLD_MEDIUM, nullptr }, + { u8"儷黑 Pro.ttf", "LiHei Pro", 9, 1, -1, 9, HINTING_THRESHOLD_MEDIUM, nullptr }, } }; TTFFontSetDescriptor TTFFontGulim = { { + { "gulim.ttc", "Gulim", 12, 1, 0, 15, HINTING_THRESHOLD_MEDIUM, nullptr }, + { "gulim.ttc", "Gulim", 12, 1, 0, 15, HINTING_THRESHOLD_MEDIUM, nullptr }, { "gulim.ttc", "Gulim", 10, 1, 0, 10, HINTING_DISABLED, nullptr }, - { "gulim.ttc", "Gulim", 12, 1, 0, 15, HINTING_THRESHOLD_MEDIUM, nullptr }, - { "gulim.ttc", "Gulim", 12, 1, 0, 15, HINTING_THRESHOLD_MEDIUM, nullptr }, } }; TTFFontSetDescriptor TTFFontMalgun = { { + { "malgun.ttf", "Malgun Gothic", 12, 1, -3, 15, HINTING_THRESHOLD_LOW, nullptr }, + { "malgun.ttf", "Malgun Gothic", 12, 1, -3, 15, HINTING_THRESHOLD_LOW, nullptr }, { "malgun.ttf", "Malgun Gothic", 10, 1, -3, 10, HINTING_THRESHOLD_LOW, nullptr }, - { "malgun.ttf", "Malgun Gothic", 12, 1, -3, 15, HINTING_THRESHOLD_LOW, nullptr }, - { "malgun.ttf", "Malgun Gothic", 12, 1, -3, 15, HINTING_THRESHOLD_LOW, nullptr }, } }; TTFFontSetDescriptor TTFFontNanum = { { + { "NanumGothic.ttf", "Nanum Gothic", 12, 1, -2, 15, HINTING_THRESHOLD_LOW, nullptr }, + { "NanumGothic.ttf", "Nanum Gothic", 12, 1, -2, 15, HINTING_THRESHOLD_LOW, nullptr }, { "NanumGothic.ttf", "Nanum Gothic", 10, 1, -2, 10, HINTING_DISABLED, nullptr }, - { "NanumGothic.ttf", "Nanum Gothic", 12, 1, -2, 15, HINTING_THRESHOLD_LOW, nullptr }, - { "NanumGothic.ttf", "Nanum Gothic", 12, 1, -2, 15, HINTING_THRESHOLD_LOW, nullptr }, } }; TTFFontSetDescriptor TTFFontArial = { { + { "arial.ttf", "Arial", 12, 0, -1, 12, HINTING_THRESHOLD_LOW, nullptr }, + { "arial.ttf", "Arial", 12, 0, -1, 12, HINTING_THRESHOLD_LOW, nullptr }, { "arial.ttf", "Arial", 10, 0, -1, 9, HINTING_THRESHOLD_LOW, nullptr }, - { "arial.ttf", "Arial", 12, 0, -1, 12, HINTING_THRESHOLD_LOW, nullptr }, - { "arial.ttf", "Arial", 12, 0, -1, 12, HINTING_THRESHOLD_LOW, nullptr }, } }; TTFFontSetDescriptor TTFFontArialUnicode = { { + { "arialuni.ttf", "Arial Unicode MS", 12, 0, -1, 12, HINTING_THRESHOLD_LOW, nullptr }, + { "arialuni.ttf", "Arial Unicode MS", 12, 0, -1, 12, HINTING_THRESHOLD_LOW, nullptr }, { "arialuni.ttf", "Arial Unicode MS", 10, 0, -1, 9, HINTING_THRESHOLD_LOW, nullptr }, - { "arialuni.ttf", "Arial Unicode MS", 12, 0, -1, 12, HINTING_THRESHOLD_LOW, nullptr }, - { "arialuni.ttf", "Arial Unicode MS", 12, 0, -1, 12, HINTING_THRESHOLD_LOW, nullptr }, } }; TTFFontSetDescriptor TTFFontMicroHei = { { - { "wqy-microhei.ttc", "WenQuanYi Micro Hei", 10, -1, -1, 10, HINTING_THRESHOLD_MEDIUM, nullptr }, { "wqy-microhei.ttc", "WenQuanYi Micro Hei", 11, 1, -1, 14, HINTING_THRESHOLD_MEDIUM, nullptr }, { "wqy-microhei.ttc", "WenQuanYi Micro Hei", 11, 1, -2, 14, HINTING_THRESHOLD_MEDIUM, nullptr }, + { "wqy-microhei.ttc", "WenQuanYi Micro Hei", 10, -1, -1, 10, HINTING_THRESHOLD_MEDIUM, nullptr }, } }; // clang-format on #endif // NO_TTF @@ -168,7 +169,7 @@ void TryLoadFonts(LocalisationService& localisationService) return; } - TTFFontDescriptor smallFont = font->size[FONT_SIZE_SMALL]; + TTFFontDescriptor smallFont = font->size[EnumValue(FontStyle::Small)]; log_verbose("Unable to load TrueType font '%s' -- trying the next font in the family.", smallFont.font_name); } @@ -183,7 +184,7 @@ void TryLoadFonts(LocalisationService& localisationService) return; } - TTFFontDescriptor smallFont = font->size[FONT_SIZE_SMALL]; + TTFFontDescriptor smallFont = font->size[EnumValue(FontStyle::Small)]; log_verbose("Unable to load TrueType font '%s' -- trying the next font in the family.", smallFont.font_name); } diff --git a/src/openrct2/localisation/Formatting.cpp b/src/openrct2/localisation/Formatting.cpp index 27d0ef6bb5..2e476bd06a 100644 --- a/src/openrct2/localisation/Formatting.cpp +++ b/src/openrct2/localisation/Formatting.cpp @@ -402,7 +402,7 @@ namespace OpenRCT2 // Currency symbol auto symbol = currencyDesc->symbol_unicode; auto affix = currencyDesc->affix_unicode; - if (!font_supports_string(symbol, FONT_SIZE_MEDIUM)) + if (!font_supports_string(symbol, FontStyle::Medium)) { symbol = currencyDesc->symbol_ascii; affix = currencyDesc->affix_ascii; diff --git a/src/openrct2/paint/Paint.cpp b/src/openrct2/paint/Paint.cpp index 6e3f557c2c..fb4c237ced 100644 --- a/src/openrct2/paint/Paint.cpp +++ b/src/openrct2/paint/Paint.cpp @@ -926,7 +926,7 @@ void PaintDrawMoneyStructs(rct_drawpixelinfo* dpi, PaintStringStruct* ps) gfx_draw_string_with_y_offsets( dpi, buffer, COLOUR_BLACK, { ps->x, ps->y }, reinterpret_cast(ps->y_offsets), forceSpriteFont, - FontSpriteBase::MEDIUM); + FontStyle::Medium); } while ((ps = ps->next) != nullptr); } diff --git a/src/openrct2/paint/Painter.cpp b/src/openrct2/paint/Painter.cpp index a1f55223c5..763f456113 100644 --- a/src/openrct2/paint/Painter.cpp +++ b/src/openrct2/paint/Painter.cpp @@ -90,7 +90,7 @@ void Painter::PaintReplayNotice(rct_drawpixelinfo* dpi, const char* text) char buffer[64]{}; FormatStringToBuffer(buffer, sizeof(buffer), "{OUTLINE}{RED}{STRING}", text); - auto stringWidth = gfx_get_string_width(buffer, FontSpriteBase::MEDIUM); + auto stringWidth = gfx_get_string_width(buffer, FontStyle::Medium); screenCoords.x = screenCoords.x - stringWidth; if (((gCurrentTicks >> 1) & 0xF) > 4) @@ -110,7 +110,7 @@ void Painter::PaintFPS(rct_drawpixelinfo* dpi) FormatStringToBuffer(buffer, sizeof(buffer), "{OUTLINE}{WHITE}{INT32}", _currentFPS); // Draw Text - int32_t stringWidth = gfx_get_string_width(buffer, FontSpriteBase::MEDIUM); + int32_t stringWidth = gfx_get_string_width(buffer, FontStyle::Medium); screenCoords.x = screenCoords.x - (stringWidth / 2); gfx_draw_string(dpi, screenCoords, buffer); diff --git a/src/openrct2/paint/tile_element/Paint.Banner.cpp b/src/openrct2/paint/tile_element/Paint.Banner.cpp index 4b27c37bd0..3b84c7a0a2 100644 --- a/src/openrct2/paint/tile_element/Paint.Banner.cpp +++ b/src/openrct2/paint/tile_element/Paint.Banner.cpp @@ -61,7 +61,7 @@ static void PaintBannerScrollingText( format_string(text, sizeof(text), STR_BANNER_TEXT_FORMAT, ft.Data()); } - auto stringWidth = gfx_get_string_width(text, FontSpriteBase::TINY); + auto stringWidth = gfx_get_string_width(text, FontStyle::Tiny); auto scroll = (gCurrentTicks / 2) % stringWidth; auto imageId = scrolling_text_setup(session, STR_BANNER_TEXT_FORMAT, ft, scroll, scrollingMode, COLOUR_BLACK); PaintAddImageAsChild(session, imageId, { 0, 0, height + 22 }, { 1, 1, 21 }, bbOffset); diff --git a/src/openrct2/paint/tile_element/Paint.Entrance.cpp b/src/openrct2/paint/tile_element/Paint.Entrance.cpp index 2489769914..de66bc0d88 100644 --- a/src/openrct2/paint/tile_element/Paint.Entrance.cpp +++ b/src/openrct2/paint/tile_element/Paint.Entrance.cpp @@ -69,7 +69,7 @@ static void PaintRideEntranceExitScrollingText( { format_string(text, sizeof(text), STR_BANNER_TEXT_FORMAT, ft.Data()); } - auto stringWidth = gfx_get_string_width(text, FontSpriteBase::TINY); + auto stringWidth = gfx_get_string_width(text, FontStyle::Tiny); auto scroll = stringWidth > 0 ? (gCurrentTicks / 2) % stringWidth : 0; PaintAddImageAsChild( @@ -241,7 +241,7 @@ static void PaintParkEntranceScrollingText( format_string(text, sizeof(text), STR_BANNER_TEXT_FORMAT, ft.Data()); } - auto stringWidth = gfx_get_string_width(text, FontSpriteBase::TINY); + auto stringWidth = gfx_get_string_width(text, FontStyle::Tiny); auto scroll = stringWidth > 0 ? (gCurrentTicks / 2) % stringWidth : 0; auto imageIndex = scrolling_text_setup( session, STR_BANNER_TEXT_FORMAT, ft, scroll, scrollingMode + direction / 2, COLOUR_BLACK); diff --git a/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp b/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp index 1cfb7ddedc..db23a1f800 100644 --- a/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp +++ b/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp @@ -321,7 +321,7 @@ static void PaintLargeSceneryScrollingText( } auto scrollMode = sceneryEntry.scrolling_mode + ((direction + 1) & 3); - auto stringWidth = gfx_get_string_width(text, FontSpriteBase::TINY); + auto stringWidth = gfx_get_string_width(text, FontStyle::Tiny); auto scroll = stringWidth > 0 ? (gCurrentTicks / 2) % stringWidth : 0; auto imageId = scrolling_text_setup(session, STR_SCROLLING_SIGN_TEXT, ft, scroll, scrollMode, textPaletteIndex); PaintAddImageAsChild(session, imageId, { 0, 0, height + 25 }, { 1, 1, 21 }, bbOffset); diff --git a/src/openrct2/paint/tile_element/Paint.Path.cpp b/src/openrct2/paint/tile_element/Paint.Path.cpp index fb3113b336..1dfc12d048 100644 --- a/src/openrct2/paint/tile_element/Paint.Path.cpp +++ b/src/openrct2/paint/tile_element/Paint.Path.cpp @@ -465,7 +465,7 @@ static void sub_6A4101( format_string(gCommonStringFormatBuffer, sizeof(gCommonStringFormatBuffer), STR_BANNER_TEXT_FORMAT, ft.Data()); } - uint16_t stringWidth = gfx_get_string_width(gCommonStringFormatBuffer, FontSpriteBase::TINY); + uint16_t stringWidth = gfx_get_string_width(gCommonStringFormatBuffer, FontStyle::Tiny); uint16_t scroll = stringWidth > 0 ? (gCurrentTicks / 2) % stringWidth : 0; PaintAddImageAsChild( diff --git a/src/openrct2/paint/tile_element/Paint.Wall.cpp b/src/openrct2/paint/tile_element/Paint.Wall.cpp index 23383b2abe..ccd17fd1e1 100644 --- a/src/openrct2/paint/tile_element/Paint.Wall.cpp +++ b/src/openrct2/paint/tile_element/Paint.Wall.cpp @@ -181,7 +181,7 @@ static void PaintWallScrollingText( format_string(signString, sizeof(signString), STR_SCROLLING_SIGN_TEXT, ft.Data()); } - auto stringWidth = gfx_get_string_width(signString, FontSpriteBase::TINY); + auto stringWidth = gfx_get_string_width(signString, FontStyle::Tiny); auto scroll = stringWidth > 0 ? (gCurrentTicks / 2) % stringWidth : 0; auto imageId = scrolling_text_setup(session, STR_SCROLLING_SIGN_TEXT, ft, scroll, scrollingMode, textPaletteIndex); PaintAddImageAsChild(session, imageId, { 0, 0, height + 8 }, { 1, 1, 13 }, boundsOffset); diff --git a/src/openrct2/title/TitleScreen.cpp b/src/openrct2/title/TitleScreen.cpp index 0fa285eb0b..1ca091e7ea 100644 --- a/src/openrct2/title/TitleScreen.cpp +++ b/src/openrct2/title/TitleScreen.cpp @@ -447,7 +447,7 @@ void DrawOpenRCT2(rct_drawpixelinfo* dpi, const ScreenCoordsXY& screenCoords) gfx_draw_string(dpi, screenCoords + ScreenCoordsXY(5, 5 - 13), buffer.c_str(), { COLOUR_BLACK }); // Invalidate screen area - int16_t width = static_cast(gfx_get_string_width(buffer, FontSpriteBase::MEDIUM)); + int16_t width = static_cast(gfx_get_string_width(buffer, FontStyle::Medium)); gfx_set_dirty_blocks( { screenCoords, screenCoords + ScreenCoordsXY{ width, 30 } }); // 30 is an arbitrary height to catch both strings