File: display.cpp

package info (click to toggle)
openmw 0.50.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,076 kB
  • sloc: cpp: 380,958; xml: 2,192; sh: 1,449; python: 911; makefile: 26; javascript: 5
file content (81 lines) | stat: -rw-r--r-- 2,269 bytes parent folder | download
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "display.hpp"

#include <format>
#include <numeric>
#include <string>

namespace Misc
{
    std::string getResolutionText(int x, int y)
    {
        int gcd = std::gcd(x, y);
        if (gcd == 0)
            return std::string();

        int xaspect = x / gcd;
        int yaspect = y / gcd;

        // It is unclear how to handle 90-degree screen rotation properly.
        // So far only swap aspects, apply custom formatting logic and then swap back.
        // As result, 1920 x 1200 is displayed as "1200 x 1920 (10:16)"
        bool flipped = false;
        if (yaspect > xaspect)
        {
            flipped = true;
            std::swap(xaspect, yaspect);
        }

        // 683:384 (used in 1366 x 768) is usually referred as 16:9
        if (xaspect == 683 && yaspect == 384)
        {
            xaspect = 16;
            yaspect = 9;
        }
        // 85:48 (used in 1360 x 768) is usually referred as 16:9
        else if (xaspect == 85 && yaspect == 48)
        {
            xaspect = 16;
            yaspect = 9;
        }
        // 49:36 (used in 1176 x 864) is usually referred as 4:3
        else if (xaspect == 49 && yaspect == 36)
        {
            xaspect = 4;
            yaspect = 3;
        }
        // 39:29 (used in 624 x 484) is usually referred as 4:3
        else if (xaspect == 39 && yaspect == 29)
        {
            xaspect = 4;
            yaspect = 3;
        }
        // 8:5 (used in 1440 x 900) is usually referred as 16:10
        else if (xaspect == 8 && yaspect == 5)
        {
            xaspect = 16;
            yaspect = 10;
        }
        // 5:3 (used in 1280 x 768) is usually referred as 15:9
        else if (xaspect == 5 && yaspect == 3)
        {
            xaspect = 15;
            yaspect = 9;
        }
        else
        {
            // everything between 21:9 and 22:9
            // is usually referred as 21:9
            float ratio = static_cast<float>(xaspect) / yaspect;
            if (ratio >= 21 / 9.f && ratio < 22 / 9.f)
            {
                xaspect = 21;
                yaspect = 9;
            }
        }

        if (flipped)
            std::swap(xaspect, yaspect);

        return std::format("{} × {} ({}:{})", x, y, xaspect, yaspect);
    }
}