/// <summary> /// Creates a colour from a string, Returns black when an error occurs /// String can be int the form (i)(i a)(r g b)(r g b a) OR a prenamed color string /// </summary> /// <param name="s">String to parse</param> /// <returns></returns> public static HColor fromString(string s) { try { string[] elements = s.Trim().Replace(" ", " ").Split(" ".ToCharArray()); float c; if (s.IndexOfAny(".".ToCharArray()) != -1) { //floating point information string switch (elements.Length) { case 0: return(HColor.fromRGB(0, 0, 0)); case 1: c = float.Parse(elements[0]); return(HColor.fromRGB(c, c, c)); case 2: //assume c c c a (intensity + opacity) c = float.Parse(elements[0]); return(HColor.fromRGBA(c, c, c, float.Parse(elements[1]))); case 3: return(HColor.fromRGB(float.Parse(elements[0]), float.Parse(elements[1]), float.Parse(elements[2]))); default: //four or more return(HColor.fromRGBA(float.Parse(elements[0]), float.Parse(elements[1]), float.Parse(elements[2]), float.Parse(elements[2]))); } } else { //integer(0-255) or named string QColor col = QColor.fromString(s); return((HColor)col); } } catch { return(QColor.fromRGB(0, 0, 0)); } }
/// <summary> /// Creates a new qColour /// </summary> /// <param name="red">0-255</param> /// <param name="green">0-255</param> /// <param name="blue">0-255</param> /// <returns></returns> public static HColor fromRGB(int red, int green, int blue) { return((HColor)QColor.fromRGB(red, green, blue)); }