-
Notifications
You must be signed in to change notification settings - Fork 399
/
DisplayMode.cs
64 lines (52 loc) · 2.29 KB
/
DisplayMode.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Drawing;
namespace osu.Framework.Platform
{
/// <summary>
/// Represents a display mode on a given <see cref="Display"/>.
/// </summary>
public readonly struct DisplayMode : IEquatable<DisplayMode>
{
/// <summary>
/// The pixel format of the display mode, if available.
/// </summary>
public readonly string Format;
/// <summary>
/// The dimensions of the screen resolution in pixels.
/// </summary>
public readonly Size Size;
/// <summary>
/// The number of bits that represent the colour value for each pixel.
/// </summary>
public readonly int BitsPerPixel;
/// <summary>
/// The refresh rate in hertz.
/// </summary>
public readonly float RefreshRate;
/// <summary>
/// The index of the display this mode belongs to as determined by the windowing backend.
/// </summary>
public readonly int DisplayIndex;
public DisplayMode(string? format, Size size, int bitsPerPixel, float refreshRate, int displayIndex)
{
Format = format ?? "Unknown";
Size = size;
BitsPerPixel = bitsPerPixel;
RefreshRate = refreshRate;
DisplayIndex = displayIndex;
}
public override string ToString() => $"Size: {Size}, BitsPerPixel: {BitsPerPixel}, RefreshRate: {RefreshRate}, Format: {Format}, DisplayIndex: {DisplayIndex}";
public bool Equals(DisplayMode other) =>
Format == other.Format
&& Size == other.Size
&& BitsPerPixel == other.BitsPerPixel
&& RefreshRate == other.RefreshRate
&& DisplayIndex == other.DisplayIndex;
public static bool operator ==(DisplayMode left, DisplayMode right) => left.Equals(right);
public static bool operator !=(DisplayMode left, DisplayMode right) => !(left == right);
public override bool Equals(object? obj) => obj is DisplayMode other && Equals(other);
public override int GetHashCode() => HashCode.Combine(Format, Size, BitsPerPixel, RefreshRate, DisplayIndex);
}
}