libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
GameOverlay.h
Go to the documentation of this file.
1#pragma once
2#include <string>
3#include <vector>
4#include <memory>
5
8#include <imgui.h>
9#include <unordered_map>
10
11namespace Ship {
12
13class ConsoleVariable;
14class Window;
15class ResourceManager;
16
18enum class OverlayType {
19 TEXT,
20 IMAGE,
22};
23
27struct Overlay {
29 std::string Value;
30 float fadeTime;
31 float duration;
32};
33
45class GameOverlay : public Component {
46 public:
47 GameOverlay(std::shared_ptr<Context> context = nullptr, std::shared_ptr<ResourceManager> resourceManager = nullptr,
48 std::shared_ptr<ConsoleVariable> consoleVariables = nullptr, std::shared_ptr<Window> window = nullptr);
49 virtual ~GameOverlay();
50
52 void OnInit(const nlohmann::json& initArgs = {}) override;
53
60 void LoadFont(const std::string& name, float fontSize, const ResourceIdentifier& identifier);
61
68 void LoadFont(const std::string& name, float fontSize, const std::string& path);
69
74 void SetCurrentFont(const std::string& name);
75
77 void Draw();
78
81
86 float GetStringWidth(const char* text);
87
96 ImVec2 CalculateTextSize(const char* text, const char* textEnd = NULL, bool shortenText = false,
97 float wrapWidth = -1.0f);
98
107 void TextDraw(float x, float y, bool shadow, ImVec4 color, const char* text, ...);
108
115 void TextDrawNotification(float duration, bool shadow, const char* fmt, ...);
116
119
125 ImGuiID GetID();
126
127 protected:
132
133 private:
134 std::unordered_map<std::string, ImFont*> mFonts;
135 std::unordered_map<std::string, Overlay> mRegisteredOverlays;
136 std::string mCurrentFont = "Default";
137 bool mNeedsCleanup = false;
138
139 std::shared_ptr<ResourceManager> mResourceManager;
140 std::shared_ptr<ConsoleVariable> mConsoleVariables;
141 std::shared_ptr<Window> mWindow;
142
144 void CleanupNotifications();
145};
146} // namespace Ship
A named Part with a parent/child hierarchy and optional thread safety.
Definition Component.h:34
Renders on-screen timed notification messages.
Definition GameOverlay.h:45
void OnInit(const nlohmann::json &initArgs={}) override
Initialises the overlay and loads the default font.
virtual ~GameOverlay()
float GetScreenHeight()
Returns the current game viewport height in pixels.
float GetStringWidth(const char *text)
Returns the pixel width of text using the currently selected font.
void SetCurrentFont(const std::string &name)
Selects the font used for subsequent TextDraw() and notification calls.
void DrawSettings()
Renders the overlay settings panel (font selector, position, etc.) in ImGui.
ImGuiID GetID()
Returns the ImGui ID of the overlay's invisible host window.
void Draw()
Renders all active overlays for the current frame. Called by Gui::DrawGame().
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 LoadFont(const std::string &name, float fontSize, const ResourceIdentifier &identifier)
Loads a font from an archive resource and registers it under name.
ImVec2 CalculateTextSize(const char *text, const char *textEnd=NULL, bool shortenText=false, float wrapWidth=-1.0f)
Calculates the bounding box of the given text.
float GetScreenWidth()
Returns the current game viewport width in pixels.
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.
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.
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)
Uniquely identifies a cached resource by path/hash, owner, and source archive.
Definition ResourceIdentifier.h:15
Core namespace for the libultraship engine framework.
Definition gfx_direct3d_common.h:14
OverlayType
Identifies the type of an overlay item rendered by GameOverlay.
Definition GameOverlay.h:18
@ IMAGE
An image drawn at a screen position.
@ NOTIFICATION
A transient notification that fades out after a duration.
An active overlay item managed by GameOverlay.
Definition GameOverlay.h:27
float fadeTime
Remaining fade-out time in seconds (notifications only).
Definition GameOverlay.h:30
float duration
Total display duration in seconds (notifications only).
Definition GameOverlay.h:31
std::string Value
Text content or resource path, depending on Type.
Definition GameOverlay.h:29
OverlayType Type
Discriminator for the overlay kind.
Definition GameOverlay.h:28