Skip to content

Exclusive mouse control to imgui #1

@arnaud-jamin

Description

@arnaud-jamin

Hello,

Thanks for your library. I find it very well designed.
I'm looking at replacing my Unreal Imgui integration (inspired by UnrealImGui) by yours in my project https://github.com/arnaud-jamin/Cog.

I have the following use case which forces me to modify your sources in a way I do not really like. Maybe you will come up with a better idea.

I want to give the option to the imgui user to change this dynamically:

  1. Disable imgui mouse. Then only the game handle the mouse.
  2. Share mouse between the game and imgui (imgui uses the mouse only over a imgui window otherwise it is for the game)
  3. Give exclusive control of the mouse to imgui. The game doesn't receive the mouse anymore.

Point 1) Can be done by using the flag ImGuiConfigFlags_NoMouse
Point 2) Can be done by disabling the flag ImGuiConfigFlags_NoMouse
Point 3) Can be done in different ways:

A) dynamically change the return value of the functions in input processor:

The InputProcessor could have a member variable "OnlyEnableImGuiMouse". Related functions would return true when this variable is true.

	virtual bool HandleMouseMoveEvent(FSlateApplication& SlateApp, const FPointerEvent& Event) override
	{
		[...]

                if (OnlyEnableImGuiMouse)
                {
                    return true;
                }    
		
                return IO.WantCaptureMouse;
	}

To be able to change that variable I would need to expose an accessor to the Overlay or the Context inside FScopedContext. Or I could create the Context by calling this:

TSharedPtr<FImGuiContext> ImGuiContext = FImGuiModule::Get().FindOrCreateContext();

Then I could keeping a reference to the created context and call a SetOnlyEnableImGuiMouse() on it. I would need to get the context from FScopedContext to do:

	virtual bool HandleMouseMoveEvent(FSlateApplication& SlateApp, const FPointerEvent& Event) override
	{
		ImGui::FScopedContext ScopedContext(Owner->GetContext());
                [...]

                if (ScopedContext.GetContext()->GetOnlyEnableImGuiMouse())
                {
                    return true;
                }    
		
                return IO.WantCaptureMouse;
	}

This doesn't seem great.

B) Another way to do this is to have a transparent imgui widget the cover the whole screen so IO.WantCaptureMouse always return true. (it could be the docking central node without ImGuiDockNodeFlags_PassthruCentralNode but made transparent)

Any suggestion ?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions