Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [[nodiscard]] inline auto SDL::GetDisplays()
- {
- const auto validDisplayIndices = ranges::views::ints(0, SDL_GetNumVideoDisplays());
- constexpr auto fetchDisplayData = ranges::views::transform([](const int displayIndex) -> std::optional<Display> {
- Display::DPI dpi;
- if (SDL_GetDisplayDPI(displayIndex, &dpi.Diagonal, &dpi.Horizontal, &dpi.Vertical) != 0)
- return std::nullopt;
- SDL_Rect bounds;
- if (SDL_GetDisplayBounds(displayIndex, &bounds) != 0)
- return std::nullopt;
- SDL_DisplayMode mode;
- if (SDL_GetCurrentDisplayMode(displayIndex, &mode) != 0)
- return std::nullopt;
- return Display{ displayIndex, SDL_GetDisplayName(displayIndex), Units::Pixels{ bounds.x }, Units::Pixels{ bounds.y }, Units::Pixels{ bounds.w },
- Units::Pixels{ bounds.h }, dpi, mode.refresh_rate };
- });
- constexpr auto removeEmptyOptionals = ranges::views::filter([](const auto& display) { return display.has_value(); });
- constexpr auto takeOptionalValues = ranges::views::transform([](const auto& opt) { return *opt; });
- return validDisplayIndices | fetchDisplayData | removeEmptyOptionals | takeOptionalValues;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement