1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-20 13:33:02 +01:00

Port remaining DrawTextWrapped calls with void args to Formatter

This commit is contained in:
Michael Steenbeek
2021-08-21 09:42:05 +02:00
committed by GitHub
parent d8997cd60f
commit f5935931e3
8 changed files with 40 additions and 31 deletions

View File

@@ -415,16 +415,18 @@ static void window_multiplayer_information_paint(rct_window* w, rct_drawpixelinf
const utf8* name = network_get_server_name();
{
screenCoords.y += DrawTextWrapped(
dpi, screenCoords, width, STR_STRING, static_cast<void*>(&name), { w->colours[1] });
auto ft = Formatter();
ft.Add<const char*>(name);
screenCoords.y += DrawTextWrapped(dpi, screenCoords, width, STR_STRING, ft, { w->colours[1] });
screenCoords.y += LIST_ROW_HEIGHT / 2;
}
const utf8* description = network_get_server_description();
if (!str_is_null_or_empty(description))
{
screenCoords.y += DrawTextWrapped(
dpi, screenCoords, width, STR_STRING, static_cast<void*>(&description), { w->colours[1] });
auto ft = Formatter();
ft.Add<const char*>(description);
screenCoords.y += DrawTextWrapped(dpi, screenCoords, width, STR_STRING, ft, { w->colours[1] });
screenCoords.y += LIST_ROW_HEIGHT / 2;
}

View File

@@ -288,7 +288,6 @@ void window_research_development_page_paint(rct_window* w, rct_drawpixelinfo* dp
auto screenCoords = w->windowPos
+ ScreenCoordsXY{ 10, w->widgets[WIDX_CURRENTLY_IN_DEVELOPMENT_GROUP + baseWidgetIndex].top + 12 };
rct_string_id stringId;
if (gResearchProgressStage == RESEARCH_STAGE_FINISHED_ALL)
{
@@ -341,16 +340,20 @@ void window_research_development_page_paint(rct_window* w, rct_drawpixelinfo* dp
}
}
}
DrawTextWrapped(dpi, screenCoords, 296, label, &strings);
auto ft = Formatter();
ft.Add<rct_string_id>(strings[0]);
ft.Add<rct_string_id>(strings[1]);
DrawTextWrapped(dpi, screenCoords, 296, label, ft);
screenCoords.y += 25;
// Progress
stringId = ResearchStageNames[gResearchProgressStage];
DrawTextWrapped(dpi, screenCoords, 296, STR_RESEARCH_PROGRESS_LABEL, &stringId);
ft = Formatter();
ft.Add<rct_string_id>(ResearchStageNames[gResearchProgressStage]);
DrawTextWrapped(dpi, screenCoords, 296, STR_RESEARCH_PROGRESS_LABEL, ft);
screenCoords.y += 15;
// Expected
auto ft = Formatter();
ft = Formatter();
if (gResearchProgressStage != RESEARCH_STAGE_INITIAL_RESEARCH && gResearchExpectedDay != 255)
{
// TODO: Should probably use game date format setting
@@ -395,7 +398,10 @@ void window_research_development_page_paint(rct_window* w, rct_drawpixelinfo* dp
}
}
DrawTextWrapped(dpi, screenCoords, 266, lastDevelopmentFormat, &strings);
auto ft = Formatter();
ft.Add<rct_string_id>(strings[0]);
ft.Add<rct_string_id>(strings[1]);
DrawTextWrapped(dpi, screenCoords, 266, lastDevelopmentFormat, ft);
}
}

View File

@@ -2931,12 +2931,13 @@ static void window_ride_vehicle_paint(rct_window* w, rct_drawpixelinfo* dpi)
auto screenCoords = w->windowPos + ScreenCoordsXY{ 8, 64 };
// Description
screenCoords.y += DrawTextWrapped(
dpi, screenCoords, 300, STR_BLACK_STRING, &rideEntry->naming.Description, { TextAlignment::LEFT });
auto ft = Formatter();
ft.Add<rct_string_id>(rideEntry->naming.Description);
screenCoords.y += DrawTextWrapped(dpi, screenCoords, 300, STR_BLACK_STRING, ft, { TextAlignment::LEFT });
screenCoords.y += 2;
// Capacity
auto ft = Formatter();
ft = Formatter();
ft.Add<rct_string_id>(rideEntry->capacity);
DrawTextBasic(dpi, screenCoords, STR_CAPACITY, ft);
@@ -6941,7 +6942,9 @@ static void window_ride_customer_paint(rct_window* w, rct_drawpixelinfo* dpi)
{
queueTime = ride->GetMaxQueueTime();
stringId = queueTime == 1 ? STR_QUEUE_TIME_MINUTE : STR_QUEUE_TIME_MINUTES;
screenCoords.y += DrawTextWrapped(dpi, screenCoords, 308, stringId, &queueTime, { TextAlignment::LEFT });
ft = Formatter();
ft.Add<int32_t>(queueTime);
screenCoords.y += DrawTextWrapped(dpi, screenCoords, 308, stringId, ft, { TextAlignment::LEFT });
screenCoords.y += 5;
}

