vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
Vkm::Engine::WindowManager Class Reference

Owns the application's window, GL context, input, and frame limiting. More...

#include <window_manager.h>

Public Member Functions

void createWindow (const std::string &title)
 Creates the main application window with the specified title.
void setIcon (const std::string &path)
 Sets the window/taskbar icon from an image file (PNG, etc.).
bool shouldClose () const
 Checks if the window close event has been triggered.
void requestClose ()
 Requests that the window be closed.
void cancelClose ()
 Cancel a pending close, e.g. behind an unsaved-changes guard.
void setTitle (const std::string &title)
 Update the window title.
void swapBuffers ()
 Swaps the front and back buffers of the window, presenting the rendered image.
void saveScreenshot (std::string pngPath)
 Write the next frame the game draws to pngPath, once.
std::string takeScreenshotRequest ()
 Hand over the pending screenshot request, leaving none.
void updateMode (WindowMode windowMode)
 Changes the current window mode (fullscreen or windowed).
void updateInput ()
 Updates all input states (keyboard, mouse, etc.).
bool beginFrame ()
 Start the frame limiter's clock for the next frame.
void setVSync (bool enabled)
 Enables or disables vertical synchronization (VSync).
void setFramerate (int framerate)
 Sets the maximum framerate for the render loop.
void setCursorMode (CursorMode mode)
 Sets the cursor mode.
bool isOpen () const
 Whether a window exists at all.
WindowMode mode () const
 The window mode last applied by updateMode.
bool vsync () const
 Whether vsync was last enabled via setVSync.
int framerate () const
 The frame cap currently in effect.
CursorMode cursorMode () const
 The cursor mode last set.
InputHandle & getInputHandle ()
 Get the current input handle for querying input state.
size_t getWidth () const
 Get the framebuffer width in pixels.
size_t getHeight () const
 Get the framebuffer height in pixels; see getWidth().
float framebufferScale () const
 Framebuffer pixels per window screen coordinate.
GLFWwindow * getWindowContext () const
 Get the underlying GLFW window pointer.
int displayHeight () const
 Height in pixels of the monitor this window is on.

Detailed Description

Owns the application's window, GL context, input, and frame limiting.

A closed window accepts every request and performs none, and reporters answer zero (framebufferScale answers one): a windowless world still ticks and must still be able to end.

Member Function Documentation

◆ createWindow()

void Vkm::Engine::WindowManager::createWindow ( const std::string & title)

Creates the main application window with the specified title.

Parameters
titleThe window title.

◆ setIcon()

void Vkm::Engine::WindowManager::setIcon ( const std::string & path)

Sets the window/taskbar icon from an image file (PNG, etc.).

A no-op before createWindow(); a file that fails to load is logged and skipped.

Parameters
pathAbsolute path to the icon image.

◆ shouldClose()

bool Vkm::Engine::WindowManager::shouldClose ( ) const

Checks if the window close event has been triggered.

Returns
true if the window should close, false otherwise.

◆ setTitle()

void Vkm::Engine::WindowManager::setTitle ( const std::string & title)

Update the window title.

Parameters
titleThe new title; kept even with no window.

◆ saveScreenshot()

void Vkm::Engine::WindowManager::saveScreenshot ( std::string pngPath)
inline

Write the next frame the game draws to pngPath, once.

A request RenderSystem takes after its next frame: the game's view at viewport size, without a host's panels. A second request replaces the first; a host drawing nothing writes nothing.

Parameters
pngPathWhere the PNG goes; the directory must exist.

◆ takeScreenshotRequest()

std::string Vkm::Engine::WindowManager::takeScreenshotRequest ( )
inline

Hand over the pending screenshot request, leaving none.

Returns
The path saveScreenshot named, or empty when none is pending.

◆ updateMode()

void Vkm::Engine::WindowManager::updateMode ( WindowMode windowMode)

Changes the current window mode (fullscreen or windowed).

Parameters
windowModeThe desired window mode.

◆ beginFrame()

bool Vkm::Engine::WindowManager::beginFrame ( )

Start the frame limiter's clock for the next frame.

Returns
False once a close has been requested.

◆ setVSync()

void Vkm::Engine::WindowManager::setVSync ( bool enabled)

Enables or disables vertical synchronization (VSync).

Parameters
enabledTrue to enable VSync, false to disable.

◆ setFramerate()

void Vkm::Engine::WindowManager::setFramerate ( int framerate)

Sets the maximum framerate for the render loop.

Parameters
framerateFrames per second limit.

◆ setCursorMode()

void Vkm::Engine::WindowManager::setCursorMode ( CursorMode mode)

Sets the cursor mode.

Kept even with no window, so cursorMode() answers what it was told.

Parameters
modeThe desired cursor mode.

◆ isOpen()

bool Vkm::Engine::WindowManager::isOpen ( ) const
inline

Whether a window exists at all.

Ask before reading a device: a reader cannot otherwise tell "zero" from "no display".

Returns
True when this manager owns an open window.

◆ mode()

WindowMode Vkm::Engine::WindowManager::mode ( ) const
inline

The window mode last applied by updateMode.

Returns
The last applied mode; Windowed at creation.

◆ vsync()

bool Vkm::Engine::WindowManager::vsync ( ) const
inline

Whether vsync was last enabled via setVSync.

Returns
The last applied vsync state; off at creation.

◆ framerate()

int Vkm::Engine::WindowManager::framerate ( ) const
inline

The frame cap currently in effect.

Independent of vsync; with both active the lower rate wins.

Returns
Frames per second, or 0 when the rate is uncapped.

◆ cursorMode()

CursorMode Vkm::Engine::WindowManager::cursorMode ( ) const
inline

The cursor mode last set.

Returns
CursorMode::Normal until something sets another.

◆ getInputHandle()

InputHandle & Vkm::Engine::WindowManager::getInputHandle ( )
inline

Get the current input handle for querying input state.

Returns
The device state.

◆ getWidth()

size_t Vkm::Engine::WindowManager::getWidth ( ) const

Get the framebuffer width in pixels.

The drawable size, which differs from the window's screen coords on a HiDPI display.

Returns
The framebuffer width in pixels.

◆ getHeight()

size_t Vkm::Engine::WindowManager::getHeight ( ) const

Get the framebuffer height in pixels; see getWidth().

Returns
The framebuffer height in pixels.

◆ framebufferScale()

float Vkm::Engine::WindowManager::framebufferScale ( ) const

Framebuffer pixels per window screen coordinate.

Diverges from 1 under HiDPI scaling, where GLFW reports window geometry and cursor in screen coords; anything crossing to the drawable multiplies by this.

Returns
The scale, or 1.0f when there is no window yet.

◆ getWindowContext()

GLFWwindow * Vkm::Engine::WindowManager::getWindowContext ( ) const

Get the underlying GLFW window pointer.

Returns
The window, or nullptr if not initialized.

◆ displayHeight()

int Vkm::Engine::WindowManager::displayHeight ( ) const

Height in pixels of the monitor this window is on.

The monitor, not the window, so the answer survives a maximise or fullscreen switch.

Returns
Monitor height in pixels, or 0 when there is no window.

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