Skip to content

Commit 0f19b9c

Browse files
committed
Also print when LuaPictureBox.DrawIcon called with mismatched w/h
see #3851, 170d1a6
1 parent f6cb86f commit 0f19b9c

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/FormsLuaLibrary.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,9 +535,24 @@ public void DrawIcon(
535535
try
536536
{
537537
var match = FindFormOrControlWithHandle(componentHandle);
538-
if (match is LuaPictureBox control) control.DrawIcon(path, x: x, y: y, width: width, height: height);
539-
else if (match is Form) LogOutputCallback(ERR_MSG_DRAW_ON_FORM);
540-
else if (match is not null) LogOutputCallback(ERR_MSG_CONTROL_NOT_LPB);
538+
if (match is LuaPictureBox control)
539+
{
540+
control.DrawIcon(
541+
path: path,
542+
x: x,
543+
y: y,
544+
width: width,
545+
height: height,
546+
functionName: "forms.drawIcon");
547+
}
548+
else if (match is Form)
549+
{
550+
LogOutputCallback(ERR_MSG_DRAW_ON_FORM);
551+
}
552+
else if (match is not null)
553+
{
554+
LogOutputCallback(ERR_MSG_CONTROL_NOT_LPB);
555+
}
541556
}
542557
catch (Exception ex)
543558
{

src/BizHawk.Client.EmuHawk/tools/Lua/LuaCanvas.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,13 @@ public void DrawIcon(string path, int x, int y, int? width = null, int? height =
220220
{
221221
try
222222
{
223-
luaPictureBox.DrawIcon(path, x, y, width, height);
223+
luaPictureBox.DrawIcon(
224+
path: path,
225+
x: x,
226+
y: y,
227+
width: width,
228+
height: height,
229+
functionName: "(LuaCanvas).DrawIcon");
224230
}
225231
catch (Exception ex)
226232
{

src/BizHawk.Client.EmuHawk/tools/Lua/LuaPictureBox.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,16 @@ public void DrawEllipse(
145145
boxBackground.DrawEllipse(GetPen(TableHelper.SafeParseColor(line) ?? _defaultForeground), x, y, width, height);
146146
}
147147

148-
public void DrawIcon(string path, int x, int y, int? width, int? height)
148+
public void DrawIcon(string path, int x, int y, int? width, int? height, string functionName)
149149
{
150150
Icon icon;
151-
if (width.HasValue && height.HasValue)
151+
if (width is int w && height is int h)
152152
{
153-
icon = new Icon(path, width.Value, height.Value);
153+
icon = new Icon(path, width: w, height: h);
154154
}
155155
else
156156
{
157+
if (width is not null || height is not null) WarnForMismatchedPair(functionName: functionName, kind: "width and height");
157158
icon = new Icon(path);
158159
}
159160

@@ -409,5 +410,8 @@ protected override void OnClick(EventArgs e)
409410
DoLuaClick(this, e);
410411
base.OnClick(e);
411412
}
413+
414+
private void WarnForMismatchedPair(string functionName, string kind)
415+
=> LogOutputCallback($"{functionName}: both {kind} must be set to have any effect");
412416
}
413417
}

0 commit comments

Comments
 (0)