libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
Ship::Gui Class Reference

Owns and drives the ImGui context, all registered GuiWindows, and texture management. More...

#include <Gui.h>

Inheritance diagram for Ship::Gui:
[legend]
Collaboration diagram for Ship::Gui:
[legend]

Public Member Functions

 Gui ()
 Constructs a Gui with no pre-registered windows.
 
 Gui (const std::vector< std::shared_ptr< GuiWindow > > &guiWindows, std::shared_ptr< Context > context=nullptr, std::shared_ptr< ConsoleVariable > consoleVariable=nullptr, std::shared_ptr< Window > window=nullptr, std::shared_ptr< Config > config=nullptr, std::shared_ptr< ResourceManager > resourceManager=nullptr, std::shared_ptr< GameOverlay > gameOverlay=nullptr)
 Constructs a Gui and pre-registers a list of GuiWindows.
 
virtual ~Gui ()
 
void OnInit (const nlohmann::json &initArgs) override
 Initialises the ImGui context and the appropriate backend renderer.
 
void StartDraw ()
 Begins a new ImGui frame.
 
void EndDraw ()
 Finalises the ImGui frame and submits draw data to the renderer.
 
void SaveConsoleVariablesNextFrame ()
 Schedules a CVar save to disk at the end of the current frame.
 
virtual bool SupportsViewports ()
 Returns true if the ImGui multi-viewport / docking feature is supported by the current backend.
 
ImGuiID GetMainGameWindowID ()
 Returns the ImGui ID of the main game viewport window.
 
void AddGuiWindow (std::shared_ptr< GuiWindow > guiWindow)
 Adds a GuiWindow to the draw loop.
 
std::shared_ptr< GuiWindowGetGuiWindow (const std::string &name)
 Returns the GuiWindow registered with the given name, or nullptr.
 
void RemoveGuiWindow (std::shared_ptr< GuiWindow > guiWindow)
 Removes a specific GuiWindow from the draw loop.
 
void RemoveGuiWindow (const std::string &name)
 Removes the GuiWindow with the given name from the draw loop.
 
void RemoveAllGuiWindows ()
 Removes all registered GuiWindows from the draw loop.
 
std::shared_ptr< GameOverlayGetGameOverlay ()
 Returns the GameOverlay instance used for on-screen text and notifications.
 
void SetMenuBar (std::shared_ptr< GuiMenuBar > menuBar)
 Sets the main application menu bar.
 
std::shared_ptr< GuiMenuBarGetMenuBar ()
 Returns the registered menu bar, or nullptr if none has been set.
 
void SetMenu (std::shared_ptr< GuiWindow > menu)
 Sets an optional full-screen "menu" GuiWindow (e.g. a title-screen or pause menu).
 
std::shared_ptr< GuiWindowGetMenu ()
 Returns the registered menu window, or nullptr if none has been set.
 
bool GetMenuOrMenubarVisible ()
 Returns true if the menu bar or the full-screen menu window is currently visible.
 
bool IsMouseOverAnyGuiItem ()
 Returns true if the mouse cursor is currently over any ImGui item.
 
bool IsMouseOverActivePopup ()
 Returns true if the mouse cursor is over an active ImGui popup.
 
bool GamepadNavigationEnabled ()
 Returns true if ImGui gamepad navigation is enabled.
 
void BlockGamepadNavigation ()
 Disables ImGui gamepad navigation (allows the game to use gamepad input).
 
void UnblockGamepadNavigation ()
 Re-enables ImGui gamepad navigation.
 
virtual void RefreshImGuiGamepads ()
 Re-binds the ImGui platform backend's gamepad list to the currently connected controllers. Called once at init and on controller add/remove so it is not re-evaluated per frame. The base implementation is a no-op.
 
void ShutDownImGui (Ship::Window *window)
 Shuts down the ImGui context and releases backend resources.
 
- 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().
 
ParentComponentListGetParents ()
 Returns a mutable reference to the parent list.
 
const ParentComponentListGetParents () const
 Returns a const reference to the parent list.
 
ComponentListGetChildren ()
 Returns a mutable reference to the child list.
 
const ComponentListGetChildren () const
 Returns a const reference to the child list.
 
virtual std::shared_ptr< ComponentTryGetSharedComponent () noexcept
 Returns a shared_ptr to this Component when available, otherwise nullptr.
 
