libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
Gui.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef __cplusplus
4
6#include <imgui.h>
7#include <imgui_internal.h>
8#include <memory>
9#include <string>
10#include <map>
11#include <unordered_map>
12#include <vector>
20
21namespace Ship {
22class Context;
23class Window;
24class ConsoleVariable;
25class Config;
26class ResourceManager;
27
40class Gui : public Component {
41 public:
43 Gui();
44
49 Gui(const std::vector<std::shared_ptr<GuiWindow>>& guiWindows, std::shared_ptr<Context> context = nullptr,
50 std::shared_ptr<ConsoleVariable> consoleVariable = nullptr, std::shared_ptr<Window> window = nullptr,
51 std::shared_ptr<Config> config = nullptr, std::shared_ptr<ResourceManager> resourceManager = nullptr,
52 std::shared_ptr<GameOverlay> gameOverlay = nullptr);
53 virtual ~Gui();
54
58 void OnInit(const nlohmann::json& initArgs) override;
59
66 void StartDraw();
67
73 void EndDraw();
74
81
89 virtual bool SupportsViewports();
90
97
102 void AddGuiWindow(std::shared_ptr<GuiWindow> guiWindow);
103
108 std::shared_ptr<GuiWindow> GetGuiWindow(const std::string& name);
109
114 void RemoveGuiWindow(std::shared_ptr<GuiWindow> guiWindow);
115
120 void RemoveGuiWindow(const std::string& name);
121
124
126 std::shared_ptr<GameOverlay> GetGameOverlay();
127
132 void SetMenuBar(std::shared_ptr<GuiMenuBar> menuBar);
133
135 std::shared_ptr<GuiMenuBar> GetMenuBar();
136
141 void SetMenu(std::shared_ptr<GuiWindow> menu);
142
144 std::shared_ptr<GuiWindow> GetMenu();
145
150
153
156
159
162
165
169 virtual void RefreshImGuiGamepads();
170
176
177 protected:
180
182 void EndFrame();
183
186 virtual void DrawFloatingWindows();
187
189 virtual void DrawMenu();
190
193 virtual void DrawGame();
194
197 virtual void CalculateGameViewport();
198
201 virtual void ImGuiBackendNewFrame();
202
205 virtual void ImGuiWMNewFrame();
206
209 virtual void ImGuiWMInit();
210
213 virtual void ImGuiWMShutdown();
214
217 virtual void ImGuiBackendInit();
218
221 virtual void ImGuiBackendShutdown();
222
228 virtual void ImGuiRenderDrawData(ImDrawData* data);
229
232
235
237 ImGuiIO* mImGuiIo;
238 std::map<std::string, std::shared_ptr<GuiWindow>> mGuiWindows;
239
240 private:
241 bool mNeedsConsoleVariableSave;
242 std::string mImGuiIniPath;
243 std::string mImGuiLogPath;
244 std::shared_ptr<GameOverlay> mGameOverlay;
245 std::shared_ptr<GuiMenuBar> mMenuBar;
246 std::shared_ptr<GuiWindow> mMenu;
247 std::shared_ptr<ConsoleVariable> mConsoleVariable;
248 std::shared_ptr<Window> mWindow;
249 std::shared_ptr<Config> mConfig;
250 std::shared_ptr<ResourceManager> mResourceManager;
251};
252} // namespace Ship
253
254#endif
A named Part with a parent/child hierarchy and optional thread safety.
Definition Component.h:34
Owns and drives the ImGui context, all registered GuiWindows, and texture management.
Definition Gui.h:40
void SetMenu(std::shared_ptr< GuiWindow > menu)
Sets an optional full-screen "menu" GuiWindow (e.g. a title-screen or pause menu).
void HandleMouseCapture()
Updates mouse capture state based on window focus and UI interaction.
std::shared_ptr< GuiWindow > GetMenu()
Returns the registered menu window, or nullptr if none has been set.
void RemoveAllGuiWindows()
Removes all registered GuiWindows from the draw loop.
virtual void DrawMenu()
Draws the menu bar and/or full-screen menu window. Override to add custom menus.
bool IsMouseOverActivePopup()
Returns true if the mouse cursor is over an active ImGui popup.
void EndFrame()
Calls ImGui::Render() and submits draw data to the backend.
std::shared_ptr< GuiWindow > GetGuiWindow(const std::string &name)
Returns the GuiWindow registered with the given name, or nullptr.
std::shared_ptr< GuiMenuBar > GetMenuBar()
Returns the registered menu bar, or nullptr if none has been set.
void EndDraw()
Finalises the ImGui frame and submits draw data to the renderer.
virtual void DrawGame()
Renders the game viewport inside the main docking space. The base implementation is a no-op....
void RemoveGuiWindow(std::shared_ptr< GuiWindow > guiWindow)
Removes a specific GuiWindow from the draw loop.
ImGuiID GetMainGameWindowID()
Returns the ImGui ID of the main game viewport window.
bool IsMouseOverAnyGuiItem()
Returns true if the mouse cursor is currently over any ImGui item.
virtual void ImGuiWMNewFrame()
Calls ImGui_ImplSDL2_NewFrame() or the platform equivalent. The base implementation is a no-op.
std::shared_ptr< GameOverlay > GetGameOverlay()
Returns the GameOverlay instance used for on-screen text and notifications.
void StartFrame()
Calls ImGui::NewFrame() after processing backend-specific input.
bool GetMenuOrMenubarVisible()
Returns true if the menu bar or the full-screen menu window is currently visible.
virtual ~Gui()
void ShutDownImGui(Ship::Window *window)
Shuts down the ImGui context and releases backend resources.
virtual bool SupportsViewports()
Returns true if the ImGui multi-viewport / docking feature is supported by the current backend.
ImGuiIO * mImGuiIo
Pointer to the active ImGuiIO context.
Definition Gui.h:237
virtual void ImGuiBackendNewFrame()
Calls the appropriate ImGui backend New Frame function (DX11 / GL / Metal). The base implementation i...
void SetMenuBar(std::shared_ptr< GuiMenuBar > menuBar)
Sets the main application menu bar.
void SaveConsoleVariablesNextFrame()
Schedules a CVar save to disk at the end of the current frame.
Gui()
Constructs a Gui with no pre-registered windows.
void RemoveGuiWindow(const std::string &name)
Removes the GuiWindow with the given name from the draw loop.
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.
void AddGuiWindow(std::shared_ptr< GuiWindow > guiWindow)
Adds a GuiWindow to the draw loop.
void OnInit(const nlohmann::json &initArgs) override
Initialises the ImGui context and the appropriate backend renderer.
void CheckSaveCvars()
Flushes CVars to disk if SaveConsoleVariablesNextFrame() was called.
void UnblockGamepadNavigation()
Re-enables ImGui gamepad navigation.
virtual void CalculateGameViewport()
Recalculates the game viewport rect to account for the menu bar and window size. The base implementat...
virtual void ImGuiBackendShutdown()
Shuts down the renderer ImGui backend. The base implementation is a no-op.
void BlockGamepadNavigation()
Disables ImGui gamepad navigation (allows the game to use gamepad input).
bool GamepadNavigationEnabled()
Returns true if ImGui gamepad navigation is enabled.
virtual void RefreshImGuiGamepads()
Re-binds the ImGui platform backend's gamepad list to the currently connected controllers....
virtual void ImGuiWMInit()
Initialises the platform/window-manager 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.
ImVec2 mTemporaryWindowPos
Scratchpad position used when repositioning windows.
Definition Gui.h:236
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 DrawFloatingWindows()
Draws all registered floating GuiWindow instances. The base implementation is a no-op....
void StartDraw()
Begins a new ImGui frame.
std::map< std::string, std::shared_ptr< GuiWindow > > mGuiWindows
Registered window map (name → window).
Definition Gui.h:238
Abstract base class for the application window and rendering surface.
Definition Window.h:62
Core namespace for the libultraship engine framework.
Definition gfx_direct3d_common.h:14