VesCodes / ImGui

ImGui plugin for Unreal Engine
MIT License
129 stars 18 forks source link

Add API for querying registering/unregistering input processor #16

Open dzeligmanriot opened 3 months ago

dzeligmanriot commented 3 months ago

We use these API in a subsystem (that maybe should exist in the root plugin in some form? ) to unregister and register during breakpoints etc.

Some example code:

void UDebugGUISubsystem::HandleScriptException(const UObject* InObject, const FFrame& InFrame,
    const FBlueprintExceptionInfo& InInfo)
{
    if (InInfo.GetType() == EBlueprintExceptionType::Breakpoint)
    {
        UnregisterInputProcessor();
    }

    if (InInfo.GetType() == EBlueprintExceptionType::AccessViolation
        || InInfo.GetType() == EBlueprintExceptionType::AbortExecution
        || InInfo.GetType() == EBlueprintExceptionType::FatalError )
    {
        DisableGUI();
    }
}
`void UDebugGUISubsystem::HandlePausePIE(bool bIsSimulating)
{
    UnregisterInputProcessor();
}

void UDebugGUISubsystem::HandleResumePIE(bool bIsSimulating)
{
    RegisterInputProcessor();
}`

void UDebugGUISubsystem::UnregisterInputProcessor()
{
    if(bDebugGuiOpen && ImGui::GetCurrentContext() != nullptr)
    {
        TSharedPtr<FImGuiContext> ActiveContext = FImGuiContext::Get(ImGui::GetCurrentContext());
        if(ActiveContext.IsValid())
        {
            ActiveContext->UnRegisterInputProcessor();
        }
    }
}

void UDebugGUISubsystem::RegisterInputProcessor()
{
    if(bDebugGuiOpen && ImGui::GetCurrentContext() != nullptr)
    {
        TSharedPtr<FImGuiContext> ActiveContext = FImGuiContext::Get(ImGui::GetCurrentContext());
        if(ActiveContext.IsValid())
        {
            ActiveContext->RegisterInputProcessor();
        }
    }
}