virtual std::shared_ptr< ComponentGetSharedComponent ()
 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< ContextGetContext () 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 StartFrame ()
 Calls ImGui::NewFrame() after processing backend-specific input.
 
void EndFrame ()
 Calls ImGui::Render() and submits draw data to the backend.
 
virtual void DrawFloatingWindows ()
 Draws all registered floating GuiWindow instances. The base implementation is a no-op. Override in subclasses to provide viewport support.
 
virtual void DrawMenu ()
 Draws the menu bar and/or full-screen menu window. Override to add custom menus.
 
virtual void DrawGame ()
 Renders the game viewport inside the main docking space. The base implementation is a no-op. Override in subclasses to render the game framebuffer.
 
virtual void CalculateGameViewport ()
 Recalculates the game viewport rect to account for the menu bar and window size. The base implementation is a no-op. Override in subclasses to set up the game viewport.
 
virtual void ImGuiBackendNewFrame ()
 Calls the appropriate ImGui backend New Frame function (DX11 / GL / Metal). The base implementation is a no-op.
 
virtual void ImGuiWMNewFrame ()
 Calls ImGui_ImplSDL2_NewFrame() or the platform equivalent. The base implementation is a no-op.
 
virtual void ImGuiWMInit ()
 Initialises the platform/window-manager ImGui backend. The base implementation is a no-op.
 
virtual void ImGuiWMShutdown ()
 Shuts down the platform/window-manager ImGui backend. The base implementation is a no-op.
 
virtual void ImGuiBackendInit ()
 Initialises the renderer ImGui backend (DX11 / OpenGL / Metal). The base implementation is a no-op.
 
virtual void ImGuiBackendShutdown ()
 Shuts down the renderer ImGui backend. The base implementation is a no-op.
 
virtual void ImGuiRenderDrawData (ImDrawData *data)
 Submits the ImGui draw data to the active graphics backend. The base implementation is a no-op.
 
void CheckSaveCvars ()
 Flushes CVars to disk if SaveConsoleVariablesNextFrame() was called.
 
void HandleMouseCapture ()
 Updates mouse capture state based on window focus and UI interaction.
 
- 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.
 

Protected Attributes

ImVec2 mTemporaryWindowPos
 Scratchpad position used when repositioning windows.
 
ImGuiIO * mImGuiIo
 Pointer to the active ImGuiIO context.
 
std::map< std::string, std::shared_ptr< GuiWindow > > mGuiWindows
 Registered window map (name → window).
 

Detailed Description

Owns and drives the ImGui context, all registered GuiWindows, and texture management.

Gui is the central hub for the in-game overlay system. It:

  • Initialises the ImGui backend for the active graphics API.
  • Maintains a registry of named GuiWindow instances and draws them each frame.
  • Owns the GameOverlay, GuiMenuBar, and optional full-screen "menu" window.

GuiWindow children are accessible via GetChildren().GetFirst<T>().

Obtain the instance from Window::GetGui().

Constructor & Destructor Documentation

◆ Gui() [1/2]

Ship::Gui::Gui ( )

Constructs a Gui with no pre-registered windows.

◆ Gui() [2/2]

Ship::Gui::Gui ( const std::vector< std::shared_ptr< GuiWindow > > &  guiWindows,
std::shared_ptr< Context context = nullptr,
std::shared_ptr< ConsoleVariable consoleVariable = nullptr,
std::shared_ptr< Window window = nullptr,
std::shared_ptr< Config config = nullptr,
std::shared_ptr< ResourceManager resourceManager = nullptr,
std::shared_ptr< GameOverlay gameOverlay = nullptr 
)

Constructs a Gui and pre-registers a list of GuiWindows.

Parameters
guiWindowsWindows to add before Init() is called.

◆ ~Gui()

virtual Ship::Gui::~Gui ( )
virtual

Member Function Documentation

◆ AddGuiWindow()

void Ship::Gui::AddGuiWindow ( std::shared_ptr< GuiWindow guiWindow)

Adds a GuiWindow to the draw loop.

Parameters
guiWindowWindow to register. Must have a unique name.

◆ BlockGamepadNavigation()

void Ship::Gui::BlockGamepadNavigation ( )

Disables ImGui gamepad navigation (allows the game to use gamepad input).

◆ CalculateGameViewport()

virtual void Ship::Gui::CalculateGameViewport ( )
protectedvirtual

