Allow `"#RRGGBB"` format when parsing colours ("luacolor" in docs)
This commit is contained in:
parent
8dd98852be
commit
5687f800a1
|
@ -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.
|
||||
|
|
|
@ -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}\")");
|
||||
|
|
Loading…
Reference in New Issue