Dedup `forms.{drawString,drawText}` implementations

This commit is contained in:
YoshiRulz 2024-08-25 03:38:41 +10:00
parent b99a3831e9
commit bda40c7ba3
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
1 changed files with 12 additions and 28 deletions

View File

@ -1151,34 +1151,18 @@ namespace BizHawk.Client.EmuHawk
string fontstyle = null,
string horizalign = null,
string vertalign = null)
{
try
{
var fgColor = _th.SafeParseColor(forecolor);
var bgColor = _th.SafeParseColor(backcolor);
var ptr = new IntPtr(componentHandle);
foreach (var form in _luaForms)
{
if (form.Handle == ptr)
{
LogOutputCallback("Drawing functions cannot be used on forms directly. Use them on a PictureBox component.");
return;
}
var match = form.Controls().FirstOrDefault(c => c.Handle == ptr);
if (match is null) return;
if (match is not LuaPictureBox control)
{
LogOutputCallback(ERR_MSG_CONTROL_NOT_LPB);
return;
}
control.DrawText(x, y, message, fgColor, bgColor, fontsize, fontfamily, fontstyle, horizalign, vertalign);
}
}
catch (Exception ex)
{
LogOutputCallback(ex.Message);
}
}
=> DrawText(
componentHandle: componentHandle,
x: x,
y: y,
message: message,
forecolor: forecolor,
backcolor: backcolor,
fontsize: fontsize,
fontfamily: fontfamily,
fontstyle: fontstyle,
horizalign: horizalign,
vertalign: vertalign);
[LuaMethodExample("forms.drawText( 334, 16, 32, \"Some message\", 0x7F0000FF, 0x00007FFF, 8, \"Arial Narrow\", \"bold\", \"center\", \"middle\" );")]
[LuaMethod(