Pass context by ref for all string functions (#1087)

This commit is contained in:
Duncan 2021-08-06 19:54:52 +01:00 committed by GitHub
parent 43b670507d
commit 33c28eff12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 56 additions and 56 deletions

View File

@ -53,7 +53,7 @@ namespace OpenLoco::Drawing
const int stringWidth = Gfx::getStringWidth(buffer);
const auto x = Ui::width() / 2 - (stringWidth / 2);
const auto y = 2;
Gfx::drawString(&context, x, y, Colour::black, buffer);
Gfx::drawString(context, x, y, Colour::black, buffer);
// Make area dirty so the text doesn't get drawn over the last
Gfx::setDirtyBlocks(x - 16, y - 4, x + 16, 16);

View File

@ -791,38 +791,38 @@ namespace OpenLoco::Gfx
* @param context @<edi>
* @param text @<esi>
*/
Gfx::point_t drawString(Context* context, int16_t x, int16_t y, uint8_t colour, void* str)
Gfx::point_t drawString(Context& context, const int16_t x, const int16_t y, uint8_t colour, void* str)
{
// 0x00E04348, 0x00E0434A
Gfx::point_t origin = { x, y };
if (colour == FormatFlags::fe)
{
return loopNewline(context, origin, (uint8_t*)str);
return loopNewline(&context, origin, (uint8_t*)str);
}
if (colour == FormatFlags::fd)
{
_currentFontFlags = 0;
setTextColour(0);
return loopNewline(context, origin, (uint8_t*)str);
return loopNewline(&context, origin, (uint8_t*)str);
}
if (x >= context->x + context->width)
if (x >= context.x + context.width)
return origin;
if (x < context->x - 1280)
if (x < context.x - 1280)
return origin;
if (y >= context->y + context->height)
if (y >= context.y + context.height)
return origin;
if (y < context->y - 90)
if (y < context.y - 90)
return origin;
if (colour == FormatFlags::ff)
{
return loopNewline(context, origin, (uint8_t*)str);
return loopNewline(&context, origin, (uint8_t*)str);
}
_currentFontFlags = 0;
@ -881,7 +881,7 @@ namespace OpenLoco::Gfx
setTextColours(Colour::getShade(colour, 9), PaletteIndex::index_0A, PaletteIndex::index_0A);
}
return loopNewline(context, origin, (uint8_t*)str);
return loopNewline(&context, origin, (uint8_t*)str);
}
// 0x00495224
@ -1135,25 +1135,25 @@ namespace OpenLoco::Gfx
* returns width @<ax>
*/
uint16_t drawStringCentredWrapped(
Context* context,
point_t* origin,
Context& context,
point_t& origin,
uint16_t width,
uint8_t colour,
string_id stringId,
const void* args)
{
registers regs;
regs.edi = X86Pointer(context);
regs.edi = X86Pointer(&context);
regs.esi = X86Pointer(args);
regs.cx = origin->x;
regs.dx = origin->y;
regs.cx = origin.x;
regs.dx = origin.y;
regs.bp = width;
regs.al = colour;
regs.bx = stringId;
call(0x00494ECF, regs);
origin->x = regs.cx;
origin->y = regs.dx;
origin.x = regs.cx;
origin.y = regs.dx;
return regs.ax;
}

View File

@ -137,7 +137,7 @@ namespace OpenLoco::Gfx
uint16_t getStringWidth(const char* buffer);
uint16_t getMaxStringWidth(const char* buffer);
Gfx::point_t drawString(Context* context, int16_t x, int16_t y, uint8_t colour, void* str);
Gfx::point_t drawString(Context& context, int16_t x, int16_t y, uint8_t colour, void* str);
int16_t drawString_495224(
Context& context,
@ -205,8 +205,8 @@ namespace OpenLoco::Gfx
string_id stringId,
const void* args = nullptr);
uint16_t drawStringCentredWrapped(
Context* context,
point_t* origin,
Context& context,
point_t& origin,
uint16_t width,
uint8_t colour,
string_id stringId,

View File

@ -696,7 +696,7 @@ void OpenLoco::Interop::registerHooks()
0x00451025,
[](registers& regs) FORCE_ALIGN_ARG_POINTER -> uint8_t {
registers backup = regs;
auto pos = Gfx::drawString(X86Pointer<Gfx::Context>(regs.edi), regs.cx, regs.dx, regs.al, X86Pointer<uint8_t>(regs.esi));
auto pos = Gfx::drawString(*X86Pointer<Gfx::Context>(regs.edi), regs.cx, regs.dx, regs.al, X86Pointer<uint8_t>(regs.esi));
regs = backup;
regs.cx = pos.x;
regs.dx = pos.y;

View File

@ -184,7 +184,7 @@ namespace OpenLoco::Ui::Dropdown
_currentFontSpriteBase = Font::m1;
Gfx::drawString(context, x, y, colour, _byte_112CC04);
Gfx::drawString(*context, x, y, colour, _byte_112CC04);
}
// 0x004CD00E

View File

@ -617,7 +617,7 @@ namespace OpenLoco::Ui
drawStationNameBackground(context, window, this, x, y, colour, width);
Gfx::drawString(context, x, y, Colour::black, stringBuffer);
Gfx::drawString(*context, x, y, Colour::black, stringBuffer);
}
// 0x004CA7F6
@ -635,7 +635,7 @@ namespace OpenLoco::Ui
int16_t stringWidth = Gfx::clipString(width - 8, stringBuffer);
x -= (stringWidth - 1) / 2;
Gfx::drawString(context, x, window->y + top + 1, FormatFlags::textflag_5 | Colour::black, stringBuffer);
Gfx::drawString(*context, x, window->y + top + 1, FormatFlags::textflag_5 | Colour::black, stringBuffer);
}
// 0x004CA88B
@ -653,7 +653,7 @@ namespace OpenLoco::Ui
int16_t stringWidth = Gfx::clipString(width - 8, stringBuffer);
x -= (stringWidth - 1) / 2;
Gfx::drawString(context, x, window->y + top + 1, FormatFlags::textflag_5 | Colour::black, stringBuffer);
Gfx::drawString(*context, x, window->y + top + 1, FormatFlags::textflag_5 | Colour::black, stringBuffer);
}
static void draw_hscroll(Gfx::Context* context, const Window* window, Widget* widget, uint16_t flags, uint8_t colour, bool enabled, bool disabled, bool activated, bool hovered, int16_t scrollview_index)
@ -683,7 +683,7 @@ namespace OpenLoco::Ui
// popa
// pusha
Gfx::drawString(context, ax + 2, cx, Colour::black, (char*)0x005045F2);
Gfx::drawString(*context, ax + 2, cx, Colour::black, (char*)0x005045F2);
// popa
// pusha
@ -696,7 +696,7 @@ namespace OpenLoco::Ui
// popa
// pusha
Gfx::drawString(context, bx - 6 - 1, cx, Colour::black, (char*)0x005045F5);
Gfx::drawString(*context, bx - 6 - 1, cx, Colour::black, (char*)0x005045F5);
// popa
// pusha
@ -748,7 +748,7 @@ namespace OpenLoco::Ui
// popa
// pusha
Gfx::drawString(context, ax + 1, cx - 1, Colour::black, (char*)0x005045EC);
Gfx::drawString(*context, ax + 1, cx - 1, Colour::black, (char*)0x005045EC);
// popa
// pusha
@ -761,7 +761,7 @@ namespace OpenLoco::Ui
// popa
// pusha
Gfx::drawString(context, ax + 1, dx - 8 - 1, Colour::black, (char*)0x005045EF);
Gfx::drawString(*context, ax + 1, dx - 8 - 1, Colour::black, (char*)0x005045EF);
// popa
// pusha
@ -880,7 +880,7 @@ namespace OpenLoco::Ui
if (activated)
{
_currentFontSpriteBase = Font::medium_bold;
Gfx::drawString(context, window->x + left, window->y + top, colour & 0x7F, _strCheckmark);
Gfx::drawString(*context, window->x + left, window->y + top, colour & 0x7F, _strCheckmark);
}
}
@ -927,7 +927,7 @@ namespace OpenLoco::Ui
char buffer[512] = { 0 };
StringManager::formatString(buffer, sizeof(buffer), text);
Gfx::drawString(context, l, t, colour, buffer);
Gfx::drawString(*context, l, t, colour, buffer);
textEndPos = l + Gfx::getStringWidth(buffer) + 1;
}

View File

@ -273,7 +273,7 @@ namespace OpenLoco::Ui::Windows::CompanyFaceSelection
_currentFontSpriteBase = Font::m1;
stringColour = Colour::opaque(self.getColour(WindowColour::secondary)) | (1 << 6);
}
Gfx::drawString(&context, 0, y - 1, stringColour, const_cast<char*>(name.c_str()));
Gfx::drawString(context, 0, y - 1, stringColour, const_cast<char*>(name.c_str()));
index++;
}

View File

@ -224,8 +224,8 @@ namespace OpenLoco::Ui::Windows::CompanyWindow
auto& widget = self->widgets[widx::change_owner_name];
auto origin = Gfx::point_t(self->x + (widget.left + widget.right) / 2, self->y + widget.top + 5);
Gfx::drawStringCentredWrapped(
context,
&origin,
*context,
origin,
widget.right - widget.left,
Colour::black,
StringIds::black_stringid,
@ -821,7 +821,7 @@ namespace OpenLoco::Ui::Windows::CompanyWindow
static_cast<int16_t>(self->y + self->widgets[widx::viewport].top + self->widgets[widx::viewport].height() / 2 - 5)
};
width -= 2;
Gfx::drawStringCentredWrapped(context, &loc, width, Colour::black, StringIds::not_yet_constructed);
Gfx::drawStringCentredWrapped(*context, loc, width, Colour::black, StringIds::not_yet_constructed);
}
if (self->viewports[0] != nullptr)

View File

@ -72,7 +72,7 @@ namespace OpenLoco::Ui::Windows::EditKeyboardShortcut
FormatArguments args{};
args.push(ShortcutManager::getName(static_cast<Shortcut>(*_11364A4)));
auto point = Gfx::point_t(self->x + 140, self->y + 32);
Gfx::drawStringCentredWrapped(ctx, &point, 272, 0, StringIds::change_keyboard_shortcut_desc, &args);
Gfx::drawStringCentredWrapped(*ctx, point, 272, 0, StringIds::change_keyboard_shortcut_desc, &args);
}
// 0x004BE821

View File

@ -45,7 +45,7 @@ namespace OpenLoco::Ui::Windows::LandscapeGenerationConfirm
*commonFormatArgs = prompt;
auto origin = Gfx::point_t(window->x + (window->width / 2), window->y + 41);
Gfx::drawStringCentredWrapped(context, &origin, window->width, Colour::black, StringIds::wcolour2_stringid, (const char*)&*commonFormatArgs);
Gfx::drawStringCentredWrapped(*context, origin, window->width, Colour::black, StringIds::wcolour2_stringid, (const char*)&*commonFormatArgs);
}
// 0x004C18E4

View File

@ -120,12 +120,12 @@ namespace OpenLoco::Ui::Windows::MapToolTip
if (_mapTooltipOwner == CompanyId::null || _mapTooltipOwner == CompanyManager::getControllingId())
{
Gfx::point_t origin(self->x + self->width / 2, self->y + self->height / 2 - 5);
Gfx::drawStringCentredWrapped(context, &origin, self->width, Colour::black, StringIds::outlined_wcolour2_stringid, &args);
Gfx::drawStringCentredWrapped(*context, origin, self->width, Colour::black, StringIds::outlined_wcolour2_stringid, &args);
}
else
{
Gfx::point_t origin(self->x + self->width / 2 + 13, self->y + self->height / 2 - 5);
auto width = Gfx::drawStringCentredWrapped(context, &origin, self->width - 28, Colour::black, StringIds::outlined_wcolour2_stringid, &args);
auto width = Gfx::drawStringCentredWrapped(*context, origin, self->width - 28, Colour::black, StringIds::outlined_wcolour2_stringid, &args);
auto left = self->width / 2 + self->x + 13 - width / 2 - 28;
auto top = self->height / 2 - 13 + self->y;

View File

@ -1380,7 +1380,7 @@ namespace OpenLoco::Ui::Windows::MapWindow
townPos.y -= 3;
_currentFontSpriteBase = Font::small;
Gfx::drawString(context, townPos.x, townPos.y, Colour::outline(Colour::bright_purple), _stringFormatBuffer);
Gfx::drawString(*context, townPos.x, townPos.y, Colour::outline(Colour::bright_purple), _stringFormatBuffer);
}
}

View File

@ -588,7 +588,7 @@ namespace OpenLoco::Ui::Windows::NewsWindow
int16_t y = self->y + 38;
Gfx::point_t origin = { x, y };
Gfx::drawStringCentredWrapped(context, &origin, 352, Colour::black, StringIds::buffer_2039);
Gfx::drawStringCentredWrapped(*context, origin, 352, Colour::black, StringIds::buffer_2039);
x = self->x + 1;
y = self->y + 1;
@ -668,7 +668,7 @@ namespace OpenLoco::Ui::Windows::NewsWindow
int16_t y = self->y + 38;
Gfx::point_t origin = { x, y };
Gfx::drawStringCentredWrapped(context, &origin, 352, Colour::black, StringIds::buffer_2039);
Gfx::drawStringCentredWrapped(*context, origin, 352, Colour::black, StringIds::buffer_2039);
origin.x = self->x + 4;
origin.y = self->y + 5;
@ -711,7 +711,7 @@ namespace OpenLoco::Ui::Windows::NewsWindow
int16_t y = self->y + 17;
Gfx::point_t origin = { x, y };
Gfx::drawStringCentredWrapped(context, &origin, 338, Colour::black, StringIds::buffer_2039);
Gfx::drawStringCentredWrapped(*context, origin, 338, Colour::black, StringIds::buffer_2039);
self->drawViewports(context);

View File

@ -630,7 +630,7 @@ namespace OpenLoco::Ui::Windows::ObjectSelectionWindow
checkColour = Colour::inset(checkColour);
}
Gfx::drawString(&context, x, y, checkColour, _strCheckmark);
Gfx::drawString(context, x, y, checkColour, _strCheckmark);
}
char buffer[512]{};
@ -638,7 +638,7 @@ namespace OpenLoco::Ui::Windows::ObjectSelectionWindow
strncpy(&buffer[1], object._name, 510);
_currentFontSpriteBase = Font::medium_bold;
Gfx::drawString(&context, 15, y, Colour::black, buffer);
Gfx::drawString(context, 15, y, Colour::black, buffer);
y += rowHeight;
}
}

View File

@ -572,7 +572,7 @@ namespace OpenLoco::Ui::Windows::PromptBrowse
auto imageId = ImageIds::random_map_watermark | (window.getColour(WindowColour::secondary) << 19) | 0x20000000;
Gfx::drawImage(&context, x, y, imageId);
Gfx::point_t origin = { (int16_t)(x + 64), (int16_t)(y + 60) };
Gfx::drawStringCentredWrapped(&context, &origin, 128, 0, StringIds::randomly_generated_landscape);
Gfx::drawStringCentredWrapped(context, origin, 128, 0, StringIds::randomly_generated_landscape);
}
}

View File

@ -150,7 +150,7 @@ namespace OpenLoco::Ui::Windows::PromptOkCancel
args.push(StringIds::buffer_2039);
auto origin = Gfx::point_t(self->x + self->width / 2, self->y + 41);
Gfx::drawStringCentredWrapped(context, &origin, self->width, Colour::black, StringIds::wcolour2_stringid, &args);
Gfx::drawStringCentredWrapped(*context, origin, self->width, Colour::black, StringIds::wcolour2_stringid, &args);
}
static void initEvents()

View File