Recalculates the game viewport rect to account for the menu bar and window size. The base implementation is a no-op. Override in subclasses to set up the game viewport.

Reimplemented in Fast::Fast3dGui.

◆ CheckSaveCvars()

void Ship::Gui::CheckSaveCvars ( )
protected

Flushes CVars to disk if SaveConsoleVariablesNextFrame() was called.

◆ DrawFloatingWindows()

virtual void Ship::Gui::DrawFloatingWindows ( )
protectedvirtual

Draws all registered floating GuiWindow instances. The base implementation is a no-op. Override in subclasses to provide viewport support.

Reimplemented in Fast::Fast3dGui.

◆ DrawGame()

virtual void Ship::Gui::DrawGame ( )
protectedvirtual

Renders the game viewport inside the main docking space. The base implementation is a no-op. Override in subclasses to render the game framebuffer.

Reimplemented in Fast::Fast3dGui.

◆ DrawMenu()

virtual void Ship::Gui::DrawMenu ( )
protectedvirtual

Draws the menu bar and/or full-screen menu window. Override to add custom menus.

◆ EndDraw()

void Ship::Gui::EndDraw ( )

Finalises the ImGui frame and submits draw data to the renderer.

Must be called once per frame after all ImGui draw calls.

◆ EndFrame()

void Ship::Gui::EndFrame ( )
protected

Calls ImGui::Render() and submits draw data to the backend.

◆ GamepadNavigationEnabled()

bool Ship::Gui::GamepadNavigationEnabled ( )

Returns true if ImGui gamepad navigation is enabled.

◆ GetGameOverlay()

std::shared_ptr< GameOverlay > Ship::Gui::GetGameOverlay ( )

Returns the GameOverlay instance used for on-screen text and notifications.

◆ GetGuiWindow()

std::shared_ptr< GuiWindow > Ship::Gui::GetGuiWindow ( const std::string &  name)

Returns the GuiWindow registered with the given name, or nullptr.

Parameters
nameName passed to the GuiWindow constructor.

◆ GetMainGameWindowID()

ImGuiID Ship::Gui::GetMainGameWindowID ( )

Returns the ImGui ID of the main game viewport window.

Useful for docking other windows relative to the game view.

◆ GetMenu()

std::shared_ptr< GuiWindow > Ship::Gui::GetMenu ( )

Returns the registered menu window, or nullptr if none has been set.

◆ GetMenuBar()

std::shared_ptr< GuiMenuBar > Ship::Gui::GetMenuBar ( )

Returns the registered menu bar, or nullptr if none has been set.

◆ GetMenuOrMenubarVisible()

bool Ship::Gui::GetMenuOrMenubarVisible ( )

Returns true if the menu bar or the full-screen menu window is currently visible.

◆ HandleMouseCapture()

void Ship::Gui::HandleMouseCapture ( )
protected

Updates mouse capture state based on window focus and UI interaction.

◆ ImGuiBackendInit()

virtual void Ship::Gui::ImGuiBackendInit ( )
protectedvirtual

Initialises the renderer ImGui backend (DX11 / OpenGL / Metal). The base implementation is a no-op.

Reimplemented in Fast::Fast3dGui.

◆ ImGuiBackendNewFrame()

virtual void Ship::Gui::ImGuiBackendNewFrame ( )
protectedvirtual

Calls the appropriate ImGui backend New Frame function (DX11 / GL / Metal). The base implementation is a no-op.

Reimplemented in Fast::Fast3dGui.

◆ ImGuiBackendShutdown()

virtual void Ship::Gui::ImGuiBackendShutdown ( )
protectedvirtual

Shuts down the renderer ImGui backend. The base implementation is a no-op.

Reimplemented in Fast::Fast3dGui.

◆ ImGuiRenderDrawData()

virtual void Ship::Gui::ImGuiRenderDrawData ( ImDrawData *  data)
protectedvirtual

Submits the ImGui draw data to the active graphics backend. The base implementation is a no-op.

Parameters
dataDraw data produced by ImGui::Render().

Reimplemented in Fast::Fast3dGui.

◆ ImGuiWMInit()

virtual void Ship::Gui::ImGuiWMInit ( )
protectedvirtual

Initialises the platform/window-manager ImGui backend. The base implementation is a no-op.

Reimplemented in Fast::Fast3dGui.

◆ ImGuiWMNewFrame()

