diff --git a/Source/ImGui/Private/ImGuiModule.cpp b/Source/ImGui/Private/ImGuiModule.cpp index 9adc679..a8478f3 100644 --- a/Source/ImGui/Private/ImGuiModule.cpp +++ b/Source/ImGui/Private/ImGuiModule.cpp @@ -12,6 +12,12 @@ #define LOCTEXT_NAMESPACE "FImGuiModule" +namespace CVars +{ + extern TAutoConsoleVariable InputEnabled; + extern TAutoConsoleVariable ShowDemo; +} + struct EDelegateCategory { enum @@ -100,6 +106,38 @@ void FImGuiModule::ShutdownModule() ModuleManager = nullptr; } +bool FImGuiModule::IsInputMode() const +{ + return CVars::InputEnabled.GetValueOnAnyThread() > 0; +} + +void FImGuiModule::SetInputMode(bool bEnabled) +{ + // This function is for supporting shortcut or subsitiute for console command, so we are using the same priority. + CVars::InputEnabled->Set(bEnabled ? 1 : 0, ECVF_SetByConsole); +} + +void FImGuiModule::ToggleInputMode() +{ + SetInputMode(!IsInputMode()); +} + +bool FImGuiModule::IsShowingDemo() const +{ + return CVars::ShowDemo.GetValueOnAnyThread() > 0; +} + +void FImGuiModule::SetShowDemo(bool bShow) +{ + // This function is for supporting shortcut or subsitiute for console command, so we are using the same priority. + CVars::ShowDemo->Set(bShow ? 1 : 0, ECVF_SetByConsole); +} + +void FImGuiModule::ToggleShowDemo() +{ + SetShowDemo(!IsShowingDemo()); +} + #undef LOCTEXT_NAMESPACE IMPLEMENT_MODULE(FImGuiModule, ImGui) diff --git a/Source/ImGui/Public/ImGuiModule.h b/Source/ImGui/Public/ImGuiModule.h index acb0112..eb23285 100644 --- a/Source/ImGui/Public/ImGuiModule.h +++ b/Source/ImGui/Public/ImGuiModule.h @@ -69,6 +69,44 @@ public: */ virtual void RemoveImGuiDelegate(const FImGuiDelegateHandle& Handle); + /** + * Check whether Input Mode is enabled (tests ImGui.InputEnabled console variable). + * + * @returns True, if Input Mode is enabled (ImGui.InputEnabled != 0) and false otherwise. + */ + virtual bool IsInputMode() const; + + /** + * Set Input Mode state (sets ImGui.InputEnabled console variable, so it can be used together with a console). + * + * @param bEnabled - Whether Input Mode should be enabled (ImGui.InputEnabled = 1) or not (ImGui.InputEnabled = 0). + */ + virtual void SetInputMode(bool bEnabled); + + /** + * Toggle Input Mode state (changes ImGui.InputEnabled console variable). + */ + virtual void ToggleInputMode(); + + /** + * Check whether ImGui Demo is shown (tests ImGui.ShowDemo console variable). + * + * @returns True, if demo is shown (ImGui.ShowDemo != 0) and false otherwise. + */ + virtual bool IsShowingDemo() const; + + /** + * Set whether to show ImGui Demo (sets ImGui.ShowDemo console variable, so it can be used together with a console). + * + * @param bShow - Whether to show ImGui Demo (ImGui.ShowDemo = 1) or not (ImGui.ShowDemo = 0). + */ + virtual void SetShowDemo(bool bShow); + + /** + * Toggle ImGui Demo (changes ImGui.ShowDemo console variable). + */ + virtual void ToggleShowDemo(); + /** IModuleInterface implementation */ virtual void StartupModule() override; virtual void ShutdownModule() override;