Пример #1
0
        /// <summary>Converts all percentage and enum values to point equivalent.</summary>
        /// <param name="fullWidth">container width to calculate percentage.</param>
        /// <param name="fullHeight">container height to calculate percentage.</param>
        /// <param name="outXValue">
        ///
        /// <see cref="UnitValue"/>
        /// to store processed xPosition.
        /// </param>
        /// <param name="outYValue">
        ///
        /// <see cref="UnitValue"/>
        /// to store processed yPosition.
        /// </param>
        public virtual void CalculatePositionValues(float fullWidth, float fullHeight, UnitValue outXValue, UnitValue
                                                    outYValue)
        {
            int posMultiplier = ParsePositionXToUnitValueAndReturnMultiplier(outXValue);

            if (posMultiplier == 0 && xShift != null && Math.Abs(xShift.GetValue()) > EPS)
            {
                outXValue.SetValue(0);
            }
            else
            {
                outXValue.SetValue(CalculateValue(outXValue, fullWidth) + CalculateValue(xShift, fullWidth) * posMultiplier
                                   );
            }
            outXValue.SetUnitType(UnitValue.POINT);
            posMultiplier = ParsePositionYToUnitValueAndReturnMultiplier(outYValue);
            if (posMultiplier == 0 && yShift != null && Math.Abs(yShift.GetValue()) > EPS)
            {
                outYValue.SetValue(0);
            }
            else
            {
                outYValue.SetValue(CalculateValue(outYValue, fullHeight) + CalculateValue(yShift, fullHeight) * posMultiplier
                                   );
            }
            outYValue.SetUnitType(UnitValue.POINT);
        }
Пример #2
0
        /// <summary>
        /// Parses positionY to
        /// <see cref="UnitValue"/>.
        /// </summary>
        /// <param name="outValue">
        ///
        /// <see cref="UnitValue"/>
        /// in which positionY will be parsed
        /// </param>
        /// <returns>multiplier by which the yShift will be multiplied</returns>
        private int ParsePositionYToUnitValueAndReturnMultiplier(UnitValue outValue)
        {
            outValue.SetUnitType(UnitValue.PERCENT);
            switch (positionY)
            {
            case BackgroundPosition.PositionY.TOP: {
                outValue.SetValue(0);
                return(1);
            }

            case BackgroundPosition.PositionY.BOTTOM: {
                outValue.SetValue(FULL_VALUE);
                return(-1);
            }

            case BackgroundPosition.PositionY.CENTER: {
                outValue.SetValue(HALF_VALUE);
                return(0);
            }

            default: {
                return(0);
            }
            }
        }