Esempio n. 1
0
 private static long SpeedSelector(ScreenUnit screenUnit)
 {
     if (screenUnit.MouseFinishedCount == 0)
     {
         return(0);
     }
     return((long)Math.Pow(screenUnit.SpeedCount / screenUnit.MouseFinishedCount, 0.5));
 }
Esempio n. 2
0
        /// <summary>
        /// Convert a value from a screen unit to another one (ex: 1cm => 37.7953px)
        /// </summary>
        /// <param name="from">Start unit</param>
        /// <param name="to">End unit</param>
        /// <param name="value">The value to convert (using start unit)</param>
        /// <returns>Returns the result of the conversion</returns>
        public static float Convert(ScreenUnit from, ScreenUnit to, float value)
        {
            if (from == to)
            {
                return(value);
            }

            switch (from)
            {
            case ScreenUnit.Pixel:
                if (to == ScreenUnit.Centimeter)
                {
                    return(value / PixelToCentimeterRatio);
                }

                if (to == ScreenUnit.Inch)
                {
                    return(value / PixelToInchRatio);
                }

                if (to == ScreenUnit.EffectivePixel)
                {
                    return(value / (float)DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel);
                }

                throw new ArgumentOutOfRangeException(nameof(to));

            case ScreenUnit.Centimeter:
                if (to == ScreenUnit.Pixel)
                {
                    return(value * PixelToCentimeterRatio);
                }

                if (to == ScreenUnit.Inch)
                {
                    return(value / CentimeterToInchRatio);
                }

                throw new ArgumentOutOfRangeException(nameof(to));

            case ScreenUnit.Inch:
                if (to == ScreenUnit.Pixel)
                {
                    return(value * PixelToInchRatio);
                }

                if (to == ScreenUnit.Centimeter)
                {
                    return(value * CentimeterToInchRatio);
                }

                throw new ArgumentOutOfRangeException(nameof(to));

            case ScreenUnit.EffectivePixel:
                if (to == ScreenUnit.Pixel)
                {
                    return(value * (float)DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel);
                }

                throw new ArgumentOutOfRangeException(nameof(to));

            default:
                throw new ArgumentOutOfRangeException(nameof(from));
            }
        }
Esempio n. 3
0
 private static long MousePassedSelector(ScreenUnit screenUnit) =>
 (long)Math.Pow(screenUnit.MousePassedCount, 0.5);
        /// <summary>
        /// Converts a screen unit to another screen unit (ex: 1cm => 37.7953px).
        /// </summary>
        /// <param name="from">Start unit</param>
        /// <param name="to">End unit</param>
        /// <param name="value">The value to convert (using start unit)</param>
        /// <param name="xamlRoot">The XamlRoot that will be used to get the screen scale. Required on Xaml Islands.</param>
        /// <returns>The result of the conversion</returns>
        public static float Convert(ScreenUnit from, ScreenUnit to, float value, XamlRoot xamlRoot = null)
        {
            if (from == to)
            {
                return(value);
            }

            switch (from)
            {
            case ScreenUnit.Pixel:
                if (to == ScreenUnit.Centimeter)
                {
                    return(value / PixelToCentimeterRatio);
                }

                if (to == ScreenUnit.Inch)
                {
                    return(value / PixelToInchRatio);
                }

                if (to == ScreenUnit.EffectivePixel)
                {
                    return(value / GetScale(xamlRoot));
                }

                throw new ArgumentOutOfRangeException(nameof(to));

            case ScreenUnit.Centimeter:
                if (to == ScreenUnit.Pixel)
                {
                    return(value * PixelToCentimeterRatio);
                }

                if (to == ScreenUnit.Inch)
                {
                    return(value / CentimeterToInchRatio);
                }

                throw new ArgumentOutOfRangeException(nameof(to));

            case ScreenUnit.Inch:
                if (to == ScreenUnit.Pixel)
                {
                    return(value * PixelToInchRatio);
                }

                if (to == ScreenUnit.Centimeter)
                {
                    return(value * CentimeterToInchRatio);
                }

                throw new ArgumentOutOfRangeException(nameof(to));

            case ScreenUnit.EffectivePixel:
                if (to == ScreenUnit.Pixel)
                {
                    return(value * GetScale(xamlRoot));
                }

                throw new ArgumentOutOfRangeException(nameof(to));

            default:
                throw new ArgumentOutOfRangeException(nameof(from));
            }
        }