Change gfx_draw_string_*_wrapped() to DrawTextWrapped()

This commit is contained in:
Gymnasiast 2021-02-27 17:17:17 +01:00
parent e2ebc9d43b
commit 3e536e2711
No known key found for this signature in database
GPG Key ID: DBFFF47AB2CA3EDD
25 changed files with 97 additions and 102 deletions

View File

@ -358,7 +358,7 @@ static void WidgetTextCentred(rct_drawpixelinfo* dpi, rct_window* w, rct_widgeti
ScreenCoordsXY coords = { (topLeft.x + r + 1) / 2 - 1, topLeft.y };
if (widget->type == WindowWidgetType::LabelCentred)
{
gfx_draw_string_centred_wrapped(dpi, ft.Data(), coords, widget->width() - 2, stringId, colour);
DrawTextWrapped(dpi, coords, widget->width() - 2, stringId, ft, { colour, TextAlignment::CENTRE });
}
else
{
@ -407,7 +407,7 @@ static void WidgetText(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex wi
ScreenCoordsXY coords = { l + 1, t };
if (widget->type == WindowWidgetType::LabelCentred)
{
gfx_draw_string_centred_wrapped(dpi, ft.Data(), coords, r - l, stringId, colour);
DrawTextWrapped(dpi, coords, r - l, stringId, ft, { colour, TextAlignment::CENTRE });
}
else
{

View File

@ -174,13 +174,14 @@ static void window_about_openrct2_common_paint(rct_window* w, rct_drawpixelinfo*
{
auto ft = Formatter();
ft.Add<rct_string_id>(STR_TITLE_SEQUENCE_OPENRCT2);
gfx_draw_string_centred_wrapped(
dpi, ft.Data(), aboutOpenRCT2Coords, 87, STR_WINDOW_COLOUR_2_STRINGID, COLOUR_AQUAMARINE);
DrawTextWrapped(
dpi, aboutOpenRCT2Coords, 87, STR_WINDOW_COLOUR_2_STRINGID, ft, { COLOUR_AQUAMARINE, TextAlignment::CENTRE });
}
{
auto ft = Formatter();
ft.Add<rct_string_id>(STR_TITLE_SEQUENCE_RCT2);
gfx_draw_string_centred_wrapped(dpi, ft.Data(), aboutRCT2Coords, 87, STR_WINDOW_COLOUR_2_STRINGID, COLOUR_AQUAMARINE);
DrawTextWrapped(
dpi, aboutRCT2Coords, 87, STR_WINDOW_COLOUR_2_STRINGID, ft, { COLOUR_AQUAMARINE, TextAlignment::CENTRE });
}
}
@ -194,8 +195,8 @@ static void window_about_openrct2_paint(rct_window* w, rct_drawpixelinfo* dpi)
w->windowPos.x + (w->width / 2), w->windowPos.y + w->widgets[WIDX_PAGE_BACKGROUND].top + lineHeight);
int32_t width = w->width - 20;
aboutCoords.y += gfx_draw_string_centred_wrapped(
dpi, nullptr, aboutCoords, width, STR_ABOUT_OPENRCT2_DESCRIPTION, w->colours[2])
aboutCoords.y += DrawTextWrapped(
dpi, aboutCoords, width, STR_ABOUT_OPENRCT2_DESCRIPTION, {}, { w->colours[2], TextAlignment::CENTRE })
+ lineHeight;
rct_size16 logoSize = gfx_get_sprite_size(SPR_G2_LOGO);
@ -203,24 +204,28 @@ static void window_about_openrct2_paint(rct_window* w, rct_drawpixelinfo* dpi)
aboutCoords.y += logoSize.height + lineHeight * 2;
// About OpenRCT2 text
aboutCoords.y += gfx_draw_string_centred_wrapped(
dpi, nullptr, aboutCoords, width, STR_ABOUT_OPENRCT2_DESCRIPTION_2, w->colours[2])
aboutCoords.y += DrawTextWrapped(
dpi, aboutCoords, width, STR_ABOUT_OPENRCT2_DESCRIPTION_2, {},
{ w->colours[2], TextAlignment::CENTRE })
+ lineHeight + 5;
// Copyright disclaimer; hidden when using truetype fonts to prevent
// the text from overlapping the changelog button.
if (!LocalisationService_UseTrueTypeFont())
{
gfx_draw_string_centred_wrapped(dpi, nullptr, aboutCoords, width, STR_ABOUT_OPENRCT2_DESCRIPTION_3, w->colours[2]);
DrawTextWrapped(
dpi, aboutCoords, width, STR_ABOUT_OPENRCT2_DESCRIPTION_3, {}, { w->colours[2], TextAlignment::CENTRE });
}
// Version info
utf8 buffer[256];
utf8* ch = buffer;
openrct2_write_full_version_info(ch, sizeof(buffer) - (ch - buffer));
auto ft = Formatter();
ft.Add<const char*>(buffer);
aboutCoords.y = w->windowPos.y + WH - 25;
gfx_draw_string_centred_wrapped(dpi, &ch, aboutCoords, width, STR_STRING, w->colours[2]);
DrawTextWrapped(dpi, aboutCoords, width, STR_STRING, ft, { w->colours[2], TextAlignment::CENTRE });
}
static void window_about_openrct2_invalidate(rct_window* w)

View File

@ -170,7 +170,7 @@ static void window_ride_demolish_paint(rct_window* w, rct_drawpixelinfo* dpi)
ft.Add<money32>(_demolishRideCost);
ScreenCoordsXY stringCoords(w->windowPos.x + WW / 2, w->windowPos.y + (WH / 2) - 3);
gfx_draw_string_centred_wrapped(dpi, ft.Data(), stringCoords, WW - 4, stringId, COLOUR_BLACK);
DrawTextWrapped(dpi, stringCoords, WW - 4, stringId, ft, { TextAlignment::CENTRE });
}
}
@ -187,6 +187,6 @@ static void window_ride_refurbish_paint(rct_window* w, rct_drawpixelinfo* dpi)
ft.Add<money32>(_demolishRideCost / 2);
ScreenCoordsXY stringCoords(w->windowPos.x + WW / 2, w->windowPos.y + (WH / 2) - 3);
gfx_draw_string_centred_wrapped(dpi, ft.Data(), stringCoords, WW - 4, stringId, COLOUR_BLACK);
DrawTextWrapped(dpi, stringCoords, WW - 4, stringId, ft, { TextAlignment::CENTRE });
}
}

