|
libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
|
Abstract base class for the application window and rendering surface. More...
#include <Window.h>
Public Member Functions | |
| Window (std::shared_ptr< Config > config=nullptr) | |
| Window (const std::vector< std::shared_ptr< GuiWindow > > &guiWindows, std::shared_ptr< Config > config=nullptr) | |
| Constructs a Window and pre-registers a list of GUI windows. | |
| Window (std::shared_ptr< Gui > gui, std::shared_ptr< Config > config=nullptr) | |
| Constructs a Window backed by a pre-constructed Gui instance. | |
| Window (std::shared_ptr< Gui > gui, std::shared_ptr< MouseStateManager > mouseStateManager, std::shared_ptr< Config > config=nullptr) | |
| Constructs a Window with both a Gui and a MouseStateManager. | |
| virtual | ~Window () |
| virtual void | Close ()=0 |
| Requests that the window and application close. | |
| virtual void | RunGuiOnly ()=0 |
| Runs a single GUI-only tick without executing game logic. | |
| virtual void | StartFrame ()=0 |
| Begins a new render frame; clears the back buffer and sets up state. | |
| virtual void | EndFrame ()=0 |
| Ends the current render frame and presents it to the display. | |
| virtual bool | IsFrameReady ()=0 |
| Returns true if the renderer is ready to begin a new frame. | |
| virtual void | HandleEvents ()=0 |
| Processes pending OS/input events. | |
| virtual void | SetCursorVisibility (bool visible)=0 |
| Shows or hides the OS mouse cursor over the window. | |
| virtual uint32_t | GetWidth ()=0 |
| Returns the current width of the window client area in pixels. | |
| virtual uint32_t | GetHeight ()=0 |
| Returns the current height of the window client area in pixels. | |
| virtual float | GetAspectRatio ()=0 |
| Returns the current aspect ratio (width / height) of the window. | |
| virtual int32_t | GetPosX ()=0 |
| Returns the X position of the window's top-left corner on the desktop. | |
| virtual int32_t | GetPosY ()=0 |
| Returns the Y position of the window's top-left corner on the desktop. | |
| virtual void | SetMousePos (Coords pos)=0 |
| Moves the mouse cursor to the given window-relative coordinates. | |
| virtual Coords | GetMousePos ()=0 |
| Returns the current mouse cursor position relative to the window. | |
| virtual Coords | GetMouseDelta ()=0 |
| Returns the mouse movement delta since the last frame. | |
| virtual CoordsF | GetMouseWheel ()=0 |
| Returns the mouse wheel scroll delta for the current frame. | |
| virtual bool | GetMouseState (MouseBtn btn)=0 |
| Returns whether the given mouse button is currently pressed. | |
| virtual void | SetMouseCapture (bool capture)=0 |
| Enables or disables mouse capture (relative/locked mouse mode). | |
| virtual bool | IsMouseCaptured ()=0 |
| Returns true if the mouse is currently captured. | |
| virtual uint32_t | GetCurrentRefreshRate ()=0 |
| Returns the display's current refresh rate in Hz. | |
| virtual bool | SupportsWindowedFullscreen ()=0 |
| Returns true if the backend supports a windowed-fullscreen (borderless) mode. | |
| virtual bool | CanDisableVerticalSync ()=0 |
| Returns true if vertical sync can be disabled on this backend. | |
| virtual void | SetResolutionMultiplier (float multiplier)=0 |
| Sets the internal rendering resolution multiplier. | |
| virtual void | SetMsaaLevel (uint32_t value)=0 |
| Sets the MSAA sample count. | |
| virtual void | SetFullscreen (bool isFullscreen)=0 |
| Switches between fullscreen and windowed mode. | |
| virtual bool | IsFullscreen ()=0 |
| Returns true if the window is currently in fullscreen mode. | |
| virtual bool | IsRunning ()=0 |
| Returns true while the window / render loop is running. | |
| virtual const char * | GetKeyName (int32_t scancode)=0 |
| Returns the human-readable name for a keyboard scancode. | |
| virtual uintptr_t | GetGfxFrameBuffer ()=0 |
| Returns a handle to the graphics API framebuffer object. | |
| virtual void | SetCurrentDimensions (uint32_t width, uint32_t height)=0 |
| Sets the window dimensions (size and position) and applies them immediately. | |
| virtual void | SetCurrentDimensions (uint32_t width, uint32_t height, int32_t posX, int32_t posY)=0 |
| Sets the window dimensions and position and applies them immediately. | |
| virtual void | SetCurrentDimensions (bool isFullscreen, uint32_t width, uint32_t height)=0 |
| Switches fullscreen state and sets the window dimensions. | |
| virtual void | SetCurrentDimensions (bool isFullscreen, uint32_t width, uint32_t height, int32_t posX, int32_t posY)=0 |
| Switches fullscreen state and sets the window dimensions and position. | |
| virtual WindowRect | GetPrimaryMonitorRect ()=0 |
| Returns the bounding rectangle of the primary monitor. | |
| int32_t | GetWindowBackend () |
| Returns the current graphics backend identifier. | |
| virtual std::string | GetWindowBackendName () |
| Returns a human-readable name for the current window backend. | |
| std::shared_ptr< std::vector< int32_t > > | GetAvailableWindowBackends () |
| Returns the list of backends available on this platform. | |
| bool | IsAvailableWindowBackend (int32_t backendId) |
| Returns true if the backend with the given ID is available on this platform. | |
| int32_t | GetLastScancode () |
| Returns the scancode of the last key event received. | |
| void | SetLastScancode (int32_t scanCode) |
| Records the most recently received keyboard scancode. | |
| void | ToggleFullscreen () |
| Toggles between fullscreen and windowed mode. | |
| float | GetCurrentAspectRatio () |
| Returns the current aspect ratio, recomputed from GetWidth() / GetHeight(). | |
| void | SaveWindowToConfig () |
| Persists window geometry and backend settings to the Config. | |
| std::shared_ptr< Gui > | GetGui () |
| Returns the GUI overlay layer. | |
| bool | ShouldAutoCaptureMouse () |
| Returns true if the window should automatically capture the mouse when focused. | |
| void | SetAutoCaptureMouse (bool capture) |
| Enables or disables automatic mouse capture on window focus. | |
| bool | ShouldForceCursorVisibility () |
| Returns true if the cursor should always be visible regardless of capture state. | |
| void | SetForceCursorVisibility (bool visible) |
| Forces the cursor to remain visible even when captured. | |
| int32_t | GetFullscreenScancode () |
| Returns the scancode bound to the fullscreen toggle action. | |
| int32_t | GetMouseCaptureScancode () |
| Returns the scancode bound to the mouse-capture toggle action. | |
| void | SetFullscreenScancode (int32_t scancode) |
| Binds a scancode to the fullscreen toggle action. | |
| void | SetMouseCaptureScancode (int32_t scancode) |
| Binds a scancode to the mouse-capture toggle action. | |
| std::shared_ptr< MouseStateManager > | GetMouseStateManager () |
| Returns the MouseStateManager used to track mouse button and position state. | |
Public Member Functions inherited from Ship::Component | |
| Component (const std::string &name, std::shared_ptr< Context > context=nullptr) | |
| Constructs a Component with the given name. | |
| virtual | ~Component () |
| void | Init (const nlohmann::json &initArgs=nlohmann::json::object()) |
| Performs one-time initialization of this component. | |
| bool | IsInitialized () const |
| Returns true once Init() (or MarkInitialized()) has completed successfully. | |
| const std::string & | GetName () const |
| Returns the name of this Component. | |
| std::string | ToString () const |
| Returns a human-readable string representation (e.g. "Name (id)"). | |
| std::string | ToTreeString (int depth=0) const |
| Returns a human-readable tree representation of this component and its children. | |
| operator std::string () const | |
| Conversion operator to std::string; equivalent to ToString(). | |
| ParentComponentList & | GetParents () |
| Returns a mutable reference to the parent list. | |
| const ParentComponentList & | GetParents () const |
| Returns a const reference to the parent list. | |
| ComponentList & | GetChildren () |
| Returns a mutable reference to the child list. | |
| const ComponentList & | GetChildren () const |
| Returns a const reference to the child list. | |
| virtual std::shared_ptr< Component > | TryGetSharedComponent () noexcept |
| Returns a shared_ptr to this Component when available, otherwise nullptr. | |
| virtual std::shared_ptr< Component > | GetSharedComponent () |
| Returns a shared_ptr to this Component via the correct enable_shared_from_this base. | |
| template<typename T > | |
| bool | HasInChildren () const |
| Checks whether any descendant Component matches type T via BFS. | |
| template<typename T > | |
| std::shared_ptr< T > | GetFirstInChildren () const |
| Returns the first descendant that matches type T via BFS. | |
| template<typename T > | |
| std::shared_ptr< std::vector< std::shared_ptr< T > > > | GetInChildren () const |
| Returns all descendants that match type T via BFS. | |
| template<typename T > | |
| bool | HasInParents () const |
| Checks whether any ancestor Component matches type T via BFS. | |
| template<typename T > | |
| std::shared_ptr< T > | GetFirstInParents () const |
| Returns the first ancestor that matches type T via BFS. | |
| template<typename T > | |
| std::shared_ptr< std::vector< std::shared_ptr< T > > > | GetInParents () const |
| Returns all ancestors that match type T via BFS. | |
Public Member Functions inherited from Ship::Part | |
| Part () | |
| Constructs a Part and assigns it a unique ID. | |
| Part (std::shared_ptr< Context > context) | |
| Constructs a Part with an explicit Context reference and unique ID. | |
| virtual | ~Part ()=default |
| uint64_t | GetId () const |
| Returns the unique identifier for this Part. | |
| bool | operator== (const Part &other) const |
| Compares two Parts for equality by their unique IDs. | |
| std::shared_ptr< Context > | GetContext () const |
| Returns the Context this Part belongs to, or nullptr if unset. | |
| void | SetContext (std::shared_ptr< Context > ctx) |
| Sets the Context this Part belongs to. | |
Protected Member Functions | |
| void | OnInit (const nlohmann::json &initArgs) override |
| Caches this Window on the MouseStateManager. | |
| void | SetWindowBackend (int32_t backend) |
| Records the active graphics backend. Called by subclass constructors. | |
| void | AddAvailableWindowBackend (int32_t backend) |
| Adds a backend to the list of backends available on this platform. | |
| int32_t | GetSavedWindowBackend () |
| Reads the saved window backend identifier from the config. | |
| std::shared_ptr< Config > | GetConfig () const |
| Returns the cached Config component after validating it is ready for use. | |
Protected Member Functions inherited from Ship::Component | |
| void | MarkInitialized () |
| Marks this component as initialized without going through Init(). | |
| template<typename T > | |
| std::shared_ptr< T > | RequireDependency (const std::shared_ptr< T > &dependency, const std::string &dependencyName) const |
| Returns a cached dependency after validating it exists and is initialized. | |
Protected Member Functions inherited from Ship::Part | |
| virtual void | OnAdded (bool forced) |
| Called after this Part has been added to a PartList. | |
| virtual void | OnRemoved (bool forced) |
| Called after this Part has been removed from a PartList. | |
Friends | |
| class | Context |
Abstract base class for the application window and rendering surface.
Window owns the platform-specific window handle, the render loop, and the ImGui/GUI layer. Concrete subclasses (e.g. an SDL+OpenGL window) implement the pure virtual methods to integrate with specific graphics APIs.
Required dependencies (constructor-injected):
The window is added to Context as a child Component and is accessible via Context::GetChildren().GetFirst<Window>().
|
explicit |
| Ship::Window::Window | ( | std::shared_ptr< Gui > | gui, |
| std::shared_ptr< MouseStateManager > | mouseStateManager, | ||
| std::shared_ptr< Config > | config = nullptr |
||
| ) |
Constructs a Window with both a Gui and a MouseStateManager.
| gui | Gui layer to use. |
| mouseStateManager | Mouse state tracker to use. |
|
virtual |
|
protected |
Adds a backend to the list of backends available on this platform.
| backend | Backend ID to mark as available. |
|
pure virtual |
Returns true if vertical sync can be disabled on this backend.
Implemented in Fast::Fast3dWindow.
|
pure virtual |
Requests that the window and application close.
Implemented in Fast::Fast3dWindow.
|
pure virtual |
Ends the current render frame and presents it to the display.
Implemented in Fast::Fast3dWindow.
|
pure virtual |
Returns the current aspect ratio (width / height) of the window.
Implemented in Fast::Fast3dWindow.
| std::shared_ptr< std::vector< int32_t > > Ship::Window::GetAvailableWindowBackends | ( | ) |
Returns the list of backends available on this platform.
|
protected |
Returns the cached Config component after validating it is ready for use.
| float Ship::Window::GetCurrentAspectRatio | ( | ) |
Returns the current aspect ratio, recomputed from GetWidth() / GetHeight().
|
pure virtual |
Returns the display's current refresh rate in Hz.
Implemented in Fast::Fast3dWindow.
| int32_t Ship::Window::GetFullscreenScancode | ( | ) |
Returns the scancode bound to the fullscreen toggle action.
|
pure virtual |
Returns a handle to the graphics API framebuffer object.
Implemented in Fast::Fast3dWindow.
| std::shared_ptr< Gui > Ship::Window::GetGui | ( | ) |
Returns the GUI overlay layer.
|
pure virtual |
Returns the current height of the window client area in pixels.
Implemented in Fast::Fast3dWindow.
|
pure virtual |
Returns the human-readable name for a keyboard scancode.
| scancode | Platform scancode value. |
Implemented in Fast::Fast3dWindow.
| int32_t Ship::Window::GetLastScancode | ( | ) |
Returns the scancode of the last key event received.
| int32_t Ship::Window::GetMouseCaptureScancode | ( | ) |
Returns the scancode bound to the mouse-capture toggle action.
|
pure virtual |
Returns the mouse movement delta since the last frame.
Implemented in Fast::Fast3dWindow.
|
pure virtual |
Returns the current mouse cursor position relative to the window.
Implemented in Fast::Fast3dWindow.
|
pure virtual |
Returns whether the given mouse button is currently pressed.
| btn | Mouse button to query. |
Implemented in Fast::Fast3dWindow.
| std::shared_ptr< MouseStateManager > Ship::Window::GetMouseStateManager | ( | ) |
Returns the MouseStateManager used to track mouse button and position state.
|
pure virtual |
Returns the mouse wheel scroll delta for the current frame.
Implemented in Fast::Fast3dWindow.
|
pure virtual |
Returns the X position of the window's top-left corner on the desktop.
Implemented in Fast::Fast3dWindow.
|
pure virtual |
Returns the Y position of the window's top-left corner on the desktop.
Implemented in Fast::Fast3dWindow.
|
pure virtual |
Returns the bounding rectangle of the primary monitor.
Implemented in Fast::Fast3dWindow.
|
protected |
Reads the saved window backend identifier from the config.
Reads Window.Backend.Id, validates it against the available backends, and falls back to the first registered backend if the saved value is not available.
|
pure virtual |
Returns the current width of the window client area in pixels.
Implemented in Fast::Fast3dWindow.
| int32_t Ship::Window::GetWindowBackend | ( | ) |
Returns the current graphics backend identifier.
See the window backend ID convention in the comment above this class: negative = no backend available, 0 = no backend in use, positive = defined by subclass.
|
virtual |
Returns a human-readable name for the current window backend.
The base implementation returns an empty string. Concrete subclasses (e.g. Fast3dWindow) override this to return backend-specific names such as "OpenGL", "Metal", or "DirectX 11".
Reimplemented in Fast::Fast3dWindow.
|
pure virtual |
Processes pending OS/input events.
Implemented in Fast::Fast3dWindow.
| bool Ship::Window::IsAvailableWindowBackend | ( | int32_t | backendId | ) |
Returns true if the backend with the given ID is available on this platform.
| backendId | Backend identifier to check. |
|
pure virtual |
Returns true if the renderer is ready to begin a new frame.
Implemented in Fast::Fast3dWindow.
|
pure virtual |
Returns true if the window is currently in fullscreen mode.
Implemented in Fast::Fast3dWindow.
|
pure virtual |
Returns true if the mouse is currently captured.
Implemented in Fast::Fast3dWindow.
|
pure virtual |
Returns true while the window / render loop is running.
Implemented in Fast::Fast3dWindow.
|
overrideprotectedvirtual |
Caches this Window on the MouseStateManager.
Reimplemented from Ship::Component.
|
pure virtual |
Runs a single GUI-only tick without executing game logic.
Implemented in Fast::Fast3dWindow.
| void Ship::Window::SaveWindowToConfig | ( | ) |
Persists window geometry and backend settings to the Config.
| void Ship::Window::SetAutoCaptureMouse | ( | bool | capture | ) |
Enables or disables automatic mouse capture on window focus.
| capture | true to enable auto-capture. |
|
pure virtual |
Switches fullscreen state and sets the window dimensions.
| isFullscreen | true to enter fullscreen, false for windowed. |
| width | New client-area width in pixels. |
| height | New client-area height in pixels. |
Implemented in Fast::Fast3dWindow.
|
pure virtual |
Switches fullscreen state and sets the window dimensions and position.
| isFullscreen | true to enter fullscreen, false for windowed. |
| width | New client-area width in pixels. |
| height | New client-area height in pixels. |
| posX | Left edge of the window in screen coordinates. |
| posY | Top edge of the window in screen coordinates. |
Implemented in Fast::Fast3dWindow.
|
pure virtual |
Sets the window dimensions (size and position) and applies them immediately.
| width | New client-area width in pixels. |
| height | New client-area height in pixels. |
Implemented in Fast::Fast3dWindow.
|
pure virtual |
Sets the window dimensions and position and applies them immediately.
| width | New client-area width in pixels. |
| height | New client-area height in pixels. |
| posX | Left edge of the window in screen coordinates. |
| posY | Top edge of the window in screen coordinates. |
Implemented in Fast::Fast3dWindow.
|
pure virtual |
Shows or hides the OS mouse cursor over the window.
| visible | true to show, false to hide. |
Implemented in Fast::Fast3dWindow.
| void Ship::Window::SetForceCursorVisibility | ( | bool | visible | ) |
Forces the cursor to remain visible even when captured.
| visible | true to force visibility. |
|
pure virtual |
Switches between fullscreen and windowed mode.
| isFullscreen | true to enter fullscreen, false to return to windowed. |
Implemented in Fast::Fast3dWindow.
| void Ship::Window::SetFullscreenScancode | ( | int32_t | scancode | ) |
Binds a scancode to the fullscreen toggle action.
| scancode | Platform scancode. |
| void Ship::Window::SetLastScancode | ( | int32_t | scanCode | ) |
Records the most recently received keyboard scancode.
| scanCode | Platform scancode value. |
|
pure virtual |
Enables or disables mouse capture (relative/locked mouse mode).
| capture | true to capture, false to release. |
Implemented in Fast::Fast3dWindow.
| void Ship::Window::SetMouseCaptureScancode | ( | int32_t | scancode | ) |
Binds a scancode to the mouse-capture toggle action.
| scancode | Platform scancode. |
|
pure virtual |
Moves the mouse cursor to the given window-relative coordinates.
| pos | Target position in window pixels. |
Implemented in Fast::Fast3dWindow.
|
pure virtual |
Sets the MSAA sample count.
| value | Number of MSAA samples (e.g. 1, 2, 4, 8). |
Implemented in Fast::Fast3dWindow.
|
pure virtual |
Sets the internal rendering resolution multiplier.
| multiplier | Values > 1 super-sample; < 1 sub-sample. |
Implemented in Fast::Fast3dWindow.
|
protected |
Records the active graphics backend. Called by subclass constructors.
| backend | The backend ID in use. |
| bool Ship::Window::ShouldAutoCaptureMouse | ( | ) |
Returns true if the window should automatically capture the mouse when focused.
| bool Ship::Window::ShouldForceCursorVisibility | ( | ) |
Returns true if the cursor should always be visible regardless of capture state.
|
pure virtual |
Begins a new render frame; clears the back buffer and sets up state.
Implemented in Fast::Fast3dWindow.
|
pure virtual |
Returns true if the backend supports a windowed-fullscreen (borderless) mode.
Implemented in Fast::Fast3dWindow.
| void Ship::Window::ToggleFullscreen | ( | ) |
Toggles between fullscreen and windowed mode.
|
friend |