Merge pull request #18311 from Gymnasiast/refactor/dark-text

Refactor FontSpriteBase and font size into FontStyle
This commit is contained in:
Michael Steenbeek authored and GitHub committed 2022-10-19 12:37:03 +02:00
commit c07795a390
53 files changed
+319 -335

No files matched your search

+2 -2
View File
@@ -30,7 +30,7 @@ namespace Graph
ft.Add<uint32_t>(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<StringId>(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);
+6 -6
View File
@@ -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)
+7 -7
View File
@@ -490,7 +490,7 @@ static void WidgetGroupboxDraw(rct_drawpixelinfo* dpi, rct_window& w, WidgetInde
auto ft = Formatter();
ft.Add<utf8*>(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<uint32_t>(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)
+1 -1
View File
@@ -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;
@@ -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<ScreenSize>(_ctx, { width, height });
}
+2 -2
View File
@@ -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 });
+3 -3
View File
@@ -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<int32_t>(_changelogLines.size()) * font_get_line_height(FontSpriteBase::MEDIUM));
static_cast<int32_t>(_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);
}
}
+1 -1
View File
@@ -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<int16_t>(strWidth, newWidth);
}
+1 -1
View File
@@ -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<void*>(&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);
}
@@ -294,14 +294,15 @@ 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())
{
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<StringId>(rideTypeName);
DrawTextEllipsised(
&dpi, { 1, itemY }, columnSplitOffset - 11, STR_INVENTIONS_LIST_RIDE_AND_VEHICLE_NAME, ft,
{ colour, fontSpriteBase });
{ colour, fontStyle, darkness });
// Draw vehicle name
ft = Formatter();
ft.Add<StringId>(itemNameId);
DrawTextEllipsised(
&dpi, { columnSplitOffset + 1, itemY }, columnSplitOffset - 11, STR_BLACK_STRING, ft,
{ colour, fontSpriteBase });
{ colour, fontStyle, darkness });
}
else
{
// Scenery group, flat ride or shop
auto ft = Formatter();
ft.Add<StringId>(itemNameId);
DrawTextEllipsised(&dpi, { 1, itemY }, boxWidth, STR_BLACK_STRING, ft, { colour, fontSpriteBase });
DrawTextEllipsised(&dpi, { 1, itemY }, boxWidth, STR_BLACK_STRING, ft, { colour, fontStyle, darkness });
}
}
}
@@ -664,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();
@@ -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<const char*>(CheckBoxMarkString),
{ static_cast<colour_t>(colour2), fontSpriteBase });
{ static_cast<colour_t>(colour2), FontStyle::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<const char*>(gCommonStringFormatBuffer);
DrawTextEllipsised(&dpi, screenCoords, width_limit - 15, STR_STRING, ft, { colour, fontSpriteBase });
DrawTextEllipsised(
&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,7 +770,7 @@ public:
}
auto ft = Formatter();
ft.Add<const char*>(gCommonStringFormatBuffer);
DrawTextEllipsised(&dpi, screenCoords, width_limit, STR_STRING, ft, { colour, fontSpriteBase });
DrawTextEllipsised(&dpi, screenCoords, width_limit, STR_STRING, ft, { colour, FontStyle::Medium, darkness });
}
screenCoords.y += SCROLLABLE_ROW_HEIGHT;
}
@@ -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<const char*>(CheckBoxMarkString),
{ static_cast<colour_t>(w->colours[1] & 0x7F), fontSpriteBase });
{ static_cast<colour_t>(w->colours[1] & 0x7F), FontStyle::Medium, darkness });
}
// Ride name
+4 -4
View File
@@ -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);
}
+3 -3
View File
@@ -632,7 +632,7 @@ public:
ft.Add<money64>(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<money64>(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<money64>(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);
@@ -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);
+3 -3
View File
@@ -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)
+2 -2
View File
@@ -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
{
+4 -4
View File
@@ -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
+5 -5
View File
@@ -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 });
}
+2 -2
View File
@@ -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());
}
+1 -1
View File
@@ -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;
}
+4 -4
View File
@@ -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<StringId>(DateDayNames[newsItem.Day - 1]);
ft.Add<StringId>(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<const char*>(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()))
+1 -1
View File
@@ -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<int32_t>(padding) };
+2 -2
View File
@@ -713,7 +713,7 @@ private:
ft.Add<uint32_t>(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<uint32_t>(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);
+3 -3
View File
@@ -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<int16_t>(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<int32_t>(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;
}
+11 -10
View File
@@ -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)
@@ -613,10 +613,11 @@ static void WindowScenarioselectScrollpaint(rct_window* w, rct_drawpixelinfo* dp
ft.Add<StringId>(STR_STRING);
ft.Add<char*>(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, FontStyle::Medium, TextAlignment::CENTRE, darkness });
// Check if scenario is completed
if (isCompleted)
@@ -639,7 +640,7 @@ static void WindowScenarioselectScrollpaint(rct_window* w, rct_drawpixelinfo* dp
ft.Add<char*>(buffer);
DrawTextBasic(
dpi, { scrollCentre, y + scenarioTitleHeight + 1 }, format, ft,
{ FontSpriteBase::SMALL, TextAlignment::CENTRE });
{ FontStyle::Small, TextAlignment::CENTRE });
}
y += scenarioItemHeight;
@@ -663,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;
+1 -1
View File
@@ -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;
+6 -6
View File
@@ -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;
+1 -1
View File
@@ -823,7 +823,7 @@ public:
{
gfx_draw_string(
&dpi, topLeft, static_cast<const char*>(CheckBoxMarkString),
{ static_cast<colour_t>(colours[1] & 0x7F), FontSpriteBase::MEDIUM_DARK });
{ static_cast<colour_t>(colours[1] & 0x7F), FontStyle::Medium, TextDarkness::Dark });
}
}
}
+1 -1
View File
@@ -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);
+4 -4
View File
@@ -58,11 +58,11 @@ static int32_t FormatTextForTooltip(const OpenRCT2String& message)
formattedMessage.args.Add<const char*>(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);
}
+1 -1
View File
@@ -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<utf8*>(pathPtr);
DrawTextBasic(
+65 -66
View File
@@ -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<size_t>::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<char*>(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;
@@ -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,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)
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;
@@ -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);
@@ -1011,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;
@@ -1045,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;
@@ -1071,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<char*>(path), fontSpriteBase) <= availableWidth)
if (gfx_get_string_width(const_cast<char*>(path), fontStyle) <= availableWidth)
{
safe_strcpy(buffer, path, bufferSize);
return;
@@ -1105,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;
}
+10 -10
View File
@@ -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);
FontStyle fontStyle, TextDarkness darkness);
// scrolling text
void scrolling_text_initialise_bitmaps();
+25 -57
View File
@@ -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 <limits>
#include <unordered_map>
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<uint8_t>(width);
_spriteFontCharacterWidths[EnumValue(fontStyle)][glyphIndex] = static_cast<uint8_t>(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<uint8_t>(width);
_additionalSpriteFontCharacterWidth[EnumValue(fontStyle)][glyphIndex] = static_cast<uint8_t>(width);
}
}
@@ -296,15 +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)
{
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);
auto baseFontIndex = EnumValue(fontStyle);
if (glyphIndex >= FONT_SPRITE_GLYPH_COUNT)
{
glyphIndex = (SPR_CHAR_START + glyphIndex) - SPR_G2_CHAR_BEGIN;
@@ -325,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<int32_t>(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())
{
@@ -377,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)
@@ -409,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;
@@ -434,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);
+15 -23
View File
@@ -13,25 +13,19 @@
#include "../core/String.hpp"
#include "../drawing/ImageId.hpp"
#include <array>
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
{
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,
};
constexpr const uint8_t FontStyleCount = 3;
constexpr const std::array<FontStyle, FontStyleCount> FontStyles = { FontStyle::Small, FontStyle::Medium, FontStyle::Tiny };
#ifndef NO_TTF
@@ -51,7 +45,7 @@ struct TTFFontDescriptor
struct TTFFontSetDescriptor
{
TTFFontDescriptor size[FONT_SIZE_COUNT];
TTFFontDescriptor size[FontStyleCount];
};
extern TTFFontSetDescriptor* gCurrentTTFFontSet;
@@ -60,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);
+6 -4
View File
@@ -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<uint32_t>(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);
+5 -5
View File
@@ -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<std::mutex> 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)
+1 -1
View File
@@ -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);
+6 -6
View File
@@ -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);
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);
}
+38 -17
View File
@@ -30,20 +30,28 @@ enum class TextUnderline
On,
};
enum class TextDarkness
{
Regular = 0,
Dark = 1,
ExtraDark = 2,
};
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;
TextPaint() = default;
TextPaint(colour_t colour)
: Colour(colour)
{
}
TextPaint(FontSpriteBase spriteBase)
: SpriteBase(spriteBase)
TextPaint(::FontStyle fontStyle)
: FontStyle(fontStyle)
{
}
TextPaint(TextUnderline underlineText)
@@ -55,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)
@@ -71,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)
{
}
@@ -87,38 +95,51 @@ 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, ::FontStyle fontStyle, TextDarkness darkness)
: Colour(colour)
, FontStyle(fontStyle)
, Darkness(darkness)
{
}
TextPaint(colour_t colour, TextUnderline underlineText, TextAlignment alignment)
: Colour(colour)
, UnderlineText(underlineText)
, 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, ::FontStyle fontStyle, TextAlignment alignment, TextDarkness darkness)
: Colour(colour)
, FontStyle(fontStyle)
, Alignment(alignment)
, Darkness(darkness)
{
}
};
void DrawTextBasic(rct_drawpixelinfo* dpi, const ScreenCoordsXY& coords, StringId format);
+1 -1
View File
@@ -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;
+6 -6
View File
@@ -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)
+24 -23
View File
@@ -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);
}
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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<int8_t*>(ps->y_offsets), forceSpriteFont,
FontSpriteBase::MEDIUM);
FontStyle::Medium);
} while ((ps = ps->next) != nullptr);
}
+2 -2
View File
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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(
@@ -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);
+1 -1
View File
@@ -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<int16_t>(gfx_get_string_width(buffer, FontSpriteBase::MEDIUM));
int16_t width = static_cast<int16_t>(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