@ -177,7 +177,7 @@ namespace OpenLoco::Ui::Windows::ScenarioSelect
auto origin = Gfx::point_t(widget.mid_x() + self->x, widget.mid_y() + self->y - 3 - offset);
const string_id caption = scenarioGroupIds[i];
Gfx::drawStringCentredWrapped(context, &origin, widget.width() - 4, Colour::black, StringIds::wcolour2_stringid, &caption);
Gfx::drawStringCentredWrapped(*context, origin, widget.width() - 4, Colour::black, StringIds::wcolour2_stringid, &caption);
}
// Scenario selected?
@ -272,7 +272,7 @@ namespace OpenLoco::Ui::Windows::ScenarioSelect
// Overlay random map note.
auto origin = Gfx::point_t(x, y);
Gfx::drawStringCentredWrapped(context, &origin, 128, Colour::black, StringIds::wcolour2_stringid, &args);
Gfx::drawStringCentredWrapped(*context, origin, 128, Colour::black, StringIds::wcolour2_stringid, &args);
}
{

View File

@ -240,7 +240,7 @@ namespace OpenLoco::Ui::Windows::TextInput
memcpy(&_commonFormatArgs[2], _formatArgs + 8, 8);
Gfx::point_t position = { (int16_t)(window->x + window->width / 2), (int16_t)(window->y + 30) };
Gfx::drawStringCentredWrapped(context, &position, window->width - 8, 0, StringIds::wcolour2_stringid, &_commonFormatArgs[0]);
Gfx::drawStringCentredWrapped(*context, position, window->width - 8, 0, StringIds::wcolour2_stringid, &_commonFormatArgs[0]);
auto widget = &_widgets[Widx::input];
Gfx::Context* clipped = nullptr;

View File

@ -159,7 +159,7 @@ namespace OpenLoco::Ui::Windows::TileInspector
snprintf(&buffer[1], std::size(buffer) - 1, "Data: %02x %02x %02x %02x %02x %02x %02x %02x", data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]);
auto widget = self->widgets[widx::detailsGroup];
Gfx::drawString(context, self->x + widget.left + 7, self->y + widget.top + 14, Colour::black, buffer);
Gfx::drawString(*context, self->x + widget.left + 7, self->y + widget.top + 14, Colour::black, buffer);
}
}

View File

@ -75,7 +75,7 @@ namespace OpenLoco::Ui::Windows::TitleExit
int16_t x = window->x + window->width / 2;
int16_t y = window->y + window->widgets[Widx::exit_button].top + 8;
Gfx::point_t origin = { x, y };
Gfx::drawStringCentredWrapped(context, &origin, window->width, Colour::black, StringIds::title_exit_game);
Gfx::drawStringCentredWrapped(*context, origin, window->width, Colour::black, StringIds::title_exit_game);
}
// 0x00439268

View File

@ -65,7 +65,7 @@ namespace OpenLoco::Ui::Windows::TitleOptions
int16_t y = window->y + window->widgets[Widx::options_button].top + 2;
Gfx::point_t origin = { x, y };
Gfx::drawStringCentredWrapped(context, &origin, window->width, Colour::white, StringIds::outlined_wcolour2_stringid, (const char*)&StringIds::options);
Gfx::drawStringCentredWrapped(*context, origin, window->width, Colour::white, StringIds::outlined_wcolour2_stringid, (const char*)&StringIds::options);
}
static void onMouseUp(Window* window, WidgetIndex_t widgetIndex)

View File

@ -40,6 +40,6 @@ namespace OpenLoco::Ui::Windows::TitleVersion
static void draw(Ui::Window* window, Gfx::Context* context)
{
auto versionInfo = getVersionInfo();
Gfx::drawString(context, window->x, window->y, Colour::white | FormatFlags::textflag_5, (void*)versionInfo.c_str());
Gfx::drawString(*context, window->x, window->y, Colour::white | FormatFlags::textflag_5, (void*)versionInfo.c_str());
}
}

View File

@ -942,8 +942,8 @@ namespace OpenLoco::Ui::Windows::Vehicle
origin.x = self->x + button.mid_x();
origin.y = self->y + button.mid_y();
Gfx::drawStringCentredWrapped(
context,
&origin,
*context,
origin,
button.width() - 6,
Colour::black,
StringIds::click_on_view_select_string_id_start,