Also print when `LuaPictureBox.DrawIcon` called with mismatched w/h

see #3851, 170d1a62e
This commit is contained in:
YoshiRulz 2024-08-25 17:03:09 +10:00
parent f6cb86fa65
commit 0f19b9c854
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
3 changed files with 32 additions and 7 deletions

View File

@ -535,9 +535,24 @@ namespace BizHawk.Client.EmuHawk
try
{
var match = FindFormOrControlWithHandle(componentHandle);
if (match is LuaPictureBox control) control.DrawIcon(path, x: x, y: y, width: width, height: height);
else if (match is Form) LogOutputCallback(ERR_MSG_DRAW_ON_FORM);
else if (match is not null) LogOutputCallback(ERR_MSG_CONTROL_NOT_LPB);
if (match is LuaPictureBox control)
{
control.DrawIcon(
path: path,
x: x,
y: y,
width: width,
height: height,
functionName: "forms.drawIcon");
}
else if (match is Form)
{
LogOutputCallback(ERR_MSG_DRAW_ON_FORM);
}
else if (match is not null)
{
LogOutputCallback(ERR_MSG_CONTROL_NOT_LPB);
}
}
catch (Exception ex)
{

View File

@ -220,7 +220,13 @@ namespace BizHawk.Client.EmuHawk
{
try
{
luaPictureBox.DrawIcon(path, x, y, width, height);
luaPictureBox.DrawIcon(
path: path,
x: x,
y: y,
width: width,
height: height,
functionName: "(LuaCanvas).DrawIcon");
}
catch (Exception ex)
{

View File

@ -145,15 +145,16 @@ namespace BizHawk.Client.EmuHawk
boxBackground.DrawEllipse(GetPen(TableHelper.SafeParseColor(line) ?? _defaultForeground), x, y, width, height);
}
public void DrawIcon(string path, int x, int y, int? width, int? height)
public void DrawIcon(string path, int x, int y, int? width, int? height, string functionName)
{
Icon icon;
if (width.HasValue && height.HasValue)
if (width is int w && height is int h)
{
icon = new Icon(path, width.Value, height.Value);
icon = new Icon(path, width: w, height: h);
}
else
{
if (width is not null || height is not null) WarnForMismatchedPair(functionName: functionName, kind: "width and height");
icon = new Icon(path);
}
@ -409,5 +410,8 @@ namespace BizHawk.Client.EmuHawk
DoLuaClick(this, e);
base.OnClick(e);
}
private void WarnForMismatchedPair(string functionName, string kind)
=> LogOutputCallback($"{functionName}: both {kind} must be set to have any effect");
}
}