public static MColor FromString(string def, MColor defaultValue) { if (def == null) { return(defaultValue); } if (def.StartsWith("#")) { return(FromHexString(def)); } if (def.StartsWith("c(") && def.EndsWith(")")) { return(FromJtg2CustomColor(def)); } if (jtraingraphColors.ContainsKey(def)) { return(jtraingraphColors[def]); } return(defaultValue); }
public string ToName(MColor color) => colors.FirstOrDefault(c => c.Value == color).Key ?? ColorFormatter.ToString(color);
public static string ToString(MColor c, bool useJtg2Format = false) => useJtg2Format?ToJtg2CustomColor(c) : ToHexString(c);
private static string ToJtg2CustomColor(MColor c) => "c(" + c.R + "," + c.G + "," + c.B + ")";
private static string ToHexString(MColor c) => $"#{c.R:X2}{c.G:X2}{c.B:X2}";
private static string ToHexString(MColor c) => string.Format("#{0:X2}{1:X2}{2:X2}", c.R, c.G, c.B);