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

Renders on-screen timed notification messages. More...

#include <GameOverlay.h>

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

Public Member Functions

 GameOverlay (std::shared_ptr< Context > context=nullptr, std::shared_ptr< ResourceManager > resourceManager=nullptr, std::shared_ptr< ConsoleVariable > consoleVariables=nullptr, std::shared_ptr< Window > window=nullptr)
 
virtual ~GameOverlay ()
 
void OnInit (const nlohmann::json &initArgs={}) override
 Initialises the overlay and loads the default font.
 
void LoadFont (const std::string &name, float fontSize, const ResourceIdentifier &identifier)
 Loads a font from an archive resource and registers it under name.
 
void LoadFont (const std::string &name, float fontSize, const std::string &path)
 Loads a font from a virtual archive path and registers it under name.
 
void SetCurrentFont (const std::string &name)
 Selects the font used for subsequent TextDraw() and notification calls.
 
void Draw ()
 Renders all active overlays for the current frame. Called by Gui::DrawGame().
 
void DrawSettings ()
 Renders the overlay settings panel (font selector, position, etc.) in ImGui.
 
float GetStringWidth (const char *text)
 Returns the pixel width of text using the currently selected font.
 
ImVec2 CalculateTextSize (const char *text, const char *textEnd=NULL, bool shortenText=false, float wrapWidth=-1.0f)
 Calculates the bounding box of the given text.
 
void TextDraw (float x, float y, bool shadow, ImVec4 color, const char *text,...)
 Draws text at the given screen position, optionally with a drop shadow.
 
void TextDrawNotification (float duration, bool shadow, const char *fmt,...)
 Posts a timed notification message that fades out automatically.
 
void ClearNotifications ()
 Immediately removes all active notification overlays.
 
ImGuiID GetID ()
 Returns the ImGui ID of the overlay's invisible host window.
 
- 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

float GetScreenWidth ()
 Returns the current game viewport width in pixels.
 
float GetScreenHeight ()
 Returns the current game viewport height in pixels.
 
- 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.
 

Detailed Description

Renders on-screen timed notification messages.

GameOverlay is a Component owned by Gui and draws directly into the "game" ImGui viewport using a custom font loaded from the archive. It is accessible via Gui::GetGameOverlay().

Fonts are loaded with LoadFont() and selected with SetCurrentFont(). Text can be drawn at an arbitrary screen position with TextDraw(), or posted as a timed notification with TextDrawNotification().

Constructor & Destructor Documentation

◆ GameOverlay()

Ship::GameOverlay::GameOverlay ( std::shared_ptr< Context context = nullptr,
std::shared_ptr< ResourceManager resourceManager = nullptr,
std::shared_ptr< ConsoleVariable consoleVariables = nullptr,
std::shared_ptr< Window window = nullptr 
)

◆ ~GameOverlay()

virtual Ship::GameOverlay::~GameOverlay ( )
virtual

Member Function Documentation

◆ CalculateTextSize()

ImVec2 Ship::GameOverlay::CalculateTextSize ( const char *  text,
const char *  textEnd = NULL,
bool  shortenText = false,
float  wrapWidth = -1.0f 
)

Calculates the bounding box of the given text.

Parameters
textText to measure.
textEndOptional end pointer (nullptr = measure until null terminator).
shortenTextIf true, the text may be clipped to wrapWidth.
wrapWidthMaximum width before wrapping (-1 = no wrap).
Returns
Bounding size in pixels.

◆ ClearNotifications()

void Ship::GameOverlay::ClearNotifications ( )

Immediately removes all active notification overlays.

◆ Draw()

void Ship::GameOverlay::Draw ( )

Renders all active overlays for the current frame. Called by Gui::DrawGame().

◆ DrawSettings()

void Ship::GameOverlay::DrawSettings ( )

Renders the overlay settings panel (font selector, position, etc.) in ImGui.

◆ GetID()

ImGuiID Ship::GameOverlay::GetID ( )

Returns the ImGui ID of the overlay's invisible host window.

Useful for docking or focus management.

◆ GetScreenHeight()

float Ship::GameOverlay::GetScreenHeight ( )
protected

Returns the current game viewport height in pixels.

◆ GetScreenWidth()

float Ship::GameOverlay::GetScreenWidth ( )
protected

Returns the current game viewport width in pixels.

◆ GetStringWidth()

float Ship::GameOverlay::GetStringWidth ( const char *  text)

Returns the pixel width of text using the currently selected font.

Parameters
textNull-terminated string to measure.

◆ LoadFont() [1/2]

void Ship::GameOverlay::LoadFont ( const std::string &  name,
float  fontSize,
const ResourceIdentifier identifier 
)

Loads a font from an archive resource and registers it under name.

Parameters
nameCache key used by SetCurrentFont() and TextDraw().
fontSizePoint size.
identifierResourceIdentifier of the font file within the archive.

◆ LoadFont() [2/2]

void Ship::GameOverlay::LoadFont ( const std::string &  name,
float  fontSize,
const std::string &  path 
)

Loads a font from a virtual archive path and registers it under name.

Parameters
nameCache key.
fontSizePoint size.
pathVirtual path of the font file within the archive.

◆ OnInit()

void Ship::GameOverlay::OnInit ( const nlohmann::json &  initArgs = {})
overridevirtual

Initialises the overlay and loads the default font.

Reimplemented from Ship::Component.

◆ SetCurrentFont()

void Ship::GameOverlay::SetCurrentFont ( const std::string &  name)

Selects the font used for subsequent TextDraw() and notification calls.

Parameters
nameCache key registered via LoadFont().

◆ TextDraw()

void Ship::GameOverlay::TextDraw ( float  x,
float  y,
bool  shadow,
ImVec4  color,
const char *  text,
  ... 
)

Draws text at the given screen position, optionally with a drop shadow.

Parameters
xScreen X coordinate in pixels.
yScreen Y coordinate in pixels.
shadowIf true, renders a black shadow one pixel behind the text.
colorRGBA colour of the text.
textprintf-style format string.

◆ TextDrawNotification()

void Ship::GameOverlay::TextDrawNotification ( float  duration,
bool  shadow,
const char *  fmt,
  ... 
)

Posts a timed notification message that fades out automatically.

Parameters
durationTotal display time in seconds.
shadowIf true, renders a drop shadow.
fmtprintf-style format string.

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