SDL subsystem installed alongside an Application. More...
#include <sdlsubsystem.h>
Public Member Functions | |
| SdlSubsystem () | |
| Initialises SDL and installs the event-loop bridge. | |
| ~SdlSubsystem () | |
| Destructor. Removes I/O source, closes pipe, calls SDL_Quit. | |
| SdlSubsystem (const SdlSubsystem &)=delete | |
| SdlSubsystem & | operator= (const SdlSubsystem &)=delete |
| SDLEventPump & | eventPump () |
| Returns the subsystem's SDLEventPump. | |
| EventLoop * | eventLoop () |
| Returns the main EventLoop the subsystem is bound to. | |
| Widget * | focusedWidget () const |
Returns the widget that currently receives keyboard input, or nullptr if none is set. | |
| void | setFocusedWidget (Widget *widget) |
| Sets the widget that receives keyboard input. | |
Static Public Member Functions | |
| static SdlSubsystem * | instance () |
| Returns the active SdlSubsystem instance. | |
SDL subsystem installed alongside an Application.
Owns the SDL library state (init / quit), the SDLEventPump, and the SDL-to-EventLoop bridge (a self-pipe fed by SDL_AddEventWatch and registered as an EventLoop::addIoSource). Stack-construct one after Application:
Multiple subsystems can coexist in the same process — e.g. a program that wants both a graphical SDL window and a text-mode TUI can construct a TuiSubsystem alongside this one and both will install their I/O sources on the same Application main EventLoop.
SdlSubsystem must be constructed, used, and destroyed on the thread that owns the bound EventLoop (typically the main thread). SDL's video subsystem itself requires that windows and renderers be created and operated from the same thread that initialised SDL — this class enforces that contract by binding to that thread at construction. Cross-thread interaction is supported only through EventLoop::postCallable / ObjectBase signal/slot dispatch. | promeki::SdlSubsystem::SdlSubsystem | ( | ) |
Initialises SDL and installs the event-loop bridge.
Requires an Application to have been constructed before this object. Calls SDL_Init with video / audio / event subsystems, creates the self-pipe used to wake the main EventLoop on SDL events, and registers the watcher + I/O source.
|
inline |
Returns the main EventLoop the subsystem is bound to.
Convenience accessor used by SDL-side code that wants to post a callable onto the main loop (e.g. SDL player sinks marshalling a resize to the main thread). Same as Application::mainEventLoop().
|
inline |
Returns the subsystem's SDLEventPump.
SDLWindow uses this to register itself for event routing.
|
inlinestatic |
Returns the active SdlSubsystem instance.
nullptr.
|
inline |
Sets the widget that receives keyboard input.
Key events arriving from SDL are delivered to widget first; if the widget does not accept the event, delivery walks up the parent chain until a handler accepts or the chain ends.
Passing nullptr clears focus — key events with no focused widget fall back to the receiving window.
Managing Widget::setFocused on the old / new widget is the caller's responsibility.
| widget | The new focused widget, or nullptr. |