View File

@@ -202,14 +202,17 @@ public:
if (_descriptionStringId == STR_NONE)
{
auto* text = _description.c_str();
auto ft = Formatter();
ft.Add<const char*>(_description.c_str());
DrawTextWrapped(
&dpi, { windowPos.x + WW / 2, screenCoords.y }, WW, STR_STRING, &text, { colours[1], TextAlignment::CENTRE });
&dpi, { windowPos.x + WW / 2, screenCoords.y }, WW, STR_STRING, ft, { colours[1], TextAlignment::CENTRE });
}
else
{
auto ft = Formatter();
ft.Add<const char*>(TextInputDescriptionArgs);
DrawTextWrapped(
&dpi, { windowPos.x + WW / 2, screenCoords.y }, WW, _descriptionStringId, &TextInputDescriptionArgs,
&dpi, { windowPos.x + WW / 2, screenCoords.y }, WW, _descriptionStringId, ft,
{ colours[1], TextAlignment::CENTRE });
}

View File

@@ -247,9 +247,11 @@ static void window_track_delete_prompt_paint(rct_window* w, rct_drawpixelinfo* d
{
WindowDrawWidgets(w, dpi);
auto ft = Formatter();
ft.Add<const char*>(_trackDesignFileReference->name);
DrawTextWrapped(
dpi, { w->windowPos.x + (WW_DELETE_PROMPT / 2), w->windowPos.y + ((WH_DELETE_PROMPT / 2) - 9) }, (WW_DELETE_PROMPT - 4),
STR_ARE_YOU_SURE_YOU_WANT_TO_PERMANENTLY_DELETE_TRACK, &_trackDesignFileReference->name, { TextAlignment::CENTRE });
STR_ARE_YOU_SURE_YOU_WANT_TO_PERMANENTLY_DELETE_TRACK, ft, { TextAlignment::CENTRE });
}
static void window_track_design_list_reload_tracks()

View File

@@ -141,9 +141,11 @@ void gfx_draw_string_no_formatting(
}
int32_t DrawTextWrapped(
rct_drawpixelinfo* dpi, const ScreenCoordsXY& coords, int32_t width, rct_string_id format, const void* args,
rct_drawpixelinfo* dpi, const ScreenCoordsXY& coords, int32_t width, rct_string_id format, const Formatter& ft,
TextPaint textPaint)
{
const void* args = ft.Data();
utf8 buffer[512];
format_string(buffer, sizeof(buffer), format, args);
@@ -165,10 +167,3 @@ int32_t DrawTextWrapped(
return layout.GetHeight();
}
int32_t DrawTextWrapped(
rct_drawpixelinfo* dpi, const ScreenCoordsXY& coords, int32_t width, rct_string_id format, const Formatter& ft,
TextPaint textPaint)
{
return DrawTextWrapped(dpi, coords, width, format, ft.Data(), textPaint);
}

View File

@@ -153,6 +153,3 @@ void DrawTextEllipsised(
int32_t DrawTextWrapped(
rct_drawpixelinfo* dpi, const ScreenCoordsXY& coords, int32_t width, rct_string_id format, const Formatter& ft = {},
TextPaint textPaint = {});
int32_t DrawTextWrapped(
rct_drawpixelinfo* dpi, const ScreenCoordsXY& coords, int32_t width, rct_string_id format, const void* args,
TextPaint textPaint = {});

View File

@@ -189,9 +189,10 @@ void chat_draw(rct_drawpixelinfo* dpi, uint8_t chatBackgroundColor)
screenCoords.y = _chatBottom - inputLineHeight - 5;
auto lineCh = lineBuffer.c_str();
auto ft = Formatter();
ft.Add<const char*>(lineCh);
inputLineHeight = DrawTextWrapped(
dpi, screenCoords + ScreenCoordsXY{ 0, 3 }, _chatWidth - 10, STR_STRING, static_cast<void*>(&lineCh),
{ TEXT_COLOUR_255 });
dpi, screenCoords + ScreenCoordsXY{ 0, 3 }, _chatWidth - 10, STR_STRING, ft, { TEXT_COLOUR_255 });
gfx_set_dirty_blocks({ screenCoords, { screenCoords + ScreenCoordsXY{ _chatWidth, inputLineHeight + 15 } } });
// TODO: Show caret if the input text has multiple lines