9#include "core/reflect.h"
10#include "platform/window/frame_limiter.h"
11#include "platform/input/input_handle.h"
12#include "platform/window/window_surface.h"
17namespace Vkm::Engine {
20inline constexpr int DEFAULT_WINDOW_WIDTH = 1920;
21inline constexpr int DEFAULT_WINDOW_HEIGHT = 1080;
26enum class WindowMode {
39 bool operator==(
const WindowSize& other)
const {
return width == other.width && height == other.height; }
51std::vector<WindowSize> fittingWindowSizes(
const std::vector<WindowSize>& modes,
WindowSize monitor);
56enum class CursorMode {
74 WindowManager(
const WindowManager& other) =
delete;
75 WindowManager& operator=(
const WindowManager& other) =
delete;
77 WindowManager(WindowManager && other) =
delete;
78 WindowManager& operator=(WindowManager && other) =
delete;
89 void createWindow(
const std::string& title, std::unique_ptr<WindowSurface> surface);
138 void saveScreenshot(std::string pngPath) { m_screenshotPath = std::move(pngPath); }
207 bool isOpen()
const {
return m_windowHandle !=
nullptr; }
214 WindowMode
mode()
const {
return m_windowMode; }
221 bool vsync()
const {
return m_vsync; }
230 int framerate()
const {
return m_frameLimiter.targetFramerate(); }
298 void setSize(
int width,
int height);
305 int getRefreshRate()
const;
308 GLFWwindow* m_windowHandle =
nullptr;
309 std::unique_ptr<WindowSurface> m_surface;
313 bool m_closeRequested =
false;
318 int m_windowWidth = 0;
319 double m_cursorX = 0.0;
320 double m_cursorY = 0.0;
321 CursorMode m_cursorMode = CursorMode::Normal;
326 WindowMode m_windowMode = WindowMode::Windowed;
327 bool m_vsync =
false;
328 std::string m_screenshotPath;
333VKM_ENUM_NAMES(::Vkm::Engine::WindowMode,
"Fullscreen",
"Windowed")
Limits a render loop's frame rate by sleeping, then spin-waiting.
Definition frame_limiter.h:12
void setTitle(const std::string &title)
Update the window title.
int displayHeight() const
Height in pixels of the monitor this window is on.
void updateMode(WindowMode windowMode)
Changes the current window mode (fullscreen or windowed).
WindowMode mode() const
The window mode last applied by updateMode.
Definition window_manager.h:214
void cancelClose()
Cancel a pending close, e.g. behind an unsaved-changes guard.
int framerate() const
The frame cap currently in effect.
Definition window_manager.h:230
void setVSync(bool enabled)
Enables or disables vertical synchronization (VSync).
GLFWwindow * getWindowContext() const
Get the underlying GLFW window pointer.
CursorMode cursorMode() const
The cursor mode last set.
Definition window_manager.h:237
float framebufferScale() const
Framebuffer pixels per window screen coordinate.
void swapBuffers()
Present the rendered image through the window's surface, then keep the frame cap.
void createWindow(const std::string &title, std::unique_ptr< WindowSurface > surface)
Creates the main application window with the specified title.
std::string takeScreenshotRequest()
Hand over the pending screenshot request, leaving none.
Definition window_manager.h:145
bool beginFrame()
Start the frame limiter's clock for the next frame.
void updateInput()
Updates all input states (keyboard, mouse, etc.).
bool isOpen() const
Whether a window exists at all.
Definition window_manager.h:207
std::vector< WindowSize > renderResolutions() const
The resolutions a settings screen can offer to render at: the monitor's own video modes that fit on i...
bool shouldClose() const
Checks if the window close event has been triggered.
size_t getWidth() const
Get the framebuffer width in pixels.
InputHandle & getInputHandle()
Get the current input handle for querying input state.
Definition window_manager.h:244
void setCursorMode(CursorMode mode)
Sets the cursor mode.
void setIcon(const std::string &path)
Sets the window/taskbar icon from an image file (PNG, etc.).
size_t getHeight() const
Get the framebuffer height in pixels; see getWidth().
void saveScreenshot(std::string pngPath)
Write the next frame the game draws to pngPath, once.
Definition window_manager.h:138
void setFramerate(int framerate)
Sets the maximum framerate for the render loop.
bool vsync() const
Whether vsync was last enabled via setVSync.
Definition window_manager.h:221
void requestClose()
Requests that the window be closed.
A window's size in pixels.
Definition window_manager.h:35