// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using System.Drawing; using System.Linq; namespace osu.Framework.Platform { /// /// Represents a physical display device on the current system. /// public sealed class Display : IEquatable { /// /// The name of the display, if available. Usually the manufacturer. /// public string Name { get; } /// /// The current rectangle of the display in screen space. /// Non-zero X and Y values represent a non-primary monitor, and indicate its position /// relative to the primary monitor. /// public Rectangle Bounds { get; } /// /// The available s on this display. /// public DisplayMode[] DisplayModes { get; } /// /// The zero-based index of the . /// public int Index { get; } public Display(int index, string name, Rectangle bounds, DisplayMode[] displayModes) { Index = index; Name = name; Bounds = bounds; DisplayModes = displayModes; } public override string ToString() => $"Name: {Name ?? "Unknown"}, Bounds: {Bounds}, DisplayModes: {DisplayModes.Length}"; public bool Equals(Display other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return Index == other.Index; } /// /// Attempts to find a for the given that /// closely matches the requested parameters. /// /// The to match. /// The bits per pixel to match. If null, the highest available bits per pixel will be used. /// The refresh rate in hertz. If null, the highest available refresh rate will be used. public DisplayMode FindDisplayMode(Size size, int? bitsPerPixel = null, int? refreshRate = null) => DisplayModes.Where(mode => mode.Size.Width <= size.Width && mode.Size.Height <= size.Height && (bitsPerPixel == null || mode.BitsPerPixel == bitsPerPixel) && (refreshRate == null || mode.RefreshRate == refreshRate)) .OrderByDescending(mode => mode.Size.Width) .ThenByDescending(mode => mode.Size.Height) .ThenByDescending(mode => mode.RefreshRate) .ThenByDescending(mode => mode.BitsPerPixel) .FirstOrDefault(); } }