Etterna 0.74.4
Loading...
Searching...
No Matches
DisplaySpec.h
1#ifndef DisplaySpec_H
2#define DisplaySpec_H
3
4#include "Core/Services/Locator.hpp"
5#include "RageUtil/Misc/RageTypes.h"
6
7#include <set>
8#include <sstream>
9#include <algorithm>
10
12{
13 // Width (in pixels) of the display in this mode
14 unsigned int width;
15 // Height (in pixels) of the display in this mode
16 unsigned int height;
23 /*
24 * Bits-per-pixel is *not* a property of the DisplayMode for our purposes:
25 * bit-depth is going to be a property of the OpenGL/D3D context, not a
26 * display configuration
27 */
28
29 auto operator<(const DisplayMode& other) const -> bool
30 {
32#define COMPARE(x) \
33 if ((x) != other.x) \
34 return (x) < other.x;
35 COMPARE(width);
36 COMPARE(height);
37 COMPARE(refreshRate);
38#undef COMPARE
39 return false;
40 }
41
42 // Lua
43 void PushSelf(lua_State* L);
44};
45
48{
49 public:
50 /*
51 * Construct a specification for the display with the given ID, which
52 * supports the given modes, and is currently using the specified mode with
53 * the specified logical screen bounds
54 */
55 DisplaySpec(std::string id,
56 std::string name,
57 const std::set<DisplayMode>& modes,
58 const DisplayMode& curMode,
59 const RectI& curBounds,
60 const bool isVirtual = false)
61 : m_sId(std::move(id))
62 , m_sName(std::move(name))
63 , m_sModes(modes)
64 , m_bCurModeActive(true)
65 , m_CurMode(curMode)
66 , m_rectBounds(curBounds)
67 , m_bIsVirtual(isVirtual)
68 {
69 if (m_sModes.find(curMode) == m_sModes.end()) {
70 // This is an error, make a failing assertion with a descriptive
71 // error message
72 std::stringstream msgStream;
73 msgStream << "DisplaySpec current mode (" << curMode.width << "x"
74 << curMode.height << "@" << curMode.refreshRate
75 << ") not in given list of supported modes: ";
76 for (const auto& m : modes) {
77 msgStream << m.width << "x" << m.height << "@" << m.refreshRate
78 << ", ";
79 }
80 auto msg = msgStream.str();
81 // Drop the trailing ", "
82 msg.resize(msg.size() - 2);
83
84 Locator::getLogger()->warn("{}", msg.c_str());
85 }
86 }
87
88 /*
89 * Construct a specification for the display with the given ID, which
90 * supports the given modes, and is currently disabled (has no active mode)
91 */
92 DisplaySpec(const std::string& id,
93 const std::string& name,
94 const std::set<DisplayMode>& modes,
95 const bool isVirtual = false)
96 : m_sId(id)
97 , m_sName(name)
98 , m_sModes(modes)
99 , m_bCurModeActive(false)
100 , m_CurMode({})
101 , m_bIsVirtual(isVirtual)
102 {
103 }
104
105 // Create a specification for a display supporting a single (and currently
106 // active) mode
107 DisplaySpec(std::string id, std::string name, DisplayMode mode)
108 : m_sId(std::move(std::move(id)))
109 , m_sName(std::move(std::move(name)))
110 , m_bCurModeActive(true)
111 , m_CurMode(mode)
112 , m_bIsVirtual(false)
113 {
114 m_sModes.insert(mode);
115 m_rectBounds = RectI(0, 0, mode.width, mode.height);
116 }
117
118 DisplaySpec(const DisplaySpec& other) = default;
119
120 [[nodiscard]] auto name() const -> std::string { return m_sName; }
121
122 [[nodiscard]] auto id() const -> std::string { return m_sId; }
123
124 [[nodiscard]] auto supportedModes() const -> const std::set<DisplayMode>&
125 {
126 return m_sModes;
127 }
128
129 /*
130 * Return a pointer to the currently active display mode, or NULL if
131 * display is inactive
132 *
133 * Note that inactive *does not* necessarily mean unusable. E.g., in X11,
134 * an output can be enabled/disabled by an application by
135 * connecting/disconnecting a crtc
136 */
137 [[nodiscard]] auto currentMode() const -> const DisplayMode*
138 {
139 return m_bCurModeActive ? &m_CurMode : nullptr;
140 }
141
142 [[nodiscard]] auto currentBounds() const -> const RectI&
143 {
144 return m_rectBounds;
145 }
146
147 [[nodiscard]] auto isVirtual() const -> bool { return m_bIsVirtual; }
148
158 auto operator<(const DisplaySpec& other) const -> bool
159 {
160 return m_sId < other.id();
161 }
162
163 // Lua
164 void PushSelf(lua_State* L);
165
166 private:
167 // Unique identifier of the display
168 std::string m_sId;
169 // "Human-readable" display name
170 std::string m_sName;
171 // Modes supported by this display
172 std::set<DisplayMode> m_sModes;
173 // currently configured mode, if available
174 bool m_bCurModeActive;
175 DisplayMode m_CurMode;
176 // The current bounds of this display in global display coordinate space
177 RectI m_rectBounds;
178 // Flag is "true" when display represents a logical display like an X screen
179 // or the Win32 "Virtual screen"
180 bool m_bIsVirtual;
181};
183typedef std::set<DisplaySpec> DisplaySpecs;
184// Lua
185auto
186pushDisplaySpecs(lua_State* L, const DisplaySpecs& specs) -> DisplaySpecs*;
187
188#endif
The dimensions of the program.
Definition DisplaySpec.h:48
auto operator<(const DisplaySpec &other) const -> bool
Determine if one DisplaySpec compares less than the other.
Definition DisplaySpec.h:158
Definition DisplaySpec.h:12
auto operator<(const DisplayMode &other) const -> bool
Definition DisplaySpec.h:29
double refreshRate
Definition DisplaySpec.h:22