ImGui: make config singleton static

Avoid indirection, also deduplicate common style var assignments.
This commit is contained in:
Kawe Mazidjatari 2024-02-29 22:31:43 +01:00
parent 828e96a74a
commit 1f8cd45626
6 changed files with 20 additions and 27 deletions

View File

@ -106,7 +106,7 @@ bool CModAppSystemGroup::StaticCreate(CModAppSystemGroup* pModAppSystemGroup)
g_pClientEntityList = (CClientEntityList*)g_FactorySystem.GetFactory(VCLIENTENTITYLIST_INTERFACE_VERSION);
g_pEngineTraceClient = (CEngineTraceClient*)g_FactorySystem.GetFactory(INTERFACEVERSION_ENGINETRACE_CLIENT);
g_pImGuiConfig->Load(); // Load ImGui configs.
g_ImGuiConfig.Load(); // Load ImGui configs.
DirectX_Init();
#endif // !DEDICATED

View File

@ -37,15 +37,15 @@ int CGame::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
if (uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYDOWN)
{
if (wParam == g_pImGuiConfig->m_ConsoleConfig.m_nBind0 ||
wParam == g_pImGuiConfig->m_ConsoleConfig.m_nBind1)
if (wParam == g_ImGuiConfig.m_ConsoleConfig.m_nBind0 ||
wParam == g_ImGuiConfig.m_ConsoleConfig.m_nBind1)
{
g_Console.ToggleActive();
ResetInput(); // Disable input to game when console is drawn.
}
if (wParam == g_pImGuiConfig->m_BrowserConfig.m_nBind0 ||
wParam == g_pImGuiConfig->m_BrowserConfig.m_nBind1)
if (wParam == g_ImGuiConfig.m_BrowserConfig.m_nBind0 ||
wParam == g_ImGuiConfig.m_BrowserConfig.m_nBind1)
{
g_Browser.ToggleActive();
ResetInput(); // Disable input to game when browser is drawn.

View File

@ -368,17 +368,17 @@ void CConsole::OptionsPanel(void)
ImGui::Text("Console hotkey:");
ImGui::SameLine();
if (ImGui::Hotkey("##ToggleConsole", &g_pImGuiConfig->m_ConsoleConfig.m_nBind0, ImVec2(80, 80)))
if (ImGui::Hotkey("##ToggleConsole", &g_ImGuiConfig.m_ConsoleConfig.m_nBind0, ImVec2(80, 80)))
{
g_pImGuiConfig->Save();
g_ImGuiConfig.Save();
}
ImGui::Text("Browser hotkey:");
ImGui::SameLine();
if (ImGui::Hotkey("##ToggleBrowser", &g_pImGuiConfig->m_BrowserConfig.m_nBind0, ImVec2(80, 80)))
if (ImGui::Hotkey("##ToggleBrowser", &g_ImGuiConfig.m_BrowserConfig.m_nBind0, ImVec2(80, 80)))
{
g_pImGuiConfig->Save();
g_ImGuiConfig.Save();
}
ImGui::EndPopup();

View File

@ -36,7 +36,7 @@ void CImguiSurface::Animate()
void CImguiSurface::SetStyleVar(const float width, const float height,
const float x, const float y)
{
m_surfaceStyle = g_pImGuiConfig->InitStyle();
m_surfaceStyle = g_ImGuiConfig.InitStyle();
ImGui::SetNextWindowSize(ImVec2(width, height), ImGuiCond_FirstUseEver);
ImGui::SetWindowPos(ImVec2(x, y), ImGuiCond_FirstUseEver);

View File

@ -115,14 +115,9 @@ ImGuiStyle_t ImGuiConfig::InitStyle() const
style.WindowBorderSize = 0.0f;
style.FrameBorderSize = 1.0f;
style.ChildBorderSize = 1.0f;
style.PopupBorderSize = 1.0f;
style.TabBorderSize = 1.0f;
style.WindowRounding = 4.0f;
style.FrameRounding = 1.0f;
style.ChildRounding = 1.0f;
style.PopupRounding = 3.0f;
style.TabRounding = 1.0f;
style.ScrollbarRounding = 1.0f;
result = ImGuiStyle_t::LEGACY;
@ -167,14 +162,9 @@ ImGuiStyle_t ImGuiConfig::InitStyle() const
style.WindowBorderSize = 1.0f;
style.FrameBorderSize = 0.0f;
style.ChildBorderSize = 0.0f;
style.PopupBorderSize = 1.0f;
style.TabBorderSize = 1.0f;
style.WindowRounding = 4.0f;
style.FrameRounding = 1.0f;
style.ChildRounding = 1.0f;
style.PopupRounding = 3.0f;
style.TabRounding = 1.0f;
style.ScrollbarRounding = 3.0f;
result = ImGuiStyle_t::MODERN;
@ -223,20 +213,23 @@ ImGuiStyle_t ImGuiConfig::InitStyle() const
style.WindowBorderSize = 1.0f;
style.FrameBorderSize = 1.0f;
style.ChildBorderSize = 0.0f;
style.PopupBorderSize = 1.0f;
style.TabBorderSize = 1.0f;
style.WindowRounding = 4.0f;
style.FrameRounding = 1.0f;
style.ChildRounding = 2.0f;
style.PopupRounding = 4.0f;
style.TabRounding = 1.0f;
style.GrabRounding = 1.0f;
style.ScrollbarRounding = 1.0f;
result = ImGuiStyle_t::DEFAULT;
}
style.PopupBorderSize = 1.0f;
style.TabBorderSize = 1.0f;
style.TabBarBorderSize = 1.0f;
style.WindowRounding = 4.0f;
style.FrameRounding = 1.0f;
style.TabRounding = 1.0f;
style.ItemSpacing = ImVec2(5, 4);
style.FramePadding = ImVec2(4, 4);
style.WindowPadding = ImVec2(5, 5);
@ -244,4 +237,4 @@ ImGuiStyle_t ImGuiConfig::InitStyle() const
return result;
}
ImGuiConfig* g_pImGuiConfig = new ImGuiConfig();
ImGuiConfig g_ImGuiConfig;

View File

@ -30,4 +30,4 @@ public:
ImGuiStyle_t InitStyle() const;
};
extern ImGuiConfig* g_pImGuiConfig;
extern ImGuiConfig g_ImGuiConfig;