VEX Engine
Retro looking game engine made in vulkan mostly because i wanted to understand it better.
Loading...
Searching...
No Matches
vex::Window Class Reference

This class esentially abstracts SDL_Window. More...

#include <Window.hpp>

Public Member Functions

 Window (std::string title, int resx=480, int resy=640)
 Constructor for Window class.
SDL_Window * GetSDLWindow ()
 Getter for SDL_Window pointer.
void setFullscreen (bool enabled, bool exclusive=false)
 Setter for fullscreen mode.
bool isFullscreen ()
 Getter for fullscreen mode.
float getRefreshRate ()
 Gets the refresh rate of the display the window is currently on.

Private Attributes

SDL_Window * window
bool done = false
bool m_cachedFullscreenState = false
 Cached fullscreen state to prevent redundant SDL calls.
bool m_cachedExclusiveMode = false
 Cached exclusive mode setting.
Uint64 m_lastFullscreenChangeTime = 0
 Timestamp of last fullscreen state change (in SDL performance counter units).

Static Private Attributes

static constexpr Uint64 FULLSCREEN_DEBOUNCE_MS = 100
 Debounce interval in milliseconds to prevent rapid fullscreen toggles.

Detailed Description

This class esentially abstracts SDL_Window.

Definition at line 18 of file Window.hpp.

Constructor & Destructor Documentation

◆ Window()

vex::Window::Window ( std::string title,
int resx = 480,
int resy = 640 )

Constructor for Window class.

Initializes SDL with Video and Gamepad subsystems.

  • On Linux, attempts to hint wayland,x11 drivers.
  • Creates the window with flags: SDL_WINDOW_VULKAN, SDL_WINDOW_HIGH_PIXEL_DENSITY, and SDL_WINDOW_RESIZABLE.
    Exceptions
    std::runtime_error- If SDL initialization or Window creation fails.
    Parameters
    std::stringtitle - Title of the window.
    intresx - Width of the window in pixels (default: 480).
    intresy - Height of the window in pixels (default: 640).

Definition at line 4 of file Window.cpp.

◆ ~Window()

vex::Window::~Window ( )

Definition at line 39 of file Window.cpp.

Member Function Documentation

◆ getRefreshRate()

float vex::Window::getRefreshRate ( )

Gets the refresh rate of the display the window is currently on.

Queries SDL_GetDisplayForWindow followed by SDL_GetCurrentDisplayMode.

Returns
float - Refresh rate in Hz. Returns 60.0f as a fallback if the query fails.

Definition at line 106 of file Window.cpp.

◆ GetSDLWindow()

SDL_Window * vex::Window::GetSDLWindow ( )

Getter for SDL_Window pointer.

Returns
SDL_Window*

Definition at line 46 of file Window.cpp.

◆ isFullscreen()

bool vex::Window::isFullscreen ( )

Getter for fullscreen mode.

Returns
bool - True if fullscreen is enabled, false otherwise.

Definition at line 102 of file Window.cpp.

◆ setFullscreen()

void vex::Window::setFullscreen ( bool enabled,
bool exclusive = false )

Setter for fullscreen mode.

  • Only performs mode change if state differs from cached state.
  • Includes debounce mechanism to prevent rapid consecutive toggles.
  • Exclusive: Queries the current display mode and sets SDL_SetWindowFullscreenMode before entering fullscreen.
  • Borderless: Sets the mode to NULL (desktop fullscreen) before entering fullscreen.
    Parameters
    boolenabled - True to enable fullscreen, false to disable.
    boolexclusive - True for exclusive fullscreen (changes video mode), false for borderless windowed
    Warning
    DO NOT call this function every frame. Use only when user initiates a display mode change.

Definition at line 50 of file Window.cpp.

Member Data Documentation

◆ done

bool vex::Window::done = false
private

Definition at line 21 of file Window.hpp.

◆ FULLSCREEN_DEBOUNCE_MS

Uint64 vex::Window::FULLSCREEN_DEBOUNCE_MS = 100
staticconstexprprivate

Debounce interval in milliseconds to prevent rapid fullscreen toggles.

Definition at line 30 of file Window.hpp.

◆ m_cachedExclusiveMode

bool vex::Window::m_cachedExclusiveMode = false
private

Cached exclusive mode setting.

Definition at line 26 of file Window.hpp.

◆ m_cachedFullscreenState

bool vex::Window::m_cachedFullscreenState = false
private

Cached fullscreen state to prevent redundant SDL calls.

Definition at line 24 of file Window.hpp.

◆ m_lastFullscreenChangeTime

Uint64 vex::Window::m_lastFullscreenChangeTime = 0
private

Timestamp of last fullscreen state change (in SDL performance counter units).

Definition at line 28 of file Window.hpp.

◆ window

SDL_Window* vex::Window::window
private

Definition at line 20 of file Window.hpp.


The documentation for this class was generated from the following files: