Files
hdk-sdl/include/hdk/sdl/video/Display.hpp
T
2026-05-13 19:48:22 +00:00

71 lines
3.3 KiB
C++

#pragma once
/// @file Display.hpp
/// For complete documentation, see src/video/Display.cpp
#include <SDL3/SDL_video.h>
#include <hdk/grid/PrimitiveWrapper.hpp>
#include <hdk/sdl/Properties.hpp>
#include <vector>
namespace hdk::sdl {
class Display : public grid::PrimitiveWrapper<SDL_DisplayID> {
public:
using grid::PrimitiveWrapper<SDL_DisplayID>::PrimitiveWrapper;
bool GetClosestFullscreenMode(
int w, int h, float refresh_rate, bool include_high_density_modes, SDL_DisplayMode* closest) {
return SDL_GetClosestFullscreenDisplayMode(*this, w, h, refresh_rate, include_high_density_modes, closest);
}
const SDL_DisplayMode* GetCurrentMode() const { return SDL_GetCurrentDisplayMode(*this); }
SDL_DisplayOrientation GetCurrentOrientation() const { return SDL_GetCurrentDisplayOrientation(*this); }
const SDL_DisplayMode* GetDesktopMode() const { return SDL_GetDesktopDisplayMode(*this); }
bool GetBounds(SDL_Rect* rect) const { return SDL_GetDisplayBounds(*this, rect); }
SDL_Rect GetBounds() const {
SDL_Rect rect;
if (GetBounds(&rect)) {
return rect;
}
return SDL_Rect{ 0, 0, 0, 0 };
}
float GetContentScale() const { return SDL_GetDisplayContentScale(*this); }
static Display GetForPoint(const SDL_Point* point) { return Display(SDL_GetDisplayForPoint(point)); }
static Display GetForRect(const SDL_Rect* rect) { return Display(SDL_GetDisplayForRect(rect)); }
static Display GetForWindow(SDL_Window* window) { return Display(SDL_GetDisplayForWindow(window)); }
const char* GetName() const { return SDL_GetDisplayName(*this); }
Properties GetProperties() const { return Properties(SDL_GetDisplayProperties(*this)); }
static SDL_DisplayID* GetDisplays(int* count) { return SDL_GetDisplays(count); }
/** @see SDL_GetDisplays
* @returns std::vector Display(s) available
*/
static std::vector<Display> GetDisplays() {
int count;
SDL_DisplayID* displayIDs = SDL_GetDisplays(&count);
std::vector<Display> displays;
if (displayIDs) {
displays.reserve(count);
for (int i = 0; i < count; ++i) {
displays.emplace_back(displayIDs[i]);
}
SDL_free(displayIDs);
}
return displays;
}
bool GetUsableBounds(SDL_Rect* rect) const { return SDL_GetDisplayUsableBounds(*this, rect); }
SDL_DisplayMode** GetFullscreenModes(int* count) const { return SDL_GetFullscreenDisplayModes(*this, count); }
/** @see SDL_GetFullscreenDisplayModes
* @returns std::vector of display modes available for fullscreen mode
*/
std::vector<SDL_DisplayMode> GetFullscreenModes() const {
int count;
SDL_DisplayMode** modes = SDL_GetFullscreenDisplayModes(*this, &count);
std::vector<SDL_DisplayMode> displayModes;
if (modes) {
displayModes.reserve(count);
for (int i = 0; i < count; ++i) {
displayModes.push_back(*modes[i]);
}
SDL_free(modes);
}
return displayModes;
}
SDL_DisplayOrientation GetNaturalOrientation() const { return SDL_GetNaturalDisplayOrientation(*this); }
static Display GetPrimaryDisplay() { return Display(SDL_GetPrimaryDisplay()); }
};
}