From 0f19b9c8546af68f4dad4b9304832453f8c6c02d Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Sun, 25 Aug 2024 17:03:09 +1000 Subject: [PATCH] Also print when `LuaPictureBox.DrawIcon` called with mismatched w/h see #3851, 170d1a62e --- .../tools/Lua/Libraries/FormsLuaLibrary.cs | 21 ++++++++++++++++--- .../tools/Lua/LuaCanvas.cs | 8 ++++++- .../tools/Lua/LuaPictureBox.cs | 10 ++++++--- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/FormsLuaLibrary.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/FormsLuaLibrary.cs index 8176025ada..b42faf633a 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/FormsLuaLibrary.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/FormsLuaLibrary.cs @@ -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) { diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaCanvas.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaCanvas.cs index c754db8dee..0ca0f8632c 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaCanvas.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaCanvas.cs @@ -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) { diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaPictureBox.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaPictureBox.cs index fedc3a49aa..6e38e6ac61 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaPictureBox.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaPictureBox.cs @@ -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"); } }