Platform class
#include <Runtime/Platform/Public/Platform.h>
Public types
- using ModalLoopTick = void(*)(void*ctx)
Public static variables
- static float MinUserScale constexpr
- static float MaxUserScale constexpr
- static uint32_t MaxDragRegions constexpr
Public static functions
- static auto PrefersReducedMotion() -> bool
- True if the user has asked the OS for less animation. Any thread; read when asked.
Constructors, destructors, conversion operators
Public functions
- auto operator=(const Platform&) -> Platform& deleted
- auto Initialize() -> bool
- Video and events must already be initialized (SDL_Init). Sentinel.
- void Shutdown()
- Destroys every window. Sentinel.
- auto OpenWindow(const PlatformWindowDesc& desc) -> PlatformWindowID
- Create an OS window (Vulkan-capable, high pixel density). The first one is the main window. Sentinel.
- void CloseWindow(PlatformWindowID window)
- auto GetMainWindow() const -> PlatformWindowID
- auto GetNativeWindow(PlatformWindowID window) const -> SDL_Window*
- Engine-internal: the SDL handle (Vulkan surface creation).
- auto ShowFileDialog(PlatformWindowID owner, uint32_t tag, std::string_view title, std::span<const std::pair<std::string, std::string>> filters, std::string_view start, int32_t kind) -> bool
- auto GetWindowMetrics(PlatformWindowID window) const -> PlatformWindowMetrics
- A window's sizes and scales as of the last pump. Sentinel.
- void SetUserScale(float scale)
- auto GetUserScale() const -> float
- auto GetKeyboardFocus() const -> PlatformWindowID
- The window that receives key and text events (0 = none: the app is in the background). Any thread.
- auto GetPointerWindow() const -> PlatformWindowID
- The window under the pointer (0 = none). Any thread.
- auto IsTextInputActive(PlatformWindowID window) const -> bool
- Whether the window currently accepts text input. Sentinel.
- void SetRelativeMouse(PlatformWindowID window, bool bEnabled)
- Sentinel: apply directly. Other threads: use Request().
- auto SetClipboardText(std::string text, PlatformClipboard which = PlatformClipboard::Clipboard) -> bool
- auto GetClipboardText(PlatformClipboard which = PlatformClipboard::Clipboard) const -> std::string
- Read the clipboard now. Sentinel; other threads use PlatformRequest::
ClipboardRead. - void SetDragRegions(PlatformWindowID window, const PlatformRect* rects, uint32_t count)
- void SetMaximizeRegion(PlatformWindowID window, const PlatformRect* rect)
- void SetModalLoopTick(ModalLoopTick tick, void* ctx)
- auto IsInModalLoop() const -> bool
- True inside a ModalLoopTick call.
- auto GetScreenRoom(PlatformWindowID window, PlatformRect& room) const -> bool
- auto GetNativeHandles(PlatformWindowID window) const -> PlatformNativeHandles
- Engine-internal: OS handles for native code behind this layer (null where not applicable).
- auto Request(const PlatformRequest& request) -> bool
- void Pump(std::vector<PlatformEvent>& out)
Typedef documentation
using Platform:: ModalLoopTick = void(*)(void*ctx)
While the OS runs its own loop (Windows: dragging or resizing a window, an open system menu), Pump() does not return. The platform then calls tick about 60 times a second from inside that loop so Sentinel's work (networking, audio, window events) keeps running; a Pump() made from the tick drains only events already queued. Sentinel.
Function documentation
void Platform:: CloseWindow(PlatformWindowID window)
Destroy a window; the renderer must have released its surface first. A window that still has popups is destroyed as soon as the last of them is. Sentinel.
bool Platform:: ShowFileDialog(PlatformWindowID owner,
uint32_t tag,
std::string_view title,
std::span<const std::pair<std::string, std::string>> filters,
std::string_view start,
int32_t kind)
Ask for the platform's file dialog, over owner: a FileChosen event with tag follows. filters: a name and its extensions (; between them) for each kind of file offered. Any thread. False if it could not be asked.
bool Platform:: SetClipboardText(std::string text,
PlatformClipboard which = PlatformClipboard::Clipboard)
Put text on the clipboard. Any thread, lock-free; applied on the next pump. False if the request queue is full.
void Platform:: SetMaximizeRegion(PlatformWindowID window,
const PlatformRect* rect)
Custom-chrome windows: where the app draws its maximize button (nullptr = none), so the OS treats it as one (Windows: Snap Layouts on hover). The app still receives pointer events over it and handles the click. Any thread, lock-free.
bool Platform:: GetScreenRoom(PlatformWindowID window,
PlatformRect& room) const
The usable part of the screen window is on (no task bar, no dock), in window coordinates relative to the window's own top left: where a popup of it can be put and still be seen. False if the window is unknown or the OS will not say. Sentinel.
bool Platform:: Request(const PlatformRequest& request)
Any thread, lock-free, non-blocking. Applied on Sentinel at the start of the next Pump(). Returns false if the queue is full (the request is dropped).
void Platform:: Pump(std::vector<PlatformEvent>& out)
Sentinel: apply queued requests, then translate every pending OS event into out (appended). Unknown windows and event kinds are skipped.
Variable documentation
static float Platform:: MinUserScale constexpr
The user's UI-scale setting, multiplied into every window's UI scale (clamped to MinUserScale..MaxUserScale). Sentinel; other threads use PlatformRequest::UserScale. Windows get a WindowScaleChanged on the next pump.
static uint32_t Platform:: MaxDragRegions constexpr
Custom-chrome windows: the areas of the app-drawn title bar that move the window. The OS runs the drag (follows the cursor anywhere, edge snapping, double-click to maximize), so the app never moves the window itself. Any thread, lock-free; replaces the previous set.