Пример #1
0
        public static Size ParseSize(string s, FileSourceInfo src)
        {
            s = s.Trim('f');

            Uno.UX.Unit unit = Uno.UX.Unit.Unspecified;
            if (s.EndsWith("%"))
            {
                unit = Uno.UX.Unit.Percent;
                s    = s.Trim('%');
            }
            else if (s.EndsWith("px"))
            {
                unit = Uno.UX.Unit.Pixels;
                s    = s.Substring(0, s.Length - 2);
            }
            else if (s.EndsWith("pt"))
            {
                unit = Uno.UX.Unit.Points;
                s    = s.Substring(0, s.Length - 2);
            }

            var d = double.Parse(s, System.Globalization.CultureInfo.InvariantCulture);

            return(new Size((float)(dynamic)d, unit.ToString(), src));
        }
Пример #2
0
        public static Scalar <T> ParseFloat <T>(string s, FileSourceInfo src) where T : IFormattable
        {
            s = s.Trim('f');
            var d = double.Parse(s, System.Globalization.CultureInfo.InvariantCulture);

            return(new Scalar <T>((T)(dynamic)d, src));
        }
Пример #3
0
        public static Scalar <T> ParseInteger <T>(string s, Func <string, T> parser, FileSourceInfo src) where T : IFormattable
        {
            // TODO: tackle other integer encodings + postfixes

            var value = parser(s);

            return(new Scalar <T>(value, src));
        }
Пример #4
0
        public static Size2 ParseSize2(string s, FileSourceInfo src)
        {
            var p    = s.Split(',');
            var data = p.Select(x => ParseSize(x, src)).ToArray();

            if (data.Length != 2)
            {
                data = AutoExpandVector(data, 2);

                if (data.Length != 2)
                {
                    throw new Exception("Unexpected component count in Size vector, expected " + 2 + " found " + p.Length);
                }
            }

            return(new Size2(data[0], data[1], src));
        }
Пример #5
0
        public static Vector <T> ParseFloatVector <T>(string s, int comps, FileSourceInfo src) where T : IFormattable
        {
            s = s.Trim();
            if (s.StartsWith("#"))
            {
                return(ParseHexVector <T>(s, comps, src));
            }

            var p    = s.Split(',');
            var data = p.Select(x => ParseFloat <T>(x, src)).ToArray();

            if (data.Length != comps)
            {
                data = AutoExpandVector(data, comps);

                if (data.Length != comps)
                {
                    throw new Exception("Unexpected component count in float vector, expected " + comps + " found " + p.Length);
                }
            }

            return(new Vector <T>(data, src));
        }
Пример #6
0
        static Scalar <T> ParseHex <T>(string digit, FileSourceInfo src) where T : IFormattable
        {
            uint res;

            if (!uint.TryParse(digit, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out res))
            {
                throw new Exception("Unrecognized hex digit: " + digit);
            }

            if (IsIntegralType(typeof(T)))
            {
                return(new Scalar <T>((T)(dynamic)res, src));
            }
            else
            {
                double ratio = (double)0xF;
                if (digit.Length == 2)
                {
                    ratio = (double)0xFF;
                }

                return(new Scalar <T>((T)(dynamic)((double)res / ratio), src));
            }
        }
Пример #7
0
        public static Vector <T> ParseHexVector <T>(string s, int comps, FileSourceInfo src) where T : IFormattable
        {
            s = s.Trim('#');

            if (comps == 3)
            {
                switch (s.Length)
                {
                case 3:
                    return(new Vector <T>(s.Select(x => ParseHex <T>(new string(x, 1), src)).ToArray(), src));

                case 6:
                    var parts = new List <string>();
                    for (int i = 0; i < s.Length; i += 2)
                    {
                        parts.Add(s.Substring(i, 2));
                    }
                    return(new Vector <T>(parts.Select(x => ParseHex <T>(x, src)).ToArray(), src));

                default:
                    throw new Exception("Invalid hex-code for 3-component vector, expected 3 or 6 digits");
                }
            }
            else if (comps == 4)
            {
                switch (s.Length)
                {
                case 3:
                    return(new Vector <T>((s + "f").Select(x => ParseHex <T>(new string(x, 1), src)).ToArray(), src));

                case 4:
                    return(new Vector <T>(s.Select(x => ParseHex <T>(new string(x, 1), src)).ToArray(), src));

                case 6:
                {
                    s += "ff";
                    var parts = new List <string>();
                    for (int i = 0; i < s.Length; i += 2)
                    {
                        parts.Add(s.Substring(i, 2));
                    }
                    return(new Vector <T>(parts.Select(x => ParseHex <T>(x, src)).ToArray(), src));
                }

                case 8:
                {
                    var parts = new List <string>();
                    for (int i = 0; i < s.Length; i += 2)
                    {
                        parts.Add(s.Substring(i, 2));
                    }
                    return(new Vector <T>(parts.Select(x => ParseHex <T>(x, src)).ToArray(), src));
                }

                default:
                    throw new Exception("Invalid hex-code for 4-component vector, expected 3, 4, 6 or 8 digits");
                }
            }
            else
            {
                throw new Exception(comps + "-component vector cannot be encoded as hex value");
            }
        }
Пример #8
0
 protected Scalar(FileSourceInfo sourceInfo) : base(sourceInfo)
 {
 }
Пример #9
0
 protected ScalarBase(T value, FileSourceInfo srcInfo)
     : base(srcInfo)
 {
     Value = value;
 }
Пример #10
0
 public Bool(bool b, FileSourceInfo srcInfo) : base(srcInfo)
 {
     Value = b;
 }
Пример #11
0
 public String(string s, FileSourceInfo srcInfo)
     : base(srcInfo)
 {
     Value = s;
 }
Пример #12
0
 public Vector(Scalar <T>[] comps, FileSourceInfo srcInfo)
     : base(srcInfo)
 {
     _comps = comps;
 }
Пример #13
0
 public Size2(Size x, Size y, FileSourceInfo srcInfo) : base(srcInfo)
 {
     X = x;
     Y = y;
 }
Пример #14
0
 public Selector(string value, FileSourceInfo srcInfo) : base(srcInfo)
 {
     Value = value;
 }
Пример #15
0
 protected AtomicValue(FileSourceInfo source)
 {
     Source = source;
 }
Пример #16
0
 public Size(float value, string unit, FileSourceInfo srcInfo) : base(srcInfo)
 {
     Value = value;
     Unit  = unit;
 }