10#include <unordered_set>
11#include <unordered_map>
119 void UpdateMouseState();
123 std::unordered_set<SDL_Window*> m_windows;
125 std::vector<SDL_Window*> m_modalWindows;
130 float OsPerPixel(SDL_Window* window)
const;
138 std::unordered_set<SDL_Window*> m_pendingDestroy;
139 std::unordered_set<SDL_Window*> m_closeRequests;
140 bool m_sdlInitialized =
false;
141 bool m_ownsSDL =
false;
142 bool m_routesSDLMemory =
false;
143 bool m_cursorVisible =
true;
145 static constexpr int kSystemCursorSlots = 32;
146 SDL_Cursor* m_systemCursors[kSystemCursorSlots] = {};
148 bool (*m_eventWatch)(
void*, SDL_Event*) =
nullptr;
150 static bool BackendEventWatch(
void* userdata, SDL_Event* event);
151 uint32_t m_focusChanges = 0;
152 bool m_checkFocusLeftApp =
false;
153 bool m_suppressLiveResize =
false;
154 SDL_Window* m_lastFocusableWindow =
nullptr;
157 SDL_Window* GetTopModalWindowSDL()
const;
A graphics backend: the device, the window contexts that render the GUI's windows,...
Definition gui_graphics_context.h:60
IWindowBackend()
Definition gui_window_backend.h:107
A window's rendering state: made by GraphicsContext::CreateWindowContext for each OS window,...
Definition gui_window_backend.h:72
Layered windows that stand in for a window while it fades in or out: each shows a fixed picture (the ...
Definition gui_layered_fade.h:20
int GetMonitorAt(int2 pos) const override
Index into GetMonitors of the monitor holding the screen point pos; 0 (the primary) when no monitor h...
IWindowContext * GetWindowContext(OSWindowHandle) override
The context attached with AttachContextToWindow, or nullptr.
SDLWindowBackendOptions Options
See SDLWindowBackendOptions.
Definition gui_window_backend_sdl.h:44
bool SetWindowCloaked(OSWindowHandle, bool cloaked) override
Cloaks a shown window: it takes frames but stays invisible, so it can be drawn before it appears.
bool IsWindow(OSWindowHandle) override
True while the handle is a live window of this backend; false once it was destroyed (by code or the u...
void EndFade(uint32_t fade) override
Removes a stand-in.
void SetWindowVisible(OSWindowHandle, bool visible) override
Shows or hides the window; hiding doesn't destroy it.
void SwapBuffers(OSWindowHandle) override
Presents for a graphics API that swaps through the window (OpenGL).
SDL_Window * ModalBlockerFor(const SDL_Event *event) const
The modal window that blocks the event's window (one of ours), or null.
void SetWindowMode(OSWindowHandle, WindowMode) override
Sets the window's state: minimized, maximized, restored or fullscreen.
static SDL_Window * ToSDL(OSWindowHandle h)
Converts between handles and SDL windows: a handle is the SDL_Window pointer.
Definition gui_window_backend_sdl.h:114
void MoveFade(uint32_t fade, IntRect screenRect, float opacity) override
Moves a stand-in and sets its opacity.
IntRect GetWindowPixelRect(OSWindowHandle window) override
The window's render target: OS position (for OS compositing) and size in physical pixels.
uint32_t GetFocusChangeCount() const override
Goes up whenever keyboard focus moves between windows, or to or from another application; open popups...
Definition gui_window_backend_sdl.h:71
uint32_t ShowFade(OSWindowHandle window, IWindowContext *context, IntRect screenRect, float opacity) override
A layered stand-in for window showing what context drew last, at screenRect (screen pixels) and opaci...
int2 GetWindowPos(OSWindowHandle) override
The client area's top-left in screen pixels.
bool TakeCloseRequest(OSWindowHandle window) override
Whether the OS asked to close a WindowFlags::ConfirmClose window since last asked.
int32_t GetCursorSize() const override
The OS mouse cursor's size in pixels (its accessibility size at the display's scale),...
OSWindowHandle CreateWindow(std::string_view title, int2 size, tachyon::WindowFlags windowFlags, OSWindowHandle parentOSHandle) override
Creates a window whose client area is size pixels, placed by the OS.
MouseButtons GetMouseButtons() override
The mouse buttons held down, wherever the mouse is (SDL: as of the last PollEvents).
std::vector< MonitorInfo > GetMonitors() const override
Every monitor, the primary first.
int2 WindowPointToPixels(SDL_Window *window, float x, float y) const
A position inside window (OS window coordinates) in screen pixels.
void SetCursor(MouseCursor cursor) override
Shows the system cursor for that shape; MouseCursor::None hides the cursor.
WindowMode GetWindowMode(OSWindowHandle) const override
The window's state as the OS has it now; WindowMode::Normal by default.
static OSWindowHandle FromSDL(SDL_Window *w)
Converts between handles and SDL windows: a handle is the SDL_Window pointer.
Definition gui_window_backend_sdl.h:115
bool DestroyWindow(OSWindowHandle) override
Queues the window for destruction: the next PollEvents passes its context to cleanup,...
OSWindowHandle CreateWindow(std::string_view title, IntRect rect, tachyon::WindowFlags windowFlags, OSWindowHandle parentOSHandle) override
Creates a window whose client area is rect (screen pixels); otherwise as the size overload.
float GetWindowDisplayScale(OSWindowHandle window) override
The UI scale the OS asks for in this window: pixel density times the monitor's content scale (1....
SDLWindowBackend(const Options &options={})
Starts SDL video if needed; failing that, logs an error and the backend makes no windows.
IntRect GetWindowRect(OSWindowHandle) override
Client area in pixels; {0,0,0,0} while minimized.
void AttachContextToWindow(OSWindowHandle window, IWindowContext *context) override
Stores the window's context (not owned), for GetWindowContext, for the ID passed with the window's in...
bool PrefersReducedMotion() override
Whether the OS asks for less motion (animations turned off); false where the platform has no such set...
void DetachWindowContext(OSWindowHandle) override
Clears the context pointer stored in the OS window, so PollEvents' cleanup callback gets nullptr inst...
void BringToFront(OSWindowHandle) override
Raises the window above the others and asks the OS for the input focus.
int2 GetScreenMousePos() override
The mouse position in screen pixels (SDL: as of the last PollEvents).
void AttachInputHandlerToWindow(OSWindowHandle window, IPlatformInputHandler *inputHandler) override
Where the window's input goes (see IPlatformInputHandler); not owned, nullptr for none.
OSWindowHandle GetActiveWindow() override
The window with the keyboard focus, or nullptr when none of the backend's windows has it.
bool SetWindowRect(OSWindowHandle, const IntRect &clientRect) override
Moves and resizes the window so its client area is clientRect (screen pixels); the backend accounts f...
~SDLWindowBackend() override
std::optional< color4b > ReadScreenPixel(int2 screenPos) override
The color of a screen pixel, anywhere on the desktop (an eyedropper); nothing where the platform can'...
std::string GetPreferredLanguage() const override
The user's preferred language as a BCP 47 tag ("ja", "en-US"), or empty when the platform doesn't say...
int GetMonitorFromWindow(OSWindowHandle handle) const override
Index into GetMonitors of the window's monitor; -1 for an unknown window.
void * GetNativeHandle(OSWindowHandle) override
The OS's own window handle, passed to GraphicsContext::CreateWindowContext (HWND on Windows,...
void PollEvents(std::function< void(OSWindowHandle, IWindowContext *)> cleanup) override
Handles the OS's pending events, delivering input to the attached handlers.
float GetDoubleClickMilliseconds() override
The OS's double-click time in milliseconds, or 0 where the platform has none.
uint32_t GetTicks() const override
A millisecond clock (SDL: since SDL started).
void SetTextInputArea(OSWindowHandle window, IntRect rect) override
Where text is being typed in the window (window coordinates), so the IME places its candidate list ne...
void SetGraphicsContext(GraphicsContext *graphicsContext) override
Windows are created for graphicsContext->GetAPI(); for a VulkanGraphicsContext this also installs its...
OSWindowHandle GetWindowUnderMouse() override
The backend's window under the mouse, or nullptr.
int2 GetWindowSize(OSWindowHandle) override
The client area's size in pixels; {0,0} while minimized.
MouseCursor
Mouse cursor shown over an element (CSS: cursor).
Definition gui_style.h:478
WindowFlags
How an OS window is made and behaves (IWindowBackend::CreateWindow); flags combine with |.
Definition gui_window_flags.h:12
WindowMode
A window's state (IWindowBackend::SetWindowMode). Any window can go fullscreen.
Definition gui_window_backend.h:60
void * OSWindowHandle
An OS window, opaque; what it points to is up to the window backend.
Definition gui_window_backend.h:37
Definition gui_logging.h:24
Memory functions a host gives the library, for the allocations that can be routed: Vulkan objects,...
Definition gui_allocation_hooks.h:15
Definition gui_base_types.h:407
Options for SDLWindowBackend (SDLWindowBackend::Options).
Definition gui_window_backend_sdl.h:28
bool pumpEvents
PollEvents empties SDL's event queue.
Definition gui_window_backend_sdl.h:35
const AllocationHooks * hooks
Hooks for SDL's memory functions, which are process-wide.
Definition gui_window_backend_sdl.h:31
Integer 2D vector.
Definition gui_base_types.h:19