/// @file platform/window.h /// @brief Platform-independent window interface. /// /// The implementation is chosen at build time by the name of the file: /// `window_mac.mm` for macOS, `window_win.cpp` for Windows. A window is created /// and driven from the main thread only. #pragma once #include "core/types.h" namespace kumo { struct FrameBuffer; class Keyboard; /// @brief Opaque window handle; the definition lives in the platform file. struct Window; /// @brief Parameters for window_create(). struct WindowDesc { const char* title; ///< UTF-8 window title. int width; ///< Content width in points. int height; ///< Content height in points. }; /// @brief Creates a window, shows it and brings it to the front. /// /// The first call also sets up the application: on macOS its menu (with Cmd+Q) /// and the rest of what a program needs to be a normal windowed application. /// /// @param desc Window parameters. /// @return The new window, or `nullptr` on failure. Window* window_create(const WindowDesc& desc); /// @brief Closes the window and frees it. Passing `nullptr` is allowed. void window_destroy(Window* window); /// @brief Processes every pending event of the window system without blocking. /// /// Call once per frame. void window_poll_events(Window* window); /// @brief Returns the keyboard state owned by the window. /// /// Use on the main thread. The reference is valid until window_destroy(). Keyboard& window_keyboard(Window* window); /// @brief Tells whether the user asked to close the window. /// /// True after the close button is pressed or Escape is hit. The window stays /// open until window_destroy(), so the caller decides when to shut down. bool window_should_close(const Window* window); /// @brief Shows a frame in the window. /// /// The frame is scaled to fill the content of the window; the window system /// does the scaling, with nearest-neighbor filtering so that pixels stay sharp. /// The call waits for the display to be ready for the next frame, so a loop /// that presents once per iteration runs at the refresh rate of the display. /// /// @param framebuffer The pixels to show. Its size may change between calls. void window_present(Window* window, const FrameBuffer& framebuffer); /// @brief Changes the title of the window. /// /// @param title UTF-8 text. void window_set_title(Window* window, const char* title); } // namespace kumo