Fix #11562 - gfx_draw_string_left_wrapped overload (#12015)

I created the overload, replaced remaining calls with the new function and removed the old function.
This commit is contained in:
TomasZilinek 2020-06-21 11:25:31 +02:00 committed by GitHub
parent ef5f117373
commit 9efe43fa59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 27 additions and 42 deletions

View File

@ -1080,7 +1080,7 @@ static void window_editor_object_selection_paint(rct_window* w, rct_drawpixelinf
width = w->windowPos.x + w->width - screenPos.x - 4;
gfx_draw_string_left_wrapped(
dpi, gCommonFormatArgs, screenPos.x, screenPos.y + 5, width, STR_WINDOW_COLOUR_2_STRINGID, COLOUR_BLACK);
dpi, gCommonFormatArgs, screenPos + ScreenCoordsXY{ 0, 5 }, width, STR_WINDOW_COLOUR_2_STRINGID, COLOUR_BLACK);
}
auto screenPos = w->windowPos + ScreenCoordsXY{ w->width - 5, w->height - (12 * 4) };

View File

@ -561,7 +561,7 @@ static void window_object_load_error_paint(rct_window* w, rct_drawpixelinfo* dpi
auto ft = Formatter::Common();
ft.Add<rct_string_id>(STR_OBJECT_ERROR_WINDOW_EXPLANATION);
gfx_draw_string_left_wrapped(
dpi, gCommonFormatArgs, { w->windowPos.x + 5, w->windowPos.y + 18 }, WW - 10, STR_BLACK_STRING, COLOUR_BLACK);
dpi, gCommonFormatArgs, w->windowPos + ScreenCoordsXY{ 5, 18 }, WW - 10, STR_BLACK_STRING, COLOUR_BLACK);
// Draw file name
ft = Formatter::Common();

View File

@ -348,14 +348,12 @@ void window_research_development_page_paint(rct_window* w, rct_drawpixelinfo* dp
if (gResearchProgressStage == RESEARCH_STAGE_FINISHED_ALL)
{
stringId = STR_RESEARCH_UNKNOWN;
gfx_draw_string_left_wrapped(
dpi, &stringId, screenCoords.x, screenCoords.y, 296, STR_RESEARCH_TYPE_LABEL, COLOUR_BLACK);
gfx_draw_string_left_wrapped(dpi, &stringId, screenCoords, 296, STR_RESEARCH_TYPE_LABEL, COLOUR_BLACK);
screenCoords.y += 25;
// Progress
stringId = STR_RESEARCH_COMPLETED_AL;
gfx_draw_string_left_wrapped(
dpi, &stringId, screenCoords.x, screenCoords.y, 296, STR_RESEARCH_PROGRESS_LABEL, COLOUR_BLACK);
gfx_draw_string_left_wrapped(dpi, &stringId, screenCoords, 296, STR_RESEARCH_PROGRESS_LABEL, COLOUR_BLACK);
screenCoords.y += 15;
auto ft = Formatter::Common();
@ -391,13 +389,12 @@ void window_research_development_page_paint(rct_window* w, rct_drawpixelinfo* dp
}
}
}
gfx_draw_string_left_wrapped(dpi, &strings, screenCoords.x, screenCoords.y, 296, label, COLOUR_BLACK);
gfx_draw_string_left_wrapped(dpi, &strings, screenCoords, 296, label, COLOUR_BLACK);
screenCoords.y += 25;
// Progress
stringId = ResearchStageNames[gResearchProgressStage];
gfx_draw_string_left_wrapped(
dpi, &stringId, screenCoords.x, screenCoords.y, 296, STR_RESEARCH_PROGRESS_LABEL, COLOUR_BLACK);
gfx_draw_string_left_wrapped(dpi, &stringId, screenCoords, 296, STR_RESEARCH_PROGRESS_LABEL, COLOUR_BLACK);
screenCoords.y += 15;
// Expected
@ -446,7 +443,7 @@ void window_research_development_page_paint(rct_window* w, rct_drawpixelinfo* dp
}
}
gfx_draw_string_left_wrapped(dpi, &strings, screenCoords.x, screenCoords.y, 266, lastDevelopmentFormat, COLOUR_BLACK);
gfx_draw_string_left_wrapped(dpi, &strings, screenCoords, 266, lastDevelopmentFormat, COLOUR_BLACK);
}
}

View File

@ -3192,7 +3192,7 @@ static void window_ride_vehicle_paint(rct_window* w, rct_drawpixelinfo* dpi)
// Description
screenCoords.y += gfx_draw_string_left_wrapped(
dpi, &rideEntry->naming.Description, screenCoords.x, screenCoords.y, 300, STR_BLACK_STRING, COLOUR_BLACK);
dpi, &rideEntry->naming.Description, screenCoords, 300, STR_BLACK_STRING, COLOUR_BLACK);
screenCoords.y += 2;
// Capacity
@ -4399,7 +4399,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_left_wrapped(dpi, nullptr, screenCoords.x + 4, screenCoords.y, 280, stringId, COLOUR_BLACK);
gfx_draw_string_left_wrapped(dpi, nullptr, screenCoords + ScreenCoordsXY{ 4, 0 }, 280, stringId, COLOUR_BLACK);
}
else
{
@ -4408,7 +4408,7 @@ static void window_ride_maintenance_paint(rct_window* w, rct_drawpixelinfo* dpi)
{
peep->FormatNameTo(gCommonFormatArgs);
gfx_draw_string_left_wrapped(
dpi, gCommonFormatArgs, screenCoords.x + 4, screenCoords.y, 280, stringId, COLOUR_BLACK);
dpi, gCommonFormatArgs, screenCoords + ScreenCoordsXY{ 4, 0 }, 280, stringId, COLOUR_BLACK);
}
}
}
@ -7106,8 +7106,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_left_wrapped(
dpi, &queueTime, screenCoords.x, screenCoords.y, 308, stringId, COLOUR_BLACK);
screenCoords.y += gfx_draw_string_left_wrapped(dpi, &queueTime, screenCoords, 308, stringId, COLOUR_BLACK);
screenCoords.y += 5;
}

View File

@ -479,7 +479,7 @@ static void window_scenarioselect_paint(rct_window* w, rct_drawpixelinfo* dpi)
gfx_draw_string_centred_clipped(
dpi, STR_SCENARIO_LOCKED, nullptr, COLOUR_BLACK, screenPos + ScreenCoordsXY{ 85, 0 }, 170);
gfx_draw_string_left_wrapped(
dpi, nullptr, screenPos.x, screenPos.y + 15, 170, STR_SCENARIO_LOCKED_DESC, COLOUR_BLACK);
dpi, nullptr, screenPos + ScreenCoordsXY{ 0, 15 }, 170, STR_SCENARIO_LOCKED_DESC, COLOUR_BLACK);
}
return;
}
@ -513,9 +513,7 @@ static void window_scenarioselect_paint(rct_window* w, rct_drawpixelinfo* dpi)
ft = Formatter::Common();
ft.Add<rct_string_id>(STR_STRING);
ft.Add<const char*>(scenario->details);
screenPos.y += gfx_draw_string_left_wrapped(
dpi, gCommonFormatArgs, screenPos.x, screenPos.y, 170, STR_BLACK_STRING, COLOUR_BLACK)
+ 5;
screenPos.y += gfx_draw_string_left_wrapped(dpi, gCommonFormatArgs, screenPos, 170, STR_BLACK_STRING, COLOUR_BLACK) + 5;
// Scenario objective
ft = Formatter::Common();
@ -523,9 +521,7 @@ static void window_scenarioselect_paint(rct_window* w, rct_drawpixelinfo* dpi)
ft.Add<int16_t>(scenario->objective_arg_3);
ft.Add<int16_t>(date_get_total_months(MONTH_OCTOBER, scenario->objective_arg_1));
ft.Add<int32_t>(scenario->objective_arg_2);
screenPos.y += gfx_draw_string_left_wrapped(
dpi, gCommonFormatArgs, screenPos.x, screenPos.y, 170, STR_OBJECTIVE, COLOUR_BLACK)
+ 5;
screenPos.y += gfx_draw_string_left_wrapped(dpi, gCommonFormatArgs, screenPos, 170, STR_OBJECTIVE, COLOUR_BLACK) + 5;
// Scenario score
if (scenario->highscore != nullptr)
@ -541,7 +537,7 @@ static void window_scenarioselect_paint(rct_window* w, rct_drawpixelinfo* dpi)
ft.Add<const char*>(completedByName);
ft.Add<money32>(scenario->highscore->company_value);
screenPos.y += gfx_draw_string_left_wrapped(
dpi, gCommonFormatArgs, screenPos.x, screenPos.y, 170, STR_COMPLETED_BY_WITH_COMPANY_VALUE, COLOUR_BLACK);
dpi, gCommonFormatArgs, screenPos, 170, STR_COMPLETED_BY_WITH_COMPANY_VALUE, COLOUR_BLACK);
}
}

View File

@ -664,8 +664,6 @@ void gfx_draw_string_centred_clipped(
void gfx_draw_string_right_clipped(
rct_drawpixelinfo* dpi, rct_string_id format, void* args, uint8_t colour, const ScreenCoordsXY& coords, int32_t width);
int32_t gfx_draw_string_left_wrapped(
rct_drawpixelinfo* dpi, void* args, int32_t x, int32_t y, int32_t width, rct_string_id format, uint8_t colour);
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(

View File

@ -207,12 +207,6 @@ void gfx_draw_string_right_clipped(
}
// Wrapping
int32_t gfx_draw_string_left_wrapped(
rct_drawpixelinfo* dpi, void* args, int32_t x, int32_t y, int32_t width, rct_string_id format, uint8_t colour)
{
return gfx_draw_string_left_wrapped(dpi, args, { x, y }, width, format, colour);
}
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)
{

View File

@ -142,12 +142,11 @@ void chat_draw(rct_drawpixelinfo* dpi, uint8_t chatBackgroundColor)
INSET_RECT_FLAG_BORDER_INSET); // Textbox
}
int32_t x = _chatLeft + 5;
int32_t y = _chatBottom - inputLineHeight - 20;
auto screenCoords = ScreenCoordsXY{ _chatLeft + 5, _chatBottom - inputLineHeight - 20 };
int32_t stringHeight = 0;
// Draw chat history
for (int32_t i = 0; i < CHAT_HISTORY_SIZE; i++, y -= stringHeight)
for (int32_t i = 0; i < CHAT_HISTORY_SIZE; i++, screenCoords.y -= stringHeight)
{
uint32_t expireTime = chat_history_get_time(i) + 10000;
if (!gChatOpen && platform_get_ticks() > expireTime)
@ -157,10 +156,10 @@ void chat_draw(rct_drawpixelinfo* dpi, uint8_t chatBackgroundColor)
safe_strcpy(lineBuffer, chat_history_get(i), sizeof(lineBuffer));
stringHeight = chat_history_draw_string(dpi, static_cast<void*>(&lineCh), ScreenCoordsXY(x, y), _chatWidth - 10) + 5;
gfx_set_dirty_blocks(x, y - stringHeight, x + _chatWidth, y + 20);
stringHeight = chat_history_draw_string(dpi, static_cast<void*>(&lineCh), screenCoords, _chatWidth - 10) + 5;
gfx_set_dirty_blocks(screenCoords.x, screenCoords.y - stringHeight, screenCoords.x + _chatWidth, screenCoords.y + 20);
if ((y - stringHeight) < 50)
if ((screenCoords.y - stringHeight) < 50)
{
break;
}
@ -173,20 +172,22 @@ void chat_draw(rct_drawpixelinfo* dpi, uint8_t chatBackgroundColor)
lineCh = utf8_write_codepoint(lineCh, FORMAT_CELADON);
safe_strcpy(lineCh, _chatCurrentLine, sizeof(_chatCurrentLine));
y = _chatBottom - inputLineHeight - 5;
screenCoords.y = _chatBottom - inputLineHeight - 5;
lineCh = lineBuffer;
inputLineHeight = gfx_draw_string_left_wrapped(
dpi, static_cast<void*>(&lineCh), x, y + 3, _chatWidth - 10, STR_STRING, TEXT_COLOUR_255);
gfx_set_dirty_blocks(x, y, x + _chatWidth, y + inputLineHeight + 15);
dpi, static_cast<void*>(&lineCh), screenCoords + ScreenCoordsXY{ 0, 3 }, _chatWidth - 10, STR_STRING,
TEXT_COLOUR_255);
gfx_set_dirty_blocks(
screenCoords.x, screenCoords.y, screenCoords.x + _chatWidth, screenCoords.y + inputLineHeight + 15);
// TODO: Show caret if the input text has multiple lines
if (_chatCaretTicks < 15 && gfx_get_string_width(lineBuffer) < (_chatWidth - 10))
{
std::memcpy(lineBuffer, _chatCurrentLine, _chatTextInputSession->SelectionStart);
lineBuffer[_chatTextInputSession->SelectionStart] = 0;
int32_t caretX = x + gfx_get_string_width(lineBuffer);
int32_t caretY = y + 14;
int32_t caretX = screenCoords.x + gfx_get_string_width(lineBuffer);
int32_t caretY = screenCoords.y + 14;
gfx_fill_rect(dpi, caretX, caretY, caretX + 6, caretY + 1, PALETTE_INDEX_56);
}