/// <summary>
        /// Initializes a new instance of the <see cref="NETCore3ScreenDensityService"/> class.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <param name="display">The <see cref="IUltravioletDisplay"/> for which to retrieve density information.</param>
        public NETCore3ScreenDensityService(UltravioletContext uv, IUltravioletDisplay display)
            : base(display)
        {
            Contract.Require(uv, nameof(uv));

            Refresh();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="macOSModernScreenDensityService"/> class.
        /// </summary>
        /// <param name="display">The <see cref="IUltravioletDisplay"/> for which to retrieve density information.</param>
        public macOSModernScreenDensityService(IUltravioletDisplay display)
            : base(display)
        {
            this.display = display;

            Refresh();
        }
Example #3
0
        /// <summary>
        /// Retrieves DPI information when running on Windows 8.1 and higher.
        /// </summary>
        private Boolean InitWindows8_1(UltravioletContext uv, IUltravioletDisplay display)
        {
            if (uv.Platform != UltravioletPlatform.Windows || Environment.OSVersion.Version < new Version(6, 3))
            {
                return(false);
            }

            var hmonitor = IntPtr.Zero;
            var rect     = new Native.Win32.RECT {
                left = display.Bounds.Left, top = display.Bounds.Top, right = display.Bounds.Right, bottom = display.Bounds.Bottom
            };

            unsafe
            {
                Native.Win32.EnumDisplayMonitors(IntPtr.Zero, &rect, (hdc, lprcClip, lprcMonitor, dwData) =>
                {
                    hmonitor = hdc;
                    return(false);
                }, IntPtr.Zero);
            }

            if (hmonitor == IntPtr.Zero)
            {
                return(false);
            }

            Native.Win32.GetDpiForMonitor(hmonitor, 0, out var x, out var y);

            this.densityX      = x;
            this.densityY      = y;
            this.densityScale  = x / 96f;
            this.densityBucket = GuessBucketFromDensityScale(densityScale);

            return(true);
        }
        /// <summary>
        /// Retrieves DPI information when running on Windows 8.1 and higher.
        /// </summary>
        private Boolean InitWindows8_1(UltravioletContext uv, IUltravioletDisplay display)
        {
            if (uv.Platform != UltravioletPlatform.Windows || Environment.OSVersion.Version < new Version(6, 3))
                return false;

            var rect = new Win32.RECT
            {
                left   = display.Bounds.Left,
                top    = display.Bounds.Top,
                right  = display.Bounds.Right,
                bottom = display.Bounds.Bottom 
            };

            var hmonitor = IntPtr.Zero;

            Win32.EnumDisplayMonitors(IntPtr.Zero, &rect, (hdc, lprcClip, lprcMonitor, dwData) =>
            {
                hmonitor = hdc;
                return false;
            }, IntPtr.Zero);

            if (hmonitor == IntPtr.Zero)
                return false;

            UInt32 x, y;
            Win32.GetDpiForMonitor(hmonitor, 0, out x, out y);

            this.densityX      = x;
            this.densityY      = y;
            this.densityScale  = x / 96f;
            this.densityBucket = GuessBucketFromDensityScale(densityScale);

            return true;
        }
Example #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NETCore2ScreenDensityService_Windows"/> class.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <param name="display">The <see cref="IUltravioletDisplay"/> for which to retrieve density information.</param>
        public NETCore2ScreenDensityService_Windows(UltravioletContext uv, IUltravioletDisplay display)
            : base(display)
        {
            Contract.Require(uv, nameof(uv));

            this.uv      = uv;
            this.display = display;

            Refresh();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="OSXScreenDensityService"/> class.
        /// </summary>
        /// <param name="display">The <see cref="IUltravioletDisplay"/> for which to retrieve density information.</param>
        public OSXScreenDensityService(IUltravioletDisplay display)
            : base(display)
        {
            var screen  = NSScreen.Screens[display.Index];
            var density = ((NSValue)screen.DeviceDescription["NSDeviceResolution"]).SizeFValue;

            this.densityScale = screen.BackingScaleFactor;
            this.densityX     = density.Width;
            this.densityY     = density.Height;
        }
		/// <summary>
		/// Initializes a new instance of the <see cref="OSXScreenDensityService"/> class.
		/// </summary>
		/// <param name="display">The <see cref="IUltravioletDisplay"/> for which to retrieve density information.</param>
		public OSXScreenDensityService(IUltravioletDisplay display)
			: base(display)
		{
			var screen  = NSScreen.Screens[display.Index];
			var density = ((NSValue)screen.DeviceDescription["NSDeviceResolution"]).SizeFValue;

			this.densityScale = screen.BackingScaleFactor;
			this.densityX     = density.Width;
			this.densityY     = density.Height;
		}
        /// <summary>
        /// Initializes a new instance of the <see cref="DesktopScreenDensityService"/> class.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <param name="display">The <see cref="IUltravioletDisplay"/> for which to retrieve density information.</param>
        public DesktopScreenDensityService(UltravioletContext uv, IUltravioletDisplay display)
            : base(display)
        {
            Contract.Require(uv, nameof(uv));

            this.uv      = uv;
            this.display = display;

            Refresh();
        }
 /// <summary>
 /// Retrieves DPI information in the general case.
 /// </summary>
 private Boolean InitFallback(UltravioletContext uv, IUltravioletDisplay display)
 {
     using (var graphics = System.Drawing.Graphics.FromHwnd(IntPtr.Zero))
     {
         this.densityX      = graphics.DpiX;
         this.densityY      = graphics.DpiY;
         this.densityScale  = graphics.DpiX / 96f;
         this.densityBucket = GuessBucketFromDensityScale(densityScale);
     }
     return(true);
 }
 /// <summary>
 /// Retrieves DPI information in the general case.
 /// </summary>
 private Boolean InitFallback(UltravioletContext uv, IUltravioletDisplay display)
 {
     using (var graphics = System.Drawing.Graphics.FromHwnd(IntPtr.Zero))
     {
         this.densityX = graphics.DpiX;
         this.densityY = graphics.DpiY;
         this.densityScale = graphics.DpiX / 96f;
         this.densityBucket = GuessBucketFromDensityScale(densityScale);
     }
     return true;
 }
        /// <summary>
        /// Converts a <see cref="Thickness"/> value with dimensions in inches to a <see cref="Thickness"/>
        /// value with dimensions in display independent pixels.
        /// </summary>
        /// <param name="this">The <see cref="IUltravioletDisplay"/> with which to perform the conversion.</param>
        /// <param name="inches">The <see cref="Thickness"/> in inches to convert.</param>
        /// <returns>The converted <see cref="Thickness"/> in display independent pixels.</returns>
        public static Thickness InchesToDips(this IUltravioletDisplay @this, Thickness inches)
        {
            Contract.Require(@this, "this");

            var left   = @this.InchesToDips(inches.Left);
            var top    = @this.InchesToDips(inches.Top);
            var right  = @this.InchesToDips(inches.Right);
            var bottom = @this.InchesToDips(inches.Bottom);

            return(new Thickness(left, top, right, bottom));
        }
        /// <summary>
        /// Retrieves DPI information on OS X when the Mac-specific compatibility shim is missing.
        /// </summary>
        private Boolean InitOSX(UltravioletContext uv, IUltravioletDisplay display)
        {
            if (uv.Platform != UltravioletPlatform.OSX)
                return false;

            this.densityX     = 72f;
            this.densityY     = 72f;
            this.densityScale = 1.0f;

            return true;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DesktopScreenDensityService"/> class.
        /// </summary>
        /// <param name="display">The <see cref="IUltravioletDisplay"/> for which to retrieve density information.</param>
        public DesktopScreenDensityService(UltravioletContext uv, IUltravioletDisplay display)
            : base(display)
        {
            if (InitWindows8_1(uv, display))
                return;

            if (InitOSX(uv, display))
                return;

            InitFallback(uv, display);
        }
        /// <summary>
        /// Converts a <see cref="Matrix"/> representing a 2D transformation in display independent pixels to an
        /// equivalent <see cref="Matrix"/> in display pixels.
        /// </summary>
        /// <param name="this">The <see cref="IUltravioletDisplay"/> with which to perform the conversion.</param>
        /// <param name="matrix">The <see cref="Matrix"/> in display independent pixels to convert.</param>
        /// <param name="result">The converted <see cref="Matrix"/> in display pixels.</param>
        public static void DipsToPixels(this IUltravioletDisplay @this, ref Matrix matrix, out Matrix result)
        {
            var x = (Single)@this.DipsToPixels(matrix.M14);
            var y = (Single)@this.DipsToPixels(matrix.M24);
            var z = (Single)@this.DipsToPixels(matrix.M34);

            result = new Matrix(
                matrix.M11, matrix.M12, matrix.M13, x,
                matrix.M21, matrix.M22, matrix.M23, y,
                matrix.M31, matrix.M32, matrix.M33, z,
                matrix.M41, matrix.M42, matrix.M43, matrix.M44);
        }
        /// <summary>
        /// Converts a <see cref="Matrix"/> representing a 2D transformation in display independent pixels to an
        /// equivalent <see cref="Matrix"/> in display pixels.
        /// </summary>
        /// <param name="this">The <see cref="IUltravioletDisplay"/> with which to perform the conversion.</param>
        /// <param name="matrix">The <see cref="Matrix"/> in display independent pixels to convert.</param>
        /// <returns>The converted <see cref="Matrix"/> in display pixels.</returns>
        public static Matrix DipsToPixels(this IUltravioletDisplay @this, Matrix matrix)
        {
            var x = (Single)@this.DipsToPixels(matrix.M14);
            var y = (Single)@this.DipsToPixels(matrix.M24);
            var z = (Single)@this.DipsToPixels(matrix.M34);

            return(new Matrix(
                       matrix.M11, matrix.M12, matrix.M13, x,
                       matrix.M21, matrix.M22, matrix.M23, y,
                       matrix.M31, matrix.M32, matrix.M33, z,
                       matrix.M41, matrix.M42, matrix.M43, matrix.M44));
        }
        /// <summary>
        /// Retrieves DPI information on OS X when the Mac-specific compatibility shim is missing.
        /// </summary>
        private Boolean InitOSX(UltravioletContext uv, IUltravioletDisplay display)
        {
            if (uv.Platform != UltravioletPlatform.OSX)
            {
                return(false);
            }

            this.densityX     = 96f;
            this.densityY     = 96f;
            this.densityScale = 1.0f;

            return(true);
        }
Example #17
0
 /// <summary>
 /// Resets the drawing context by clearing its render state stacks.
 /// </summary>
 /// <param name="display">The display on which the drawing context is rendering.</param>
 public void Reset(IUltravioletDisplay display)
 {
     this.display = display;
     this.opacityStack.Clear();
     this.clipStack.Clear();
     this.currentStencil    = null;
     this.transforms        = 0;
     this.outOfBand         = 0;
     this.localTransform    = Matrix.Identity;
     this.globalTransform   = Matrix.Identity;
     this.combinedTransform = Matrix.Identity;
     this.IsOutOfBandRenderingSuppressed = false;
 }
Example #18
0
 /// <summary>
 /// Resets the drawing context by clearing its render state stacks.
 /// </summary>
 /// <param name="display">The display on which the drawing context is rendering.</param>
 public void Reset(IUltravioletDisplay display)
 {
     this.display = display;
     this.opacityStack.Clear();
     this.clipStack.Clear();
     this.currentStencil = null;
     this.transforms = 0;
     this.outOfBand = 0;
     this.localTransform = Matrix.Identity;
     this.globalTransform = Matrix.Identity;
     this.combinedTransform = Matrix.Identity;
     this.IsOutOfBandRenderingSuppressed = false;
 }
        /// <inheritdoc/>
        public void ChangeDisplay(IUltravioletDisplay display)
        {
            Contract.EnsureNotDisposed(this, Disposed);
            Contract.Require(display, nameof(display));

            if (Display == display)
            {
                return;
            }

            var x = display.Bounds.Center.X - (ClientSize.Width / 2);
            var y = display.Bounds.Center.Y - (ClientSize.Height / 2);

            Position = new Point2(x, y);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DesktopScreenDensityService"/> class.
        /// </summary>
        /// <param name="display">The <see cref="IUltravioletDisplay"/> for which to retrieve density information.</param>
        public DesktopScreenDensityService(UltravioletContext uv, IUltravioletDisplay display)
            : base(display)
        {
            if (InitWindows8_1(uv, display))
            {
                return;
            }

            if (InitOSX(uv, display))
            {
                return;
            }

            InitFallback(uv, display);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="OSXScreenDensityService"/> class.
        /// </summary>
        /// <param name="display">The <see cref="IUltravioletDisplay"/> for which to retrieve density information.</param>
        public OSXScreenDensityService(IUltravioletDisplay display)
            : base(display)
        {
            var screen = NSScreen.Screens[display.Index];
            deviceScale = (Single)screen.BackingScaleFactor;

            var density = ((NSValue)screen.DeviceDescription["NSDeviceResolution"]).CGSizeValue;
            densityX = (Single)density.Width * (96f / 72f);
            densityY = (Single)density.Height * (96f / 72f);

            var displayIsScaled = !UltravioletContext.DemandCurrent().SupportsHighDensityDisplayModes;
            if (displayIsScaled)
            {
                densityX /= deviceScale;
                densityY /= deviceScale;
            }

            densityScale = densityX / 96f;
            densityBucket = GuessBucketFromDensityScale(densityScale);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="OSXScreenDensityService"/> class.
        /// </summary>
        /// <param name="display">The <see cref="IUltravioletDisplay"/> for which to retrieve density information.</param>
        public OSXScreenDensityService(IUltravioletDisplay display)
            : base(display)
        {
            var screen = NSScreen.Screens[display.Index];

            deviceScale = (Single)screen.BackingScaleFactor;

            var density = ((NSValue)screen.DeviceDescription["NSDeviceResolution"]).CGSizeValue;

            densityX = (Single)density.Width * (96f / 72f);
            densityY = (Single)density.Height * (96f / 72f);

            var displayIsScaled = !UltravioletContext.DemandCurrent().SupportsHighDensityDisplayModes;

            if (displayIsScaled)
            {
                densityX /= deviceScale;
                densityY /= deviceScale;
            }

            densityScale  = densityX / 96f;
            densityBucket = GuessBucketFromDensityScale(densityScale);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="OSXScreenOrientationService"/> class.
 /// </summary>
 /// <param name="display">The <see cref="IUltravioletDisplay"/> for which to retrieve rotation information.</param>
 public OSXScreenOrientationService(IUltravioletDisplay display)
     : base(display)
 {
 }
Example #24
0
        /// <summary>
        /// Creates a new instance of the <see cref="ScreenRotationService"/> class.
        /// </summary>
        /// <param name="display">The <see cref="IUltravioletDisplay"/> for which to retrieve rotation information.</param>
        /// <returns>The instance of <see cref="ScreenRotationService"/> that was created.</returns>
        public static ScreenRotationService Create(IUltravioletDisplay display)
        {
            var uv = UltravioletContext.DemandCurrent();

            return(uv.GetFactoryMethod <ScreenRotationServiceFactory>()(display));
        }
Example #25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ScreenRotationService"/> class.
 /// </summary>
 /// <param name="display">The <see cref="IUltravioletDisplay"/> for which to retrieve rotation information.</param>
 protected ScreenRotationService(IUltravioletDisplay display)
 {
     Contract.Require(display, nameof(display));
 }
Example #26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="macOSScreenOrientationService"/> class.
 /// </summary>
 /// <param name="display">The <see cref="IUltravioletDisplay"/> for which to retrieve rotation information.</param>
 public macOSScreenOrientationService(IUltravioletDisplay display)
     : base(display)
 {
 }
 /// <summary>
 /// Creates a new instance of the <see cref="ScreenDensityService"/> class.
 /// </summary>
 /// <param name="display">The <see cref="IUltravioletDisplay"/> for which 
 /// to retrieve a screen density service.</param>
 /// <returns>The instance of <see cref="ScreenDensityService"/> that was created.</returns>
 public static ScreenDensityService Create(IUltravioletDisplay display)
 {
     var uv = UltravioletContext.DemandCurrent();
     return uv.GetFactoryMethod<ScreenDensityServiceFactory>()(display);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AndroidScreenDensityService"/> class.
 /// </summary>
 /// <param name="display">The <see cref="IUltravioletDisplay"/> for which to retrieve density information.</param>
 public AndroidScreenDensityService(IUltravioletDisplay display)
     : base(display)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AndroidScreenRotationService"/> class.
 /// </summary>
 /// <param name="display">The <see cref="IUltravioletDisplay"/> for which to retrieve rotation information.</param>
 public AndroidScreenRotationService(IUltravioletDisplay display)
     : base(display)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ScreenDensityService"/> class.
 /// </summary>
 /// <param name="display">The <see cref="IUltravioletDisplay"/> for which to retrieve density information.</param>
 protected ScreenDensityService(IUltravioletDisplay display)
 {
     Contract.Require(display, nameof(display));
 }
Example #31
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NETCoreScreenOrientationService"/> class.
 /// </summary>
 /// <param name="display">The <see cref="IUltravioletDisplay"/> for which to retrieve rotation information.</param>
 public NETCoreScreenOrientationService(IUltravioletDisplay display)
     : base(display)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="iOSScreenRotationService"/> class.
 /// </summary>
 /// <param name="display">The <see cref="IUltravioletDisplay"/> for which to retrieve rotation information.</param>
 public iOSScreenRotationService(IUltravioletDisplay display)
     : base(display)
 {
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="iOSScreenDensityService"/> class.
        /// </summary>
        /// <param name="display">The <see cref="IUltravioletDisplay"/> for which to retrieve density information.</param>
        public unsafe iOSScreenDensityService(IUltravioletDisplay display)
            : base(display)
        {
            var buf = IntPtr.Zero;

            try
            {
                buf = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(UltravioletNative.utsname_darwin)));
                if (UltravioletNative.uname(buf) < 0)
                {
                    throw new InvalidOperationException(UltravioletStrings.UnableToRetrieveDeviceName);
                }

                var deviceInfo = Marshal.PtrToStructure <UltravioletNative.utsname_darwin>(buf);
                var deviceID   = deviceInfo.machine;

                deviceScale = (Single)UIScreen.MainScreen.Scale;

                switch (deviceID)
                {
                // Simulator
                case "i386":
                case "x86_64":
                    densityX = densityY = (Int32)(72 * deviceScale);
                    break;

                // iPod Touch 1st-3rd Gen
                case "iPod1,1":
                case "iPod2,1":
                case "iPod3,1":
                    densityX = densityY = 163;
                    break;

                // iPod Touch 4th-6th Gen
                case "iPod4,1":
                case "iPod5,1":
                case "iPod7,1":
                    densityX = densityY = 326;
                    break;

                // iPhone, 3G, 3GS
                case "iPhone1,1":
                case "iPhone1,2":
                case "iPhone2,1":
                    densityX = densityY = 163;
                    break;

                // iPhone 4-6, SE
                case "iPhone3,3":
                case "iPhone3,1":
                case "iPhone4,1":
                case "iPhone5,1":
                case "iPhone5,2":
                case "iPhone5,3":
                case "iPhone5,4":
                case "iPhone6,1":
                case "iPhone6,2":
                case "iPhone7,2":
                case "iPhone8,1":
                case "iPhone8,4":
                    densityX = densityY = 326;
                    break;

                // iPhone 6 Plus, 6S Plus
                case "iPhone7,1":
                case "iPhone8,2":
                    densityX = densityY = 401;
                    break;

                // iPad
                case "iPad1,1":
                case "iPad2,1":
                    densityX = densityY = 132;
                    break;

                // iPad 3rd Gen, iPad Air
                case "iPad3,1":
                case "iPad3,4":
                case "iPad4,1":
                case "iPad4,2":
                    densityX = densityY = 264;
                    break;

                // iPad Mini
                case "iPad2,5":
                    densityX = densityY = 163;
                    break;

                // iPad Mini 2, Mini 3, Mini 4
                case "iPad4,4":
                case "iPad4,5":
                case "iPad4,7":
                case "iPad5,1":
                case "iPad5,2":
                    densityX = densityY = 326;
                    break;

                // iPad Pro
                case "iPad6,3":
                case "iPad6,8":
                    densityX = densityY = 264;
                    break;

                // We don't know what this is so just blindly assume 326ppi
                default:
                    densityX = densityY = 326;
                    break;
                }

                densityX *= 96f / 72f;
                densityY *= 96f / 72f;

                var displayIsScaled = !UltravioletContext.DemandCurrent().SupportsHighDensityDisplayModes;
                if (displayIsScaled)
                {
                    densityX /= deviceScale;
                    densityY /= deviceScale;
                }

                densityScale  = densityX / 96f;
                densityBucket = GuessBucketFromDensityScale(densityScale);
            }
            finally
            {
                if (buf != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(buf);
                }
            }
        }
Example #34
0
        /// <summary>
        /// Initializes a new instance of the <see cref="iOSScreenDensityService"/> class.
        /// </summary>
        /// <param name="display">The <see cref="IUltravioletDisplay"/> for which to retrieve density information.</param>
        public unsafe iOSScreenDensityService(IUltravioletDisplay display)
            : base(display)
        {
            deviceScale = (Single)UIScreen.MainScreen.Scale;

            switch (UltravioletPlatformInfo.CurrentPlatformMachineHardwareName)
            {
            // Simulator
            case "i386":
            case "x86_64":
                densityX = densityY = (Int32)(72 * deviceScale);
                break;

            // iPod Touch 1st-3rd Gen
            case "iPod1,1":
            case "iPod2,1":
            case "iPod3,1":
                densityX = densityY = 163;
                break;

            // iPod Touch 4th-6th Gen
            case "iPod4,1":
            case "iPod5,1":
            case "iPod7,1":
                densityX = densityY = 326;
                break;

            // iPhone, 3G, 3GS
            case "iPhone1,1":
            case "iPhone1,2":
            case "iPhone2,1":
                densityX = densityY = 163;
                break;

            // iPhone 4-6, SE
            case "iPhone3,3":
            case "iPhone3,1":
            case "iPhone4,1":
            case "iPhone5,1":
            case "iPhone5,2":
            case "iPhone5,3":
            case "iPhone5,4":
            case "iPhone6,1":
            case "iPhone6,2":
            case "iPhone7,2":
            case "iPhone8,1":
            case "iPhone8,4":
                densityX = densityY = 326;
                break;

            // iPhone 6 Plus, 6S Plus
            case "iPhone7,1":
            case "iPhone8,2":
                densityX = densityY = 401;
                break;

            // iPad
            case "iPad1,1":
            case "iPad2,1":
                densityX = densityY = 132;
                break;

            // iPad 3rd Gen, iPad Air
            case "iPad3,1":
            case "iPad3,4":
            case "iPad4,1":
            case "iPad4,2":
                densityX = densityY = 264;
                break;

            // iPad Mini
            case "iPad2,5":
                densityX = densityY = 163;
                break;

            // iPad Mini 2, Mini 3, Mini 4
            case "iPad4,4":
            case "iPad4,5":
            case "iPad4,7":
            case "iPad5,1":
            case "iPad5,2":
                densityX = densityY = 326;
                break;

            // iPad Pro
            case "iPad6,3":
            case "iPad6,8":
                densityX = densityY = 264;
                break;

            // We don't know what this is so just blindly assume 326ppi
            default:
                densityX = densityY = 326;
                break;
            }

            densityX *= 96f / 72f;
            densityY *= 96f / 72f;

            var displayIsScaled = !UltravioletContext.DemandCurrent().Properties.SupportsHighDensityDisplayModes;

            if (displayIsScaled)
            {
                densityX /= deviceScale;
                densityY /= deviceScale;
            }

            densityScale  = densityX / 96f;
            densityBucket = GuessBucketFromDensityScale(densityScale);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AndroidScreenDensityService"/> class.
 /// </summary>
 /// <param name="display">The <see cref="IUltravioletDisplay"/> for which to retrieve density information.</param>
 public AndroidScreenDensityService(IUltravioletDisplay display)
     : base(display)
 {
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="iOSScreenDensityService"/> class.
        /// </summary>
        /// <param name="display">The <see cref="IUltravioletDisplay"/> for which to retrieve density information.</param>
        public unsafe iOSScreenDensityService(IUltravioletDisplay display)
            : base(display)
        {
            var buf = IntPtr.Zero;
            try
            {
                buf = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(UltravioletNative.utsname_darwin)));
                if (UltravioletNative.uname(buf) < 0)
                    throw new InvalidOperationException(UltravioletStrings.UnableToRetrieveDeviceName);

                var deviceInfo = Marshal.PtrToStructure<UltravioletNative.utsname_darwin>(buf);
                var deviceID = deviceInfo.machine;

                deviceScale = (Single)UIScreen.MainScreen.Scale;

                switch (deviceID)
                {
                    // Simulator
                    case "i386":
                    case "x86_64":
                        densityX = densityY = (Int32)(72 * deviceScale);
                        break;

                    // iPod Touch 1st-3rd Gen
                    case "iPod1,1":
                    case "iPod2,1":
                    case "iPod3,1":
                        densityX = densityY = 163;
                        break;

                    // iPod Touch 4th-6th Gen
                    case "iPod4,1":
                    case "iPod5,1":
                    case "iPod7,1":
                        densityX = densityY = 326;
                        break;

                    // iPhone, 3G, 3GS
                    case "iPhone1,1":
                    case "iPhone1,2":
                    case "iPhone2,1":
                        densityX = densityY = 163;
                        break;

                    // iPhone 4-6, SE
                    case "iPhone3,3":
                    case "iPhone3,1":
                    case "iPhone4,1":
                    case "iPhone5,1":
                    case "iPhone5,2":
                    case "iPhone5,3":
                    case "iPhone5,4":
                    case "iPhone6,1":
                    case "iPhone6,2":
                    case "iPhone7,2":
                    case "iPhone8,1":
                    case "iPhone8,4":
                        densityX = densityY = 326;
                        break;

                    // iPhone 6 Plus, 6S Plus
                    case "iPhone7,1":
                    case "iPhone8,2":
                        densityX = densityY = 401;
                        break;

                    // iPad
                    case "iPad1,1":
                    case "iPad2,1":
                        densityX = densityY = 132;
                        break;

                    // iPad 3rd Gen, iPad Air
                    case "iPad3,1":
                    case "iPad3,4":
                    case "iPad4,1":
                    case "iPad4,2":
                        densityX = densityY = 264;
                        break;

                    // iPad Mini
                    case "iPad2,5":
                        densityX = densityY = 163;
                        break;

                    // iPad Mini 2, Mini 3, Mini 4
                    case "iPad4,4":
                    case "iPad4,5":
                    case "iPad4,7":
                    case "iPad5,1":
                    case "iPad5,2":
                        densityX = densityY = 326;
                        break;

                    // iPad Pro
                    case "iPad6,3":
                    case "iPad6,8":
                        densityX = densityY = 264;
                        break;

                    // We don't know what this is so just blindly assume 326ppi
                    default:
                        densityX = densityY = 326;
                        break;
                }

                densityX *= 96f / 72f;
                densityY *= 96f / 72f;

                var displayIsScaled = !UltravioletContext.DemandCurrent().SupportsHighDensityDisplayModes;
                if (displayIsScaled)
                {
                    densityX /= deviceScale;
                    densityY /= deviceScale;
                }

                densityScale = densityX / 96f;
                densityBucket = GuessBucketFromDensityScale(densityScale);
            }
            finally
            {
                if (buf != IntPtr.Zero)
                    Marshal.FreeHGlobal(buf);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ScreenDensityService"/> class.
 /// </summary>
 /// <param name="display">The <see cref="IUltravioletDisplay"/> for which to retrieve density information.</param>
 protected ScreenDensityService(IUltravioletDisplay display)
 {
     Contract.Require(display, nameof(display));
 }
Example #38
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AndroidScreenDensityService"/> class.
 /// </summary>
 /// <param name="display">The <see cref="IUltravioletDisplay"/> for which to retrieve density information.</param>
 public AndroidScreenDensityService(IUltravioletDisplay display)
     : base(display)
 {
     EnsureMetrics();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DesktopScreenOrientationService"/> class.
 /// </summary>
 /// <param name="display">The <see cref="IUltravioletDisplay"/> for which to retrieve rotation information.</param>
 public DesktopScreenOrientationService(IUltravioletDisplay display)
     : base(display)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ScreenRotationService"/> class.
 /// </summary>
 /// <param name="display">The <see cref="IUltravioletDisplay"/> for which to retrieve rotation information.</param>
 protected ScreenRotationService(IUltravioletDisplay display)
 {
     Contract.Require(display, "display");
 }