Ejemplo n.º 1
0
        /// <summary>
        /// Finds the best set of DPI values to use when loading the font for the specified density bucket.
        /// </summary>
        private static void GetBestScreenDensityMatch(UltravioletContext uv, ScreenDensityBucket bucket, out Single dpiX, out Single dpiY)
        {
            dpiX = 96f;
            dpiY = 96f;

            var bestMatchFound = false;
            var bestMatchScale = Single.MaxValue;

            foreach (var display in uv.GetPlatform().Displays)
            {
                if (display.DensityBucket == bucket)
                {
                    if (display.DensityScale < bestMatchScale)
                    {
                        bestMatchFound = true;
                        bestMatchScale = display.DensityScale;
                        dpiX           = display.DpiX;
                        dpiY           = display.DpiY;
                    }
                }
            }

            if (bestMatchFound)
            {
                return;
            }

            dpiX = dpiY = ScreenDensityService.GuessDensityFromBucket(bucket);
        }
        /// <summary>
        /// Initializes a new instance of the OpenGLUltravioletDisplay class.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <param name="displayIndex">The SDL2 display index that this object represents.</param>
        public SDL2UltravioletDisplay(UltravioletContext uv, Int32 displayIndex)
        {
            Contract.Require(uv, nameof(uv));

            this.uv = uv;

            this.displayIndex = displayIndex;
            this.displayModes = Enumerable.Range(0, SDL_GetNumDisplayModes(displayIndex))
                                .Select(modeIndex => CreateDisplayModeFromSDL(displayIndex, modeIndex))
                                .ToList();

            this.name = SDL_GetDisplayName(displayIndex);

            SDL_DisplayMode sdlDesktopDisplayMode;

            if (SDL_GetDesktopDisplayMode(displayIndex, &sdlDesktopDisplayMode) < 0)
            {
                throw new SDL2Exception();
            }

            this.desktopDisplayMode = CreateDisplayModeFromSDL(sdlDesktopDisplayMode);

            this.screenRotationService = ScreenRotationService.Create(this);
            this.screenDensityService  = ScreenDensityService.Create(this);
        }
        /// <summary>
        /// Initializes a new instance of the OpenGLUltravioletDisplay class.
        /// </summary>
        /// <param name="displayIndex">The SDL2 display index that this object represents.</param>
        public OpenGLUltravioletDisplay(Int32 displayIndex)
        {
            this.displayIndex = displayIndex;
            this.displayModes = Enumerable.Range(0, SDL.GetNumDisplayModes(displayIndex))
                                .Select(modeIndex => CreateDisplayModeFromSDL(displayIndex, modeIndex))
                                .ToList();

            this.name = SDL.GetDisplayName(displayIndex);

            SDL_DisplayMode sdlDesktopDisplayMode;

            if (SDL.GetDesktopDisplayMode(displayIndex, &sdlDesktopDisplayMode) < 0)
            {
                throw new SDL2Exception();
            }

            this.desktopDisplayMode = CreateDisplayModeFromSDL(sdlDesktopDisplayMode);

            this.screenRotationService = ScreenRotationService.Create(this);
            this.screenDensityService  = ScreenDensityService.Create(this);
        }