OpenBve.Interface.TryParseHexColor C# (CSharp) Method

TryParseHexColor() static private method

Parses a hexadecimal string into a Color24
static private TryParseHexColor ( string Expression, Color24 &Color ) : bool
Expression string The color in hexadecimal format
Color Color24 The Color24, updated via 'out'
return bool
		internal static bool TryParseHexColor(string Expression, out Color24 Color) {
			if (Expression.StartsWith("#")) {
				string a = Expression.Substring(1).TrimStart();
				int x; if (int.TryParse(a, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out x)) {
					int r = (x >> 16) & 0xFF;
					int g = (x >> 8) & 0xFF;
					int b = x & 0xFF;
					if (r >= 0 & r <= 255 & g >= 0 & g <= 255 & b >= 0 & b <= 255) {
						Color = new Color24((byte)r, (byte)g, (byte)b);
						return true;
					} else {
						Color = new Color24(0, 0, 255);
						return false;
					}
				} else {
					Color = new Color24(0, 0, 255);
					return false;
				}
			} else {
				Color = new Color24(0, 0, 255);
				return false;
			}
		}

Same methods

Interface::TryParseHexColor ( string Expression, Color32 &Color ) : bool
Interface::TryParseHexColor ( string Expression, World &Color ) : bool