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

Concrete Gui subclass for the Fast3D rendering backend. More...

#include <Fast3dGui.h>

Inheritance diagram for Fast::Fast3dGui:
[legend]
Collaboration diagram for Fast::Fast3dGui:
[legend]

Public Member Functions

 Fast3dGui ()
 
 Fast3dGui (std::vector< std::shared_ptr< Ship::GuiWindow > > guiWindows)
 
 ~Fast3dGui () override=default
 
bool SupportsViewports () override
 Returns true if the ImGui multi-viewport / docking feature is supported by the current backend.
 
void Init (GuiWindowInitData windowImpl)
 Initialises the ImGui context with the given backend-specific handles.
 
void HandleWindowEvents (Fast::WindowEvent event)
 Forwards a platform window event to the active ImGui backend.
 
void LoadGuiTexture (const std::string &name, const std::string &path, const ImVec4 &tint)
 Loads an image from an archive path and caches it under the given name.
 
bool HasTextureByName (const std::string &name)
 Returns true if a texture with the given name is already cached.
 
void LoadGuiTexture (const std::string &name, const Fast::Texture &tex, const ImVec4 &tint)
 Uploads a Fast::Texture object to the GPU and caches it under name.
 
void UnloadTexture (const std::string &name)
 Removes the texture with the given name from the cache and frees GPU resources.
 
ImTextureID GetTextureByName (const std::string &name)
 Returns the ImGui texture handle for the given cache key.
 
ImVec2 GetTextureSize (const std::string &name)
 Returns the pixel dimensions of the cached texture.
 
void LoadTextureFromRawImage (const std::string &name, const std::string &path)
 Loads a raw image file from the filesystem (not the archive) and caches it.
 
void LoadTextureFromResource (const std::string &name, std::shared_ptr< Ship::GuiTexture > texture)
 Uploads a pre-loaded GuiTexture resource to the GPU and caches it.
 
void RefreshImGuiGamepads () override
 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.
 
- Public Member Functions inherited from Ship::Gui
 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.
 
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.
 
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 ImGuiWMInit () override
 Initialises the platform/window-manager ImGui backend. The base implementation is a no-op.
 
void ImGuiWMShutdown () override
 Shuts down the platform/window-manager ImGui backend. The base implementation is a no-op.
 
void ImGuiBackendInit () override
 Initialises the renderer ImGui backend (DX11 / OpenGL / Metal). The base implementation is a no-op.
 
void ImGuiBackendShutdown () override
 Shuts down the renderer ImGui backend. The base implementation is a no-op.
 
void ImGuiBackendNewFrame () override
 Calls the appropriate ImGui backend New Frame function (DX11 / GL / Metal). The base implementation is a no-op.
 
void ImGuiWMNewFrame () override
 Calls ImGui_ImplSDL2_NewFrame() or the platform equivalent. The base implementation is a no-op.
 
void ImGuiRenderDrawData (ImDrawData *data) override
 Submits the ImGui draw data to the active graphics backend. The base implementation is a no-op.
 
void DrawFloatingWindows () override
 Draws all registered floating GuiWindow instances. The base implementation is a no-op. Override in subclasses to provide viewport support.
 
void CalculateGameViewport () override
 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.
 
void DrawGame () override
 Renders the game viewport inside the main docking space. The base implementation is a no-op. Override in subclasses to render the game framebuffer.
 
ImTextureID GetTextureById (int32_t id)
 Returns the ImTextureID for a texture identified by its integer ID.
 
- Protected Member Functions inherited from Ship::Gui
void StartFrame ()
 Calls ImGui::NewFrame() after processing backend-specific input.
 
void EndFrame ()
 Calls ImGui::Render() and submits draw data to the backend.
 
virtual void DrawMenu ()
 Draws the menu bar and/or full-screen menu window. Override to add custom menus.
 
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

std::weak_ptr< InterpretermInterpreter
 Weak reference to the Fast3D scripting interpreter.
 
GuiWindowInitData mImpl
 Backend-specific window/context handles passed to Init().
 
std::shared_ptr< Ship::WindowmWindow
 Cached Window component.
 
std::shared_ptr< Ship::ConsoleVariablemConsoleVariables
 Cached ConsoleVariable component.
 
std::shared_ptr< Ship::ResourceManagermResourceManager
 Cached ResourceManager component.
 
- Protected Attributes inherited from Ship::Gui
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

Concrete Gui subclass for the Fast3D rendering backend.

Overrides the virtual ImGui backend methods defined by Ship::Gui with implementations that dispatch to the appropriate platform/renderer backend (SDL+OpenGL, SDL+Metal, or DXGI+DX11) based on the active WindowBackend.

Also owns the Fast3D-specific rendering resources: texture cache and the Interpreter weak reference used for viewport and resolution calculations.

Constructor & Destructor Documentation

◆ Fast3dGui() [1/2]

Fast::Fast3dGui::Fast3dGui ( )

◆ Fast3dGui() [2/2]

Fast::Fast3dGui::Fast3dGui ( std::vector< std::shared_ptr< Ship::GuiWindow > >  guiWindows)

◆ ~Fast3dGui()

Fast::Fast3dGui::~Fast3dGui ( )
overridedefault

Member Function Documentation

◆ CalculateGameViewport()

void Fast::Fast3dGui::CalculateGameViewport ( )
overrideprotectedvirtual

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 from Ship::Gui.

◆ DrawFloatingWindows()

void Fast::Fast3dGui::DrawFloatingWindows ( )
overrideprotectedvirtual

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

Reimplemented from Ship::Gui.

◆ DrawGame()

void Fast::Fast3dGui::DrawGame ( )
overrideprotectedvirtual

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 from Ship::Gui.

◆ GetTextureById()

ImTextureID Fast::Fast3dGui::GetTextureById ( int32_t  id)
protected

Returns the ImTextureID for a texture identified by its integer ID.

Parameters
idInternal texture registry ID.
Returns
ImTextureID for use with ImGui::Image().

◆ GetTextureByName()

ImTextureID Fast::Fast3dGui::GetTextureByName ( const std::string &  name)

Returns the ImGui texture handle for the given cache key.

Parameters
nameTexture cache key.
Returns
ImTextureID suitable for ImGui::Image(), or nullptr if not found.

◆ GetTextureSize()

ImVec2 Fast::Fast3dGui::GetTextureSize ( const std::string &  name)

Returns the pixel dimensions of the cached texture.

Parameters
nameTexture cache key.
Returns
ImVec2 with the texture's width and height, or (0, 0) if not found.

◆ HandleWindowEvents()

void Fast::Fast3dGui::HandleWindowEvents ( Fast::WindowEvent  event)

Forwards a platform window event to the active ImGui backend.

Only Fast3D backends (gfx_sdl2, gfx_dxgi) construct and dispatch WindowEvents. Callers retrieve the Gui via Window::GetGui() and dynamic_cast to Fast3dGui.

Parameters
eventPlatform event (SDL or Win32) wrapped in a Fast::WindowEvent.

◆ HasTextureByName()

bool Fast::Fast3dGui::HasTextureByName ( const std::string &  name)

Returns true if a texture with the given name is already cached.

Parameters
nameTexture cache key.

◆ ImGuiBackendInit()

void Fast::Fast3dGui::ImGuiBackendInit ( )
overrideprotectedvirtual

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

Reimplemented from Ship::Gui.

◆ ImGuiBackendNewFrame()

void Fast::Fast3dGui::ImGuiBackendNewFrame ( )
overrideprotectedvirtual

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

Reimplemented from Ship::Gui.

◆ ImGuiBackendShutdown()

void Fast::Fast3dGui::ImGuiBackendShutdown ( )
overrideprotectedvirtual

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

Reimplemented from Ship::Gui.

