From 1a123fa491e13a6a7f58ef0b839f6c4049e7495d Mon Sep 17 00:00:00 2001 From: zeromus Date: Mon, 8 Feb 2016 02:33:46 -0600 Subject: [PATCH] allow "#aarrggbb" as Color parameter to forms.setproperty. fixes #547 --- .../Lua/Libraries/EmuLuaLibrary.Forms.cs | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Forms.cs b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Forms.cs index c010793a43..9fa0390546 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Forms.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Forms.cs @@ -482,10 +482,19 @@ namespace BizHawk.Client.EmuHawk { if (form.Handle == ptr) { - if (form.GetType().GetProperty(property).PropertyType.IsEnum) + var pt = form.GetType().GetProperty(property).PropertyType; + if (pt.IsEnum) { value = Enum.Parse(form.GetType().GetProperty(property).PropertyType, value.ToString(), true); } + if (pt == typeof(Color)) + { + //relying on exceptions for error handling here + var sval = (string)value; + if (sval[0] != '#') throw new Exception("Invalid #aarrggbb color"); + if (sval.Length != 9) throw new Exception("Invalid #aarrggbb color"); + value = Color.FromArgb(int.Parse(sval.Substring(1),System.Globalization.NumberStyles.HexNumber)); + } form .GetType() .GetProperty(property) @@ -511,6 +520,15 @@ namespace BizHawk.Client.EmuHawk } } + [LuaMethodAttributes( + "createcolor", + "Creates a color object useful with setproperty" + )] + public Color CreateColor(int r, int g, int b, int a) + { + return Color.FromArgb(a, r, g, b); + } + [LuaMethodAttributes( "setsize", "TODO"