allow "#aarrggbb" as Color parameter to forms.setproperty. fixes #547

This commit is contained in:
zeromus 2016-02-08 02:33:46 -06:00
parent 89a4381d9d
commit 1a123fa491
1 changed files with 19 additions and 1 deletions

View File

@ -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"