Exemplo n.º 1
0
        /// <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));
            }
        }
Exemplo n.º 2
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>
 /// <param name="alpha">0-255 (0=transparent, 255=solid)</param>
 /// <returns></returns>
 public static hColor fromRGBA(int red, int green, int blue, int alpha)
 {
     return((hColor)QColor.fromRGBA(red, green, blue, alpha));
 }
Exemplo n.º 3
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));
 }