|
TachyonUI 0.1.0
High-performance UI for building tools.
|
The default window backend, on SDL3. More...
#include <gui_core/windows/sdl/gui_window_backend_sdl.h>
Public Types | |
| using | Options = SDLWindowBackendOptions |
| See SDLWindowBackendOptions. | |
Public Member Functions | |
| SDLWindowBackend (const Options &options={}) | |
| Starts SDL video if needed; failing that, logs an error and the backend makes no windows. | |
| ~SDLWindowBackend () override | |
| void | SetGraphicsContext (GraphicsContext *graphicsContext) override |
| Windows are created for graphicsContext->GetAPI(); for a VulkanGraphicsContext this also installs its SDL surface factory. | |
| 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. | |
| 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. | |
| void | AttachInputHandlerToWindow (OSWindowHandle window, IPlatformInputHandler *inputHandler) override |
| Where the window's input goes (see IPlatformInputHandler); not owned, nullptr for none. | |
| void | AttachContextToWindow (OSWindowHandle window, IWindowContext *context) override |
| Stores the window's context (not owned), for GetWindowContext, for the ID passed with the window's input, and for PollEvents' cleanup. | |
| bool | DestroyWindow (OSWindowHandle) override |
| Queues the window for destruction: the next PollEvents passes its context to cleanup, then destroys it. | |
| void | DetachWindowContext (OSWindowHandle) override |
| Clears the context pointer stored in the OS window, so PollEvents' cleanup callback gets nullptr instead of double-freeing a context the caller destroys. | |
| bool | IsWindow (OSWindowHandle) override |
| True while the handle is a live window of this backend; false once it was destroyed (by code or the user) and for nullptr. | |
| IWindowContext * | GetWindowContext (OSWindowHandle) override |
| The context attached with AttachContextToWindow, or nullptr. | |
| void | BringToFront (OSWindowHandle) override |
| Raises the window above the others and asks the OS for the input focus. | |
| OSWindowHandle | GetWindowUnderMouse () override |
| The backend's window under the mouse, or nullptr. | |
| OSWindowHandle | GetActiveWindow () override |
| The window with the keyboard focus, or nullptr when none of the backend's windows has it. | |
| uint32_t | GetFocusChangeCount () const override |
| Goes up whenever keyboard focus moves between windows, or to or from another application; open popups are checked against it. | |
| void | PollEvents (std::function< void(OSWindowHandle, IWindowContext *)> cleanup) override |
| Handles the OS's pending events, delivering input to the attached handlers. | |
| int2 | GetScreenMousePos () override |
| The mouse position in screen pixels (SDL: as of the last PollEvents). | |
| std::optional< color4b > | ReadScreenPixel (int2 screenPos) override |
| The color of a screen pixel, anywhere on the desktop (an eyedropper); nothing where the platform can't read the screen. | |
| bool | TakeCloseRequest (OSWindowHandle window) override |
| Whether the OS asked to close a WindowFlags::ConfirmClose window since last asked. | |
| MouseButtons | GetMouseButtons () override |
| The mouse buttons held down, wherever the mouse is (SDL: as of the last PollEvents). | |
| float | GetDoubleClickMilliseconds () override |
| The OS's double-click time in milliseconds, or 0 where the platform has none. | |
| 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 opacity (0 to 1), so the window itself can be hidden or cloaked while it fades in or out. | |
| void | MoveFade (uint32_t fade, IntRect screenRect, float opacity) override |
| Moves a stand-in and sets its opacity. | |
| void | EndFade (uint32_t fade) override |
| Removes a stand-in. | |
| bool | PrefersReducedMotion () override |
| Whether the OS asks for less motion (animations turned off); false where the platform has no such setting. | |
| void | SetCursor (MouseCursor cursor) override |
| Shows the system cursor for that shape; MouseCursor::None hides the cursor. | |
| void | SetTextInputArea (OSWindowHandle window, IntRect rect) override |
| Where text is being typed in the window (window coordinates), so the IME places its candidate list next to it. | |
| float | GetWindowDisplayScale (OSWindowHandle window) override |
| The UI scale the OS asks for in this window: pixel density times the monitor's content scale (1.5 on a 150% display). | |
| IntRect | GetWindowPixelRect (OSWindowHandle window) override |
| The window's render target: OS position (for OS compositing) and size in physical pixels. | |
| void | SwapBuffers (OSWindowHandle) override |
| Presents for a graphics API that swaps through the window (OpenGL). | |
| IntRect | GetWindowRect (OSWindowHandle) override |
| Client area in pixels; {0,0,0,0} while minimized. | |
| int2 | GetWindowPos (OSWindowHandle) override |
| The client area's top-left in screen pixels. | |
| int2 | GetWindowSize (OSWindowHandle) override |
| The client area's size in pixels; {0,0} while minimized. | |
| bool | SetWindowRect (OSWindowHandle, const IntRect &clientRect) override |
| Moves and resizes the window so its client area is clientRect (screen pixels); the backend accounts for the frame. | |
| void | SetWindowVisible (OSWindowHandle, bool visible) override |
| Shows or hides the window; hiding doesn't destroy it. | |
| bool | SetWindowCloaked (OSWindowHandle, bool cloaked) override |
| Cloaks a shown window: it takes frames but stays invisible, so it can be drawn before it appears. | |
| void | SetWindowMode (OSWindowHandle, WindowMode) override |
| Sets the window's state: minimized, maximized, restored or fullscreen. | |
| WindowMode | GetWindowMode (OSWindowHandle) const override |
| The window's state as the OS has it now; WindowMode::Normal by default. | |
| std::vector< MonitorInfo > | GetMonitors () const override |
| Every monitor, the primary first. | |
| int | GetMonitorAt (int2 pos) const override |
| Index into GetMonitors of the monitor holding the screen point pos; 0 (the primary) when no monitor holds it, -1 without monitors. | |
| int | GetMonitorFromWindow (OSWindowHandle handle) const override |
| Index into GetMonitors of the window's monitor; -1 for an unknown window. | |
| uint32_t | GetTicks () const override |
| A millisecond clock (SDL: since SDL started). | |
| 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. | |
| int32_t | GetCursorSize () const override |
| The OS mouse cursor's size in pixels (its accessibility size at the display's scale), or 0 when the platform doesn't say. | |
| void * | GetNativeHandle (OSWindowHandle) override |
| The OS's own window handle, passed to GraphicsContext::CreateWindowContext (HWND on Windows, NSWindow on macOS, an X11 window or Wayland surface on Linux); nullptr without one. | |
| int2 | WindowPointToPixels (SDL_Window *window, float x, float y) const |
| A position inside window (OS window coordinates) in screen pixels. | |
| SDL_Window * | ModalBlockerFor (const SDL_Event *event) const |
| The modal window that blocks the event's window (one of ours), or null. | |
| Public Member Functions inherited from tachyon::IWindowBackend | |
| IWindowBackend () | |
| virtual | ~IWindowBackend () |
| void | SetWindowMovedCallback (std::function< void()> cb) |
| Sets cb, called as soon as any window moves or resizes, even inside the OS modal move / resize loop (before the next frame), so it must be safe outside the frame. | |
| void | SetHitTestCallback (std::function< WindowHitArea(OSWindowHandle, int2 screenPos)> cb) |
| Classifies points (screen pixels) of CustomTitleBar windows for the OS. | |
| WindowHitArea | HitTestWindow (OSWindowHandle window, int2 screenPos) const |
| What a point (screen pixels) of the window is, from the hit-test callback; WindowHitArea::Client without one. | |
| static SDL_Window * | ToSDL (OSWindowHandle h) |
| Converts between handles and SDL windows: a handle is the SDL_Window pointer. | |
| static OSWindowHandle | FromSDL (SDL_Window *w) |
| Converts between handles and SDL windows: a handle is the SDL_Window pointer. | |
Additional Inherited Members | |
| Protected Attributes inherited from tachyon::IWindowBackend | |
| std::function< void()> | m_onWindowMoved |
| Set by SetWindowMovedCallback; a backend calls it when a window moves or resizes. | |
| std::function< WindowHitArea(OSWindowHandle, int2)> | m_hitTest |
| Set by SetHitTestCallback; a backend asks it through HitTestWindow. | |
| GraphicsContext * | m_graphicsContext = nullptr |
| Set by SetGraphicsContext; not owned. | |
The default window backend, on SDL3.
Starts SDL's video subsystem unless it already runs, and then quits SDL again when destroyed.
|
explicit |
Starts SDL video if needed; failing that, logs an error and the backend makes no windows.
|
override |
|
overridevirtual |
Windows are created for graphicsContext->GetAPI(); for a VulkanGraphicsContext this also installs its SDL surface factory.
Reimplemented from tachyon::IWindowBackend.
|
overridevirtual |
Creates a window whose client area is size pixels, placed by the OS.
parentOSHandle is the owner window, or nullptr for a top-level one. Returns nullptr on failure.
Implements tachyon::IWindowBackend.
|
overridevirtual |
Creates a window whose client area is rect (screen pixels); otherwise as the size overload.
Implements tachyon::IWindowBackend.
|
overridevirtual |
Where the window's input goes (see IPlatformInputHandler); not owned, nullptr for none.
Implements tachyon::IWindowBackend.
|
overridevirtual |
Stores the window's context (not owned), for GetWindowContext, for the ID passed with the window's input, and for PollEvents' cleanup.
nullptr clears it.
Implements tachyon::IWindowBackend.
|
overridevirtual |
Queues the window for destruction: the next PollEvents passes its context to cleanup, then destroys it.
False for a handle that isn't one of the backend's windows.
Implements tachyon::IWindowBackend.
|
overridevirtual |
Clears the context pointer stored in the OS window, so PollEvents' cleanup callback gets nullptr instead of double-freeing a context the caller destroys.
Implements tachyon::IWindowBackend.
|
overridevirtual |
True while the handle is a live window of this backend; false once it was destroyed (by code or the user) and for nullptr.
Implements tachyon::IWindowBackend.
|
overridevirtual |
The context attached with AttachContextToWindow, or nullptr.
Implements tachyon::IWindowBackend.
|
overridevirtual |
Raises the window above the others and asks the OS for the input focus.
Implements tachyon::IWindowBackend.
|
overridevirtual |
The backend's window under the mouse, or nullptr.
Implements tachyon::IWindowBackend.
|
overridevirtual |
The window with the keyboard focus, or nullptr when none of the backend's windows has it.
Implements tachyon::IWindowBackend.
|
inlineoverridevirtual |
Goes up whenever keyboard focus moves between windows, or to or from another application; open popups are checked against it.
Implements tachyon::IWindowBackend.
|
overridevirtual |
Handles the OS's pending events, delivering input to the attached handlers.
Then the windows destroyed since the last call (DestroyWindow, or closed by the OS) go: cleanup gets each handle and its context while the window still exists. Runs in UpdateFrame, and again in RecordFrame.
Implements tachyon::IWindowBackend.
|
overridevirtual |
The mouse position in screen pixels (SDL: as of the last PollEvents).
Implements tachyon::IWindowBackend.
|
overridevirtual |
The color of a screen pixel, anywhere on the desktop (an eyedropper); nothing where the platform can't read the screen.
Reimplemented from tachyon::IWindowBackend.
|
overridevirtual |
Whether the OS asked to close a WindowFlags::ConfirmClose window since last asked.
Reimplemented from tachyon::IWindowBackend.
|
overridevirtual |
The mouse buttons held down, wherever the mouse is (SDL: as of the last PollEvents).
Implements tachyon::IWindowBackend.
|
overridevirtual |
The OS's double-click time in milliseconds, or 0 where the platform has none.
Reimplemented from tachyon::IWindowBackend.
|
overridevirtual |
A layered stand-in for window showing what context drew last, at screenRect (screen pixels) and opacity (0 to 1), so the window itself can be hidden or cloaked while it fades in or out.
Returns the stand-in, or 0 where there are none: then the window shows and hides at once.
Reimplemented from tachyon::IWindowBackend.
|
overridevirtual |
Moves a stand-in and sets its opacity.
Reimplemented from tachyon::IWindowBackend.
|
overridevirtual |
Removes a stand-in.
Reimplemented from tachyon::IWindowBackend.
|
overridevirtual |
Whether the OS asks for less motion (animations turned off); false where the platform has no such setting.
Reimplemented from tachyon::IWindowBackend.
|
overridevirtual |
Shows the system cursor for that shape; MouseCursor::None hides the cursor.
The library sets it once per frame.
Implements tachyon::IWindowBackend.
|
overridevirtual |
Where text is being typed in the window (window coordinates), so the IME places its candidate list next to it.
Implements tachyon::IWindowBackend.
|
overridevirtual |
The UI scale the OS asks for in this window: pixel density times the monitor's content scale (1.5 on a 150% display).
0 when unknown.
Implements tachyon::IWindowBackend.
|
overridevirtual |
The window's render target: OS position (for OS compositing) and size in physical pixels.
Implements tachyon::IWindowBackend.
|
overridevirtual |
Presents for a graphics API that swaps through the window (OpenGL).
The library doesn't call it: a Vulkan window context presents itself.
Implements tachyon::IWindowBackend.
|
overridevirtual |
Client area in pixels; {0,0,0,0} while minimized.
Implements tachyon::IWindowBackend.
|
overridevirtual |
The client area's top-left in screen pixels.
Implements tachyon::IWindowBackend.
|
overridevirtual |
The client area's size in pixels; {0,0} while minimized.
Implements tachyon::IWindowBackend.
|
overridevirtual |
Moves and resizes the window so its client area is clientRect (screen pixels); the backend accounts for the frame.
True on success.
Implements tachyon::IWindowBackend.
|
overridevirtual |
Shows or hides the window; hiding doesn't destroy it.
Implements tachyon::IWindowBackend.
|
overridevirtual |
Cloaks a shown window: it takes frames but stays invisible, so it can be drawn before it appears.
False when the backend can't (then the window is hidden until drawn instead).
Reimplemented from tachyon::IWindowBackend.
|
overridevirtual |
Sets the window's state: minimized, maximized, restored or fullscreen.
The default does nothing.
Reimplemented from tachyon::IWindowBackend.
|
overridevirtual |
The window's state as the OS has it now; WindowMode::Normal by default.
Reimplemented from tachyon::IWindowBackend.
|
overridevirtual |
Every monitor, the primary first.
Implements tachyon::IWindowBackend.
|
overridevirtual |
Index into GetMonitors of the monitor holding the screen point pos; 0 (the primary) when no monitor holds it, -1 without monitors.
Implements tachyon::IWindowBackend.
|
overridevirtual |
Index into GetMonitors of the window's monitor; -1 for an unknown window.
Implements tachyon::IWindowBackend.
|
overridevirtual |
A millisecond clock (SDL: since SDL started).
Implements tachyon::IWindowBackend.
|
overridevirtual |
The user's preferred language as a BCP 47 tag ("ja", "en-US"), or empty when the platform doesn't say.
Reimplemented from tachyon::IWindowBackend.
|
overridevirtual |
The OS mouse cursor's size in pixels (its accessibility size at the display's scale), or 0 when the platform doesn't say.
Reimplemented from tachyon::IWindowBackend.
|
overridevirtual |
The OS's own window handle, passed to GraphicsContext::CreateWindowContext (HWND on Windows, NSWindow on macOS, an X11 window or Wayland surface on Linux); nullptr without one.
Implements tachyon::IWindowBackend.
|
inlinestatic |
Converts between handles and SDL windows: a handle is the SDL_Window pointer.
|
inlinestatic |
Converts between handles and SDL windows: a handle is the SDL_Window pointer.
| int2 tachyon::SDLWindowBackend::WindowPointToPixels | ( | SDL_Window * | window, |
| float | x, | ||
| float | y ) const |
A position inside window (OS window coordinates) in screen pixels.
| SDL_Window * tachyon::SDLWindowBackend::ModalBlockerFor | ( | const SDL_Event * | event | ) | const |
The modal window that blocks the event's window (one of ours), or null.