◆ ImGuiRenderDrawData()

void Fast::Fast3dGui::ImGuiRenderDrawData ( ImDrawData *  data)
overrideprotectedvirtual

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 from Ship::Gui.

◆ ImGuiWMInit()

void Fast::Fast3dGui::ImGuiWMInit ( )
overrideprotectedvirtual

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

Reimplemented from Ship::Gui.

◆ ImGuiWMNewFrame()

void Fast::Fast3dGui::ImGuiWMNewFrame ( )
overrideprotectedvirtual

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

Reimplemented from Ship::Gui.

◆ ImGuiWMShutdown()

void Fast::Fast3dGui::ImGuiWMShutdown ( )
overrideprotectedvirtual

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

Reimplemented from Ship::Gui.

◆ Init()

void Fast::Fast3dGui::Init ( GuiWindowInitData  windowImpl)

Initialises the ImGui context with the given backend-specific handles.

Parameters
windowImplBackend-specific handles required by the ImGui backend.

◆ LoadGuiTexture() [1/2]

void Fast::Fast3dGui::LoadGuiTexture ( const std::string &  name,
const Fast::Texture tex,
const ImVec4 &  tint 
)

Uploads a Fast::Texture object to the GPU and caches it under name.

Parameters
nameTexture cache key.
texSource texture data.
tintRGBA tint.

◆ LoadGuiTexture() [2/2]

void Fast::Fast3dGui::LoadGuiTexture ( const std::string &  name,
const std::string &  path,
const ImVec4 &  tint 
)

Loads an image from an archive path and caches it under the given name.

Parameters
namePath/texture name used to reference the texture in GetTextureByName().
pathVirtual resource path of the source image.
tintRGBA tint multiplied over the image (use ImVec4(1,1,1,1) for no tint).

◆ LoadTextureFromRawImage()

void Fast::Fast3dGui::LoadTextureFromRawImage ( const std::string &  name,
const std::string &  path 
)

Loads a raw image file from the filesystem (not the archive) and caches it.

Parameters
nameCache key.
pathAbsolute filesystem path to the image file (e.g. a PNG).

◆ LoadTextureFromResource()

void Fast::Fast3dGui::LoadTextureFromResource ( const std::string &  name,
std::shared_ptr< Ship::GuiTexture texture 
)

Uploads a pre-loaded GuiTexture resource to the GPU and caches it.

Parameters
nameCache key.
textureLoaded GuiTexture resource.

◆ RefreshImGuiGamepads()

void Fast::Fast3dGui::RefreshImGuiGamepads ( )
overridevirtual

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 from Ship::Gui.

◆ SupportsViewports()

bool Fast::Fast3dGui::SupportsViewports ( )
overridevirtual

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 from Ship::Gui.

◆ UnloadTexture()

void Fast::Fast3dGui::UnloadTexture ( const std::string &  name)

Removes the texture with the given name from the cache and frees GPU resources.

Parameters
nameTexture cache key to remove.

Member Data Documentation

◆ mConsoleVariables

std::shared_ptr<Ship::ConsoleVariable> Fast::Fast3dGui::mConsoleVariables
protected

Cached ConsoleVariable component.

Note
Requires ConsoleVariable component in Context.

◆ mImpl

GuiWindowInitData Fast::Fast3dGui::mImpl
protected

Backend-specific window/context handles passed to Init().

◆ mInterpreter

std::weak_ptr<Interpreter> Fast::Fast3dGui::mInterpreter
protected

Weak reference to the Fast3D scripting interpreter.

◆ mResourceManager

std::shared_ptr<Ship::ResourceManager> Fast::Fast3dGui::mResourceManager
protected

Cached ResourceManager component.

Note
Requires ResourceManager component in Context.

◆ mWindow

std::shared_ptr<Ship::Window> Fast::Fast3dGui::mWindow
protected

Cached Window component.

Note
Requires Window component in Context.

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