virtual void Ship::Gui::ImGuiWMNewFrame ( )
protectedvirtual

Calls ImGui_ImplSDL2_NewFrame() or the platform equivalent. The base implementation is a no-op.

Reimplemented in Fast::Fast3dGui.

◆ ImGuiWMShutdown()

virtual void Ship::Gui::ImGuiWMShutdown ( )
protectedvirtual

Shuts down the platform/window-manager ImGui backend. The base implementation is a no-op.

Reimplemented in Fast::Fast3dGui.

◆ IsMouseOverActivePopup()

bool Ship::Gui::IsMouseOverActivePopup ( )

Returns true if the mouse cursor is over an active ImGui popup.

◆ IsMouseOverAnyGuiItem()

bool Ship::Gui::IsMouseOverAnyGuiItem ( )

Returns true if the mouse cursor is currently over any ImGui item.

◆ OnInit()

void Ship::Gui::OnInit ( const nlohmann::json &  initArgs)
overridevirtual

Initialises the ImGui context and the appropriate backend renderer.

Reimplemented from Ship::Component.

◆ RefreshImGuiGamepads()

virtual void Ship::Gui::RefreshImGuiGamepads ( )
virtual

Re-binds the ImGui platform backend's gamepad list to the currently connected controllers. Called once at init and on controller add/remove so it is not re-evaluated per frame. The base implementation is a no-op.

Reimplemented in Fast::Fast3dGui.

◆ RemoveAllGuiWindows()

void Ship::Gui::RemoveAllGuiWindows ( )

Removes all registered GuiWindows from the draw loop.

◆ RemoveGuiWindow() [1/2]

void Ship::Gui::RemoveGuiWindow ( const std::string &  name)

Removes the GuiWindow with the given name from the draw loop.

Parameters
nameName of the window to remove.

◆ RemoveGuiWindow() [2/2]

void Ship::Gui::RemoveGuiWindow ( std::shared_ptr< GuiWindow guiWindow)

Removes a specific GuiWindow from the draw loop.

Parameters
guiWindowWindow to remove.

◆ SaveConsoleVariablesNextFrame()

void Ship::Gui::SaveConsoleVariablesNextFrame ( )

Schedules a CVar save to disk at the end of the current frame.

Calling this multiple times in the same frame is safe — the save occurs only once.

◆ SetMenu()

void Ship::Gui::SetMenu ( std::shared_ptr< GuiWindow menu)

Sets an optional full-screen "menu" GuiWindow (e.g. a title-screen or pause menu).

Parameters
menuGuiWindow to draw as the menu overlay.

◆ SetMenuBar()

void Ship::Gui::SetMenuBar ( std::shared_ptr< GuiMenuBar menuBar)

Sets the main application menu bar.

Parameters
menuBarGuiMenuBar to render at the top of the screen each frame.

◆ ShutDownImGui()

void Ship::Gui::ShutDownImGui ( Ship::Window window)

Shuts down the ImGui context and releases backend resources.

Parameters
windowPointer to the Window whose backend context should be torn down.

◆ StartDraw()

void Ship::Gui::StartDraw ( )

Begins a new ImGui frame.

Must be called once per frame before any ImGui draw calls. Calls ImGui::NewFrame() after processing input via the backend.

◆ StartFrame()

void Ship::Gui::StartFrame ( )
protected

Calls ImGui::NewFrame() after processing backend-specific input.

◆ SupportsViewports()

virtual bool Ship::Gui::SupportsViewports ( )
virtual

Returns true if the ImGui multi-viewport / docking feature is supported by the current backend.

The base implementation returns false. Concrete subclasses (e.g. Fast3dGui) override this to report actual backend capabilities.

Reimplemented in Fast::Fast3dGui.

◆ UnblockGamepadNavigation()

void Ship::Gui::UnblockGamepadNavigation ( )

Re-enables ImGui gamepad navigation.

Member Data Documentation

◆ mGuiWindows

std::map<std::string, std::shared_ptr<GuiWindow> > Ship::Gui::mGuiWindows
protected

Registered window map (name → window).

◆ mImGuiIo

ImGuiIO* Ship::Gui::mImGuiIo
protected

Pointer to the active ImGuiIO context.

◆ mTemporaryWindowPos

ImVec2 Ship::Gui::mTemporaryWindowPos
protected

Scratchpad position used when repositioning windows.


The documentation for this class was generated from the following file: