Allow `"#RRGGBB"` format when parsing colours ("luacolor" in docs)

This commit is contained in:
YoshiRulz 2021-12-29 15:28:12 +10:00
parent 8dd98852be
commit 5687f800a1
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
2 changed files with 7 additions and 2 deletions

View File

@ -33,7 +33,7 @@ namespace BizHawk.Client.Common
* luacolor
** Any of:
** a 32-bit number in the format 0xAARRGGBB;
** a string in the format ""#AARRGGBB"";
** a string in the format ""#RRGGBB"" or ""#AARRGGBB"";
** a string containing a CSS3/X11 color name e.g. ""blue"", ""palegoldenrod""; or
** a Color created with forms.createcolor.
** As noted above, luacolor? indicates nil may also be passed.

View File

@ -86,7 +86,12 @@ namespace BizHawk.Client.Common
case int i:
return Color.FromArgb(i);
case string s:
if (s[0] == '#' && s.Length == 9) return ParseColor(int.Parse(s.Substring(1), NumberStyles.HexNumber), safe, logCallback);
if (s[0] is '#' && (s.Length is 7 or 9))
{
var i1 = uint.Parse(s.Substring(1), NumberStyles.HexNumber);
if (s.Length is 7) i1 |= 0xFF000000U;
return ParseColor(unchecked((int) i1), safe, logCallback);
}
var fromName = Color.FromName(s);
if (fromName.IsNamedColor) return fromName;
if (safe) logCallback($"ParseColor: not a known color name (\"{s}\")");