-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResolution.cs
More file actions
58 lines (49 loc) · 1.61 KB
/
Resolution.cs
File metadata and controls
58 lines (49 loc) · 1.61 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
namespace Hopeful;
public readonly struct Resolution
{
public int Width { get; }
public int Height { get; }
public float AspectRatio => (float)Width / Height;
private Resolution(int width, int height)
{
Width = width;
Height = height;
}
public static readonly Resolution HD = new(1280, 720); // 720p
public static readonly Resolution FullHD = new(1920, 1080); // 1080p
public static readonly Resolution QHD = new(2560, 1440); // 1440p
public static readonly Resolution UHD = new(3840, 2160); // 4K
// 4:3
public static readonly Resolution R_1024x768 = new(1024, 768);
public static readonly Resolution R_1280x960 = new(1280, 960);
public static readonly Resolution R_1600x1200 = new(1600, 1200);
// 16:9
public static readonly Resolution R_1366x768 = new(1366, 768);
public static readonly Resolution R_1600x900 = new(1600, 900);
public static IReadOnlyList<Resolution> GetAvailableResolutions()
{
return new[]
{
HD,
FullHD,
QHD,
UHD,
R_1024x768,
R_1280x960,
R_1600x1200,
R_1366x768,
R_1600x900
}.OrderBy(r => r.Width * r.Height).ToList();
}
public static Resolution GetNearestResolution(int width, int height)
{
var targetPixels = width * height;
return GetAvailableResolutions()
.OrderBy(r => Math.Abs(r.Width * r.Height - targetPixels))
.First();
}
public override string ToString() => $"{Width}x{Height}";
}