View File

@ -1070,8 +1070,7 @@ static void window_editor_object_selection_paint(rct_window* w, rct_drawpixelinf
auto screenPos = w->windowPos + ScreenCoordsXY{ w->widgets[WIDX_LIST].right + 4, widget->bottom + 18 };
width = w->windowPos.x + w->width - screenPos.x - 4;
gfx_draw_string_left_wrapped(
dpi, ft.Data(), screenPos + ScreenCoordsXY{ 0, 5 }, width, STR_WINDOW_COLOUR_2_STRINGID, COLOUR_BLACK);
DrawTextWrapped(dpi, screenPos + ScreenCoordsXY{ 0, 5 }, width, STR_WINDOW_COLOUR_2_STRINGID, ft);
}
auto screenPos = w->windowPos + ScreenCoordsXY{ w->width - 5, w->height - (LIST_ROW_HEIGHT * 5) };

View File

@ -913,7 +913,7 @@ static void window_editor_objective_options_main_paint(rct_window* w, rct_drawpi
ft = Formatter();
ft.Add<rct_string_id>(STR_STRING);
ft.Add<const char*>(gS6Info.details);
gfx_draw_string_left_wrapped(dpi, ft.Data(), screenCoords, width, STR_BLACK_STRING, COLOUR_BLACK);
DrawTextWrapped(dpi, screenCoords, width, STR_BLACK_STRING, ft);
// Scenario category label
screenCoords = w->windowPos + ScreenCoordsXY{ 8, w->widgets[WIDX_CATEGORY].top };

View File

@ -675,12 +675,13 @@ static void window_game_bottom_toolbar_draw_middle_panel(rct_drawpixelinfo* dpi,
std::memcpy(&stringId, ft.Data(), sizeof(rct_string_id));
if (stringId == STR_NONE)
{
gfx_draw_string_centred_wrapped(dpi, ft.Data(), middleWidgetCoords, width, STR_TITLE_SEQUENCE_OPENRCT2, w->colours[0]);
DrawTextWrapped(
dpi, middleWidgetCoords, width, STR_TITLE_SEQUENCE_OPENRCT2, ft, { w->colours[0], TextAlignment::CENTRE });
}
else
{
// Show tooltip in bottom toolbar
gfx_draw_string_centred_wrapped(dpi, ft.Data(), middleWidgetCoords, width, STR_STRINGID, w->colours[0]);
DrawTextWrapped(dpi, middleWidgetCoords, width, STR_STRINGID, ft, { w->colours[0], TextAlignment::CENTRE });
}
}

View File

@ -1808,7 +1808,7 @@ void window_guest_thoughts_paint(rct_window* w, rct_drawpixelinfo* dpi)
auto ft = Formatter();
peep_thought_set_format_args(thought, ft);
screenCoords.y += gfx_draw_string_left_wrapped(dpi, ft.Data(), screenCoords, width, STR_BLACK_STRING, COLOUR_BLACK);
screenCoords.y += DrawTextWrapped(dpi, screenCoords, width, STR_BLACK_STRING, ft);
// If this is the last visible line end drawing.
if (screenCoords.y > w->windowPos.y + window_guest_thoughts_widgets[WIDX_PAGE_BACKGROUND].bottom - 32)
@ -1990,7 +1990,7 @@ void window_guest_inventory_paint(rct_window* w, rct_drawpixelinfo* dpi)
continue;
auto [stringId, ft] = window_guest_inventory_format_item(guest, item);
screenCoords.y += gfx_draw_string_left_wrapped(dpi, ft.Data(), screenCoords, itemNameWidth, stringId, COLOUR_BLACK);
screenCoords.y += DrawTextWrapped(dpi, screenCoords, itemNameWidth, stringId, ft);
numItems++;
}

View File

@ -1206,7 +1206,7 @@ static void window_overwrite_prompt_paint(rct_window* w, rct_drawpixelinfo* dpi)
ft.Add<char*>(_window_overwrite_prompt_name);
ScreenCoordsXY stringCoords(w->windowPos.x + w->width / 2, w->windowPos.y + (w->height / 2) - 3);
gfx_draw_string_centred_wrapped(dpi, ft.Data(), stringCoords, w->width - 4, STR_FILEBROWSER_OVERWRITE_PROMPT, COLOUR_BLACK);
DrawTextWrapped(dpi, stringCoords, w->width - 4, STR_FILEBROWSER_OVERWRITE_PROMPT, ft, { TextAlignment::CENTRE });
}
#pragma endregion

View File

@ -145,6 +145,5 @@ static void window_map_tooltip_paint(rct_window* w, rct_drawpixelinfo* dpi)
}
ScreenCoordsXY stringCoords(w->windowPos.x + (w->width / 2), w->windowPos.y + (w->height / 2));
gfx_draw_string_centred_wrapped(
dpi, _mapTooltipArgs.Data(), stringCoords, w->width, STR_MAP_TOOLTIP_STRINGID, COLOUR_BLACK);
DrawTextWrapped(dpi, stringCoords, w->width, STR_MAP_TOOLTIP_STRINGID, _mapTooltipArgs, { TextAlignment::CENTRE });
}

View File

@ -418,16 +418,16 @@ static void window_multiplayer_information_paint(rct_window* w, rct_drawpixelinf
const utf8* name = network_get_server_name();
{
screenCoords.y += gfx_draw_string_left_wrapped(
dpi, static_cast<void*>(&name), screenCoords, width, STR_STRING, w->colours[1]);
screenCoords.y += DrawTextWrapped(
dpi, screenCoords, width, STR_STRING, static_cast<void*>(&name), { 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 += gfx_draw_string_left_wrapped(
dpi, static_cast<void*>(&description), screenCoords, width, STR_STRING, w->colours[1]);
screenCoords.y += DrawTextWrapped(
dpi, screenCoords, width, STR_STRING, static_cast<void*>(&description), { w->colours[1] });
screenCoords.y += LIST_ROW_HEIGHT / 2;
}

View File

@ -901,7 +901,7 @@ static void window_new_ride_paint_ride_information(
auto ft = Formatter();
ft.Add<rct_string_id>(rideNaming.Name);
ft.Add<rct_string_id>(rideNaming.Description);
gfx_draw_string_left_wrapped(dpi, ft.Data(), screenPos, width, STR_NEW_RIDE_NAME_AND_DESCRIPTION, COLOUR_BLACK);
DrawTextWrapped(dpi, screenPos, width, STR_NEW_RIDE_NAME_AND_DESCRIPTION, ft);
char availabilityString[AVAILABILITY_STRING_SIZE];
window_new_ride_list_vehicles_for(item.Type, rideEntry, availabilityString, sizeof(availabilityString));

View File

@ -249,8 +249,7 @@ static void window_news_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, int32
{
auto ft = Formatter();
ft.Add<const char*>(newsItem.Text.c_str());
gfx_draw_string_left_wrapped(
dpi, ft.Data(), { 2, y + lineHeight }, 325, STR_BOTTOM_TOOLBAR_NEWS_TEXT, COLOUR_BRIGHT_GREEN);
DrawTextWrapped(dpi, { 2, y + lineHeight }, 325, STR_BOTTOM_TOOLBAR_NEWS_TEXT, ft);
}
// Subject button
if ((newsItem.TypeHasSubject()) && !(newsItem.HasButton()))

View File

@ -541,8 +541,7 @@ static void window_object_load_error_paint(rct_window* w, rct_drawpixelinfo* dpi
// Draw explanatory message
auto ft = Formatter();
ft.Add<rct_string_id>(STR_OBJECT_ERROR_WINDOW_EXPLANATION);
gfx_draw_string_left_wrapped(
dpi, ft.Data(), w->windowPos + ScreenCoordsXY{ 5, 18 }, WW - 10, STR_BLACK_STRING, COLOUR_BLACK);
DrawTextWrapped(dpi, w->windowPos + ScreenCoordsXY{ 5, 18 }, WW - 10, STR_BLACK_STRING, ft);
// Draw file name
ft = Formatter();

View File

@ -1459,7 +1459,7 @@ static void window_park_objective_paint(rct_window* w, rct_drawpixelinfo* dpi)
auto ft = Formatter();
ft.Add<rct_string_id>(STR_STRING);
ft.Add<const char*>(gScenarioDetails.c_str());
screenCoords.y += gfx_draw_string_left_wrapped(dpi, ft.Data(), screenCoords, 222, STR_BLACK_STRING, COLOUR_BLACK);
screenCoords.y += DrawTextWrapped(dpi, screenCoords, 222, STR_BLACK_STRING, ft);
screenCoords.y += 5;
// Your objective:
@ -1488,8 +1488,7 @@ static void window_park_objective_paint(rct_window* w, rct_drawpixelinfo* dpi)
ft.Add<money32>(gScenarioObjective.Currency);
}
screenCoords.y += gfx_draw_string_left_wrapped(
dpi, ft.Data(), screenCoords, 221, ObjectiveNames[gScenarioObjective.Type], COLOUR_BLACK);
screenCoords.y += DrawTextWrapped(dpi, screenCoords, 221, ObjectiveNames[gScenarioObjective.Type], ft);
screenCoords.y += 5;
// Objective outcome
@ -1498,14 +1497,14 @@ static void window_park_objective_paint(rct_window* w, rct_drawpixelinfo* dpi)
if (gScenarioCompletedCompanyValue == COMPANY_VALUE_ON_FAILED_OBJECTIVE)
{
// Objective failed
gfx_draw_string_left_wrapped(dpi, nullptr, screenCoords, 222, STR_OBJECTIVE_FAILED, COLOUR_BLACK);
DrawTextWrapped(dpi, screenCoords, 222, STR_OBJECTIVE_FAILED);
}
else
{
// Objective completed
ft = Formatter();
ft.Add<money32>(gScenarioCompletedCompanyValue);
gfx_draw_string_left_wrapped(dpi, ft.Data(), screenCoords, 222, STR_OBJECTIVE_ACHIEVED, COLOUR_BLACK);
DrawTextWrapped(dpi, screenCoords, 222, STR_OBJECTIVE_ACHIEVED, ft);
}
}
}
@ -1620,8 +1619,7 @@ static void window_park_awards_paint(rct_window* w, rct_drawpixelinfo* dpi)
continue;
gfx_draw_sprite(dpi, ParkAwards[award->Type].sprite, screenCoords, 0);
gfx_draw_string_left_wrapped(
dpi, nullptr, screenCoords + ScreenCoordsXY{ 34, 6 }, 180, ParkAwards[award->Type].text, COLOUR_BLACK);
DrawTextWrapped(dpi, screenCoords + ScreenCoordsXY{ 34, 6 }, 180, ParkAwards[award->Type].text);
screenCoords.y += 32;
count++;

View File

@ -295,14 +295,14 @@ void window_research_development_page_paint(rct_window* w, rct_drawpixelinfo* dp
{
auto ft = Formatter();
ft.Add<rct_string_id>(STR_RESEARCH_UNKNOWN);
gfx_draw_string_left_wrapped(dpi, ft.Data(), screenCoords, 296, STR_RESEARCH_TYPE_LABEL, COLOUR_BLACK);
DrawTextWrapped(dpi, screenCoords, 296, STR_RESEARCH_TYPE_LABEL, ft);
screenCoords.y += 25;
}
// Progress
{
auto ft = Formatter();
ft.Add<rct_string_id>(STR_RESEARCH_COMPLETED_AL);
gfx_draw_string_left_wrapped(dpi, ft.Data(), screenCoords, 296, STR_RESEARCH_PROGRESS_LABEL, COLOUR_BLACK);
DrawTextWrapped(dpi, screenCoords, 296, STR_RESEARCH_PROGRESS_LABEL, ft);
screenCoords.y += 15;
}
@ -341,12 +341,12 @@ void window_research_development_page_paint(rct_window* w, rct_drawpixelinfo* dp
}
}
}
gfx_draw_string_left_wrapped(dpi, &strings, screenCoords, 296, label, COLOUR_BLACK);
DrawTextWrapped(dpi, screenCoords, 296, label, &strings);
screenCoords.y += 25;
// Progress
stringId = ResearchStageNames[gResearchProgressStage];
gfx_draw_string_left_wrapped(dpi, &stringId, screenCoords, 296, STR_RESEARCH_PROGRESS_LABEL, COLOUR_BLACK);
DrawTextWrapped(dpi, screenCoords, 296, STR_RESEARCH_PROGRESS_LABEL, &stringId);
screenCoords.y += 15;
// Expected
@ -395,7 +395,7 @@ void window_research_development_page_paint(rct_window* w, rct_drawpixelinfo* dp
}
}
gfx_draw_string_left_wrapped(dpi, &strings, screenCoords, 266, lastDevelopmentFormat, COLOUR_BLACK);
DrawTextWrapped(dpi, screenCoords, 266, lastDevelopmentFormat, &strings);
}
}

View File

@ -2952,8 +2952,8 @@ static void window_ride_vehicle_paint(rct_window* w, rct_drawpixelinfo* dpi)
auto screenCoords = w->windowPos + ScreenCoordsXY{ 8, 64 };
// Description
screenCoords.y += gfx_draw_string_centred_wrapped(
dpi, &rideEntry->naming.Description, screenCoords, 300, STR_BLACK_STRING, COLOUR_BLACK);
screenCoords.y += DrawTextWrapped(
dpi, screenCoords, 300, STR_BLACK_STRING, &rideEntry->naming.Description, { TextAlignment::CENTRE });
screenCoords.y += 2;
// Capacity
@ -4155,8 +4155,7 @@ static void window_ride_maintenance_paint(rct_window* w, rct_drawpixelinfo* dpi)
{
if (stringId == STR_CALLING_MECHANIC || stringId == STR_NO_MECHANICS_ARE_HIRED_MESSAGE)
{
gfx_draw_string_centred_wrapped(
dpi, nullptr, screenCoords + ScreenCoordsXY{ 4, 0 }, 280, stringId, COLOUR_BLACK);
DrawTextWrapped(dpi, screenCoords + ScreenCoordsXY{ 4, 0 }, 280, stringId, {}, { TextAlignment::CENTRE });
}
else
{
@ -4165,8 +4164,7 @@ static void window_ride_maintenance_paint(rct_window* w, rct_drawpixelinfo* dpi)
{
auto ft = Formatter();
staff->FormatNameTo(ft);
gfx_draw_string_centred_wrapped(
dpi, ft.Data(), screenCoords + ScreenCoordsXY{ 4, 0 }, 280, stringId, COLOUR_BLACK);
DrawTextWrapped(dpi, screenCoords + ScreenCoordsXY{ 4, 0 }, 280, stringId, ft, { TextAlignment::CENTRE });
}
}
}
@ -5578,8 +5576,7 @@ static void window_ride_measurements_paint(rct_window* w, rct_drawpixelinfo* dpi
rct_widget* widget = &window_ride_measurements_widgets[WIDX_PAGE_BACKGROUND];
ScreenCoordsXY widgetCoords(w->windowPos.x + widget->width() / 2, w->windowPos.y + widget->top + 40);
gfx_draw_string_centred_wrapped(
dpi, nullptr, widgetCoords, w->width - 8, STR_CLICK_ITEMS_OF_SCENERY_TO_SELECT, COLOUR_BLACK);
DrawTextWrapped(dpi, widgetCoords, w->width - 8, STR_CLICK_ITEMS_OF_SCENERY_TO_SELECT, {}, { TextAlignment::CENTRE });
widgetCoords.x = w->windowPos.x + 4;
widgetCoords.y = w->windowPos.y + window_ride_measurements_widgets[WIDX_SELECT_NEARBY_SCENERY].bottom + 17;
@ -6073,7 +6070,7 @@ static void window_ride_graphs_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi
// No measurement message
ScreenCoordsXY stringCoords(widget->width() / 2, widget->height() / 2 - 5);
int32_t width = widget->width() - 2;
gfx_draw_string_centred_wrapped(dpi, message.args.Data(), stringCoords, width, message.str, COLOUR_BLACK);
DrawTextWrapped(dpi, stringCoords, width, message.str, message.args, { TextAlignment::CENTRE });
return;
}
@ -6924,7 +6921,7 @@ 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 += gfx_draw_string_centred_wrapped(dpi, &queueTime, screenCoords, 308, stringId, COLOUR_BLACK);
screenCoords.y += DrawTextWrapped(dpi, screenCoords, 308, stringId, &queueTime, { TextAlignment::CENTRE });
screenCoords.y += 5;
}

View File

@ -453,7 +453,7 @@ static void window_scenarioselect_paint(rct_window* w, rct_drawpixelinfo* dpi)
}
ScreenCoordsXY stringCoords(widget->midX() + w->windowPos.x, widget->midY() + w->windowPos.y - 3);
gfx_draw_string_centred_wrapped(dpi, ft.Data(), stringCoords, 87, format, COLOUR_AQUAMARINE);
DrawTextWrapped(dpi, stringCoords, 87, format, ft, { COLOUR_AQUAMARINE, TextAlignment::CENTRE });
}
// Return if no scenario highlighted
@ -468,8 +468,7 @@ static void window_scenarioselect_paint(rct_window* w, rct_drawpixelinfo* dpi)
window_scenarioselect_widgets[WIDX_TABCONTENT].top + 5 };
DrawTextEllipsised(
dpi, screenPos + ScreenCoordsXY{ 85, 0 }, 170, STR_SCENARIO_LOCKED, {}, COLOUR_BLACK, TextAlignment::CENTRE);
gfx_draw_string_left_wrapped(
dpi, nullptr, screenPos + ScreenCoordsXY{ 0, 15 }, 170, STR_SCENARIO_LOCKED_DESC, COLOUR_BLACK);
DrawTextWrapped(dpi, screenPos + ScreenCoordsXY{ 0, 15 }, 170, STR_SCENARIO_LOCKED_DESC);
}
return;
}
@ -503,7 +502,7 @@ static void window_scenarioselect_paint(rct_window* w, rct_drawpixelinfo* dpi)
ft = Formatter();
ft.Add<rct_string_id>(STR_STRING);
ft.Add<const char*>(scenario->details);
screenPos.y += gfx_draw_string_left_wrapped(dpi, ft.Data(), screenPos, 170, STR_BLACK_STRING, COLOUR_BLACK) + 5;
screenPos.y += DrawTextWrapped(dpi, screenPos, 170, STR_BLACK_STRING, ft) + 5;
// Scenario objective
ft = Formatter();
@ -527,7 +526,7 @@ static void window_scenarioselect_paint(rct_window* w, rct_drawpixelinfo* dpi)
else
ft.Add<money32>(scenario->objective_arg_2);
}
screenPos.y += gfx_draw_string_left_wrapped(dpi, ft.Data(), screenPos, 170, STR_OBJECTIVE, COLOUR_BLACK) + 5;
screenPos.y += DrawTextWrapped(dpi, screenPos, 170, STR_OBJECTIVE, ft) + 5;
// Scenario score
if (scenario->highscore != nullptr)
@ -542,8 +541,7 @@ static void window_scenarioselect_paint(rct_window* w, rct_drawpixelinfo* dpi)
ft.Add<rct_string_id>(STR_STRING);
ft.Add<const char*>(completedByName);
ft.Add<money32>(scenario->highscore->company_value);
screenPos.y += gfx_draw_string_left_wrapped(
dpi, ft.Data(), screenPos, 170, STR_COMPLETED_BY_WITH_COMPANY_VALUE, COLOUR_BLACK);
screenPos.y += DrawTextWrapped(dpi, screenPos, 170, STR_COMPLETED_BY_WITH_COMPANY_VALUE, ft);
}
}

View File

@ -134,7 +134,7 @@ public:
ft.Add<rct_string_id>(STR_STRING);
ft.Add<const char*>(_shortcutCustomName.c_str());
}
gfx_draw_string_centred_wrapped(&dpi, ft.Data(), stringCoords, 242, STR_SHORTCUT_CHANGE_PROMPT, COLOUR_BLACK);
DrawTextWrapped(&dpi, stringCoords, 242, STR_SHORTCUT_CHANGE_PROMPT, ft, { TextAlignment::CENTRE });
}
private:

View File

@ -104,5 +104,5 @@ static void window_staff_fire_paint(rct_window* w, rct_drawpixelinfo* dpi)
peep->FormatNameTo(ft);
ScreenCoordsXY stringCoords(w->windowPos.x + WW / 2, w->windowPos.y + (WH / 2) - 3);
gfx_draw_string_centred_wrapped(dpi, ft.Data(), stringCoords, WW - 4, STR_FIRE_STAFF_ID, COLOUR_BLACK);
DrawTextWrapped(dpi, stringCoords, WW - 4, STR_FIRE_STAFF_ID, ft, { TextAlignment::CENTRE });
}

View File

@ -204,13 +204,14 @@ public:
if (_descriptionStringId == STR_NONE)
{
auto* text = _description.c_str();
gfx_draw_string_centred_wrapped(&dpi, &text, { windowPos.x + WW / 2, screenCoords.y }, WW, STR_STRING, colours[1]);
DrawTextWrapped(
&dpi, { windowPos.x + WW / 2, screenCoords.y }, WW, STR_STRING, &text, { colours[1], TextAlignment::CENTRE });
}
else
{
gfx_draw_string_centred_wrapped(
&dpi, &TextInputDescriptionArgs, { windowPos.x + WW / 2, screenCoords.y }, WW, _descriptionStringId,
colours[1]);
DrawTextWrapped(
&dpi, { windowPos.x + WW / 2, screenCoords.y }, WW, _descriptionStringId, &TextInputDescriptionArgs,
{ colours[1], TextAlignment::CENTRE });
}
screenCoords.y += 25;

View File

@ -243,9 +243,9 @@ static void window_track_delete_prompt_paint(rct_window* w, rct_drawpixelinfo* d
{
WindowDrawWidgets(w, dpi);
gfx_draw_string_centred_wrapped(
dpi, &_trackDesignFileReference->name, { w->windowPos.x + 125, w->windowPos.y + 28 }, 246,
STR_ARE_YOU_SURE_YOU_WANT_TO_PERMANENTLY_DELETE_TRACK, COLOUR_BLACK);
DrawTextWrapped(
dpi, { w->windowPos.x + 125, w->windowPos.y + 28 }, 246, STR_ARE_YOU_SURE_YOU_WANT_TO_PERMANENTLY_DELETE_TRACK,
&_trackDesignFileReference->name, { TextAlignment::CENTRE });
}
static void window_track_design_list_reload_tracks()

View File

@ -739,11 +739,6 @@ void gfx_draw_string(rct_drawpixelinfo* dpi, const_utf8string buffer, uint8_t co
void gfx_draw_string_no_formatting(
rct_drawpixelinfo* dpi, const_utf8string buffer, uint8_t colour, const ScreenCoordsXY& coords);
int32_t gfx_draw_string_left_wrapped(
rct_drawpixelinfo* dpi, void* args, const ScreenCoordsXY& coords, int32_t width, rct_string_id format, uint8_t colour);
int32_t gfx_draw_string_centred_wrapped(
rct_drawpixelinfo* dpi, void* args, const ScreenCoordsXY& coords, int32_t width, rct_string_id format, uint8_t colour);
void gfx_draw_string_left_centred(
rct_drawpixelinfo* dpi, rct_string_id format, void* args, int32_t colour, const ScreenCoordsXY& coords);
void draw_string_centred_raw(rct_drawpixelinfo* dpi, const ScreenCoordsXY& coords, int32_t numLines, char* text);

View File

@ -156,39 +156,37 @@ void gfx_draw_string_no_formatting(
DrawText(dpi, coords, textPaint, buffer, true);
}
// Wrapping
int32_t gfx_draw_string_left_wrapped(
rct_drawpixelinfo* dpi, void* args, const ScreenCoordsXY& coords, int32_t width, rct_string_id format, uint8_t colour)
int32_t DrawTextWrapped(
rct_drawpixelinfo* dpi, const ScreenCoordsXY& coords, int32_t width, rct_string_id format, const void* args,
TextPaint textPaint)
{
utf8 buffer[512];
format_string(buffer, sizeof(buffer), format, args);
gCurrentFontSpriteBase = FontSpriteBase::MEDIUM;
gCurrentFontSpriteBase = textPaint.SpriteBase;
TextPaint textPaint = { colour, FontSpriteBase::MEDIUM, TextUnderline::Off, TextAlignment::LEFT };
StaticLayout layout(buffer, textPaint, width);
layout.Draw(dpi, coords);
if (textPaint.Alignment == TextAlignment::CENTRE)
{
// The original tried to vertically centre the text, but used line count - 1
int32_t lineCount = layout.GetLineCount();
int32_t lineHeight = layout.GetHeight() / lineCount;
int32_t yOffset = (lineCount - 1) * lineHeight / 2;
layout.Draw(dpi, coords - ScreenCoordsXY{ layout.GetWidth() / 2, yOffset });
}
else
{
layout.Draw(dpi, coords);
}
return layout.GetHeight();
}
int32_t gfx_draw_string_centred_wrapped(
rct_drawpixelinfo* dpi, void* args, const ScreenCoordsXY& coords, int32_t width, rct_string_id format, uint8_t colour)
int32_t DrawTextWrapped(
rct_drawpixelinfo* dpi, const ScreenCoordsXY& coords, int32_t width, rct_string_id format, const Formatter& ft,
TextPaint textPaint)
{
utf8 buffer[512];
format_string(buffer, sizeof(buffer), format, args);
gCurrentFontSpriteBase = FontSpriteBase::MEDIUM;
TextPaint textPaint = { colour, gCurrentFontSpriteBase, TextUnderline::Off, TextAlignment::CENTRE };
StaticLayout layout(buffer, textPaint, width);
// The original tried to vertically centre the text, but used line count - 1
int32_t lineCount = layout.GetLineCount();
int32_t lineHeight = layout.GetHeight() / lineCount;
int32_t yOffset = (lineCount - 1) * lineHeight / 2;
layout.Draw(dpi, coords - ScreenCoordsXY{ layout.GetWidth() / 2, yOffset });
return layout.GetHeight();
return DrawTextWrapped(dpi, coords, width, format, ft.Data(), textPaint);
}

View File

@ -152,3 +152,9 @@ void DrawTextBasic(
void DrawTextEllipsised(
rct_drawpixelinfo* dpi, const ScreenCoordsXY& coords, int32_t width, rct_string_id format, const Formatter& ft,
colour_t colour, TextAlignment alignment = TextAlignment::LEFT, bool underline = false);
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,9 @@ void chat_draw(rct_drawpixelinfo* dpi, uint8_t chatBackgroundColor)
screenCoords.y = _chatBottom - inputLineHeight - 5;
auto lineCh = lineBuffer.c_str();
inputLineHeight = gfx_draw_string_left_wrapped(
dpi, static_cast<void*>(&lineCh), screenCoords + ScreenCoordsXY{ 0, 3 }, _chatWidth - 10, STR_STRING,
TEXT_COLOUR_255);
inputLineHeight = DrawTextWrapped(
dpi, screenCoords + ScreenCoordsXY{ 0, 3 }, _chatWidth - 10, STR_STRING, static_cast<void*>(&lineCh),
{ TEXT_COLOUR_255 });
gfx_set_dirty_blocks({ screenCoords, { screenCoords + ScreenCoordsXY{ _chatWidth, inputLineHeight + 15 } } });
// TODO: Show caret if the input text has multiple lines