Beispiel #1
0
        public Dimension(TypedValue val) : this()
        {
            if (val.Type != DataType.Dimension)
            {
                throw new ArgumentException("Wrong type: " + val.Type);
            }

            ComplexUnitType unit = (ComplexUnitType)((val.Data >> (int)ComplexUnitType.Shift) & (int)ComplexUnitType.Mask);

            switch (unit)
            {
            case ComplexUnitType.Dip:
                this.Unit = DimensionUnit.Dp;
                break;

            case ComplexUnitType.Sp:
                this.Unit = DimensionUnit.Sp;
                break;

            case ComplexUnitType.Px:
                this.Unit = DimensionUnit.Px;
                break;

            case ComplexUnitType.In:
                this.Unit = DimensionUnit.In;
                break;

            case ComplexUnitType.Mm:
                this.Unit = DimensionUnit.Mm;
                break;

            case ComplexUnitType.Pt:
                this.Unit = DimensionUnit.Pt;
                break;

            default:
                throw new Exception("Unexpected: " + (int)unit);
            }

            this.Value = TypedValue.ComplexToFloat(val.Data);
        }