public void ParseColorStopWithoutValue()
        {
            var stop = ColorStop.Parse("#00a, #fff, #000");

            Assert.Equal(Rgba32.Parse("#00a"), stop.Color);
            Assert.Null(stop.Position);
        }
        public void ParseColorStopWithRgb()
        {
            var stop = ColorStop.Parse("rgb(153, 116, 186) 0%");

            Assert.Equal(new Rgba32(153, 116, 186), stop.Color);
            Assert.Equal(0, stop.Position);
        }
        public void ParseColorStop()
        {
            var stop = ColorStop.Parse("#00a 90%");

            Assert.Equal(Rgba32.Parse("#00a"), stop.Color);
            Assert.Equal(0.9, stop.Position);
        }
Exemple #4
0
        public static object Parse(string s)
        {
            if (string.IsNullOrEmpty(s))
            {
                return(Color.White);
            }

            Crow.Gradient tmp;

            string[] stops = s.Trim().Split('|');

            switch (stops[0].Trim())
            {
            case "vgradient":
                tmp = new Gradient(Type.Vertical);
                break;

            case "hgradient":
                tmp = new Gradient(Type.Horizontal);
                break;

            case "ogradient":
                tmp = new Gradient(Type.Oblic);
                break;

            default:
                throw new Exception("Unknown gradient type: " + stops [0]);
            }

            for (int i = 1; i < stops.Length; i++)
            {
                tmp.Stops.Add((ColorStop)ColorStop.Parse(stops[i]));
            }

            return(tmp);
        }