7#include "platform/window/frame_limiter.h"
8#include "platform/input/input_handle.h"
13namespace Vkm::Engine {
16inline constexpr int OPENGL_MAJOR_VERSION = 4;
17inline constexpr int OPENGL_MINOR_VERSION = 3;
19inline constexpr int OPENGL_GLSL_VERSION = OPENGL_MAJOR_VERSION * 100 + OPENGL_MINOR_VERSION * 10;
20inline constexpr int DEFAULT_WINDOW_WIDTH = 1920;
21inline constexpr int DEFAULT_WINDOW_HEIGHT = 1080;
26enum class WindowMode {
34enum class CursorMode {
47constexpr const char* toString(WindowMode type) {
49 case WindowMode::Fullscreen:
return "Fullscreen";
50 case WindowMode::Windowed:
return "Windowed";
51 default:
return "UNKNOWN";
66 WindowManager(
const WindowManager& other) =
delete;
67 WindowManager& operator=(
const WindowManager& other) =
delete;
69 WindowManager(WindowManager && other) =
delete;
70 WindowManager& operator=(WindowManager && other) =
delete;
127 void saveScreenshot(std::string pngPath) { m_screenshotPath = std::move(pngPath); }
185 bool isOpen()
const {
return m_windowHandle !=
nullptr; }
192 WindowMode
mode()
const {
return m_windowMode; }
199 bool vsync()
const {
return m_vsync; }
208 int framerate()
const {
return m_frameLimiter.targetFramerate(); }
276 void setSize(
int width,
int height);
283 int getRefreshRate()
const;
286 GLFWwindow* m_windowHandle =
nullptr;
290 bool m_closeRequested =
false;
295 int m_windowWidth = 0;
296 double m_cursorX = 0.0;
297 double m_cursorY = 0.0;
298 CursorMode m_cursorMode = CursorMode::Normal;
303 WindowMode m_windowMode = WindowMode::Windowed;
304 bool m_vsync =
false;
305 std::string m_screenshotPath;
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:192
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:208
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:215
float framebufferScale() const
Framebuffer pixels per window screen coordinate.
void swapBuffers()
Swaps the front and back buffers of the window, presenting the rendered image.
std::string takeScreenshotRequest()
Hand over the pending screenshot request, leaving none.
Definition window_manager.h:134
bool beginFrame()
Start the frame limiter's clock for the next frame.
void createWindow(const std::string &title)
Creates the main application window with the specified title.
void updateInput()
Updates all input states (keyboard, mouse, etc.).
bool isOpen() const
Whether a window exists at all.
Definition window_manager.h:185
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:222
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:127
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:199
void requestClose()
Requests that the window be closed.