Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to sharing mouse input #63

Open
benui-dev opened this issue Mar 5, 2022 · 3 comments
Open

Improvements to sharing mouse input #63

benui-dev opened this issue Mar 5, 2022 · 3 comments

Comments

@benui-dev
Copy link

benui-dev commented Mar 5, 2022

Creating a new ticket as the old one was closed
#49

I read the description of input sharing and the issues with mouse being that there is an ImGui Slate widget covering the whole screen and intercepting mouse events. I'm not a complete expert on how your plugin works so maybe this is a naive idea but...

I see that ImGuiInputHandler returns FReply::Handled for MouseDown and MouseUp events and that seems to be what make sure that mouse clicks on the UI don't accidentally go through to the game.

Is there no way to only return FReply::Handled if the cursor is over a UI element? That way the Slate widget can behave kind of like HitTestInvisible?

Edit: Okay yeah it was mega naive, checking for WantCaptureMouse and IsWindowHovered doesn't work, even though the imgui demo window seems to show the flags correctly.

FReply UImGuiInputHandler::OnMouseButtonDown(const FPointerEvent& MouseEvent)
{
	if (MouseEvent.IsTouchEvent())
	{
		return ToReply(false);
	}

	//const bool bHandled = ImGui::GetIO().WantCaptureMouse;
	const bool bHandled = ImGui::IsWindowHovered();

	InputState->SetMouseDown(MouseEvent, true);
	return ToReply(bHandled);
}
@benui-dev
Copy link
Author

I wonder if input preprocessors might be helpful? FSlateApplication::Get().RegisterInputPreProcessor

@benui-dev
Copy link
Author

benui-dev commented Mar 19, 2022

Made some progress by adding this to ImGuiInputHandler.cpp

With mouse input sharing disabled, the payer controller still receives clicks when clicking outside ImGui windows, and ImGui receives events when clicking inside ImGui windows.

It's probably a naive solution and I'm going to hit some big problem soon, but maybe it will help someone develop a better solution?

FReply UImGuiInputHandler::OnMouseButtonDown(const FPointerEvent& MouseEvent)
{
	if (MouseEvent.IsTouchEvent())
	{
		return ToReply(false);
	}

	InputState->SetMouseDown(MouseEvent, true);
	if (ModuleManager)
	{
		FImGuiContextProxy* Proxy = ModuleManager->GetContextManager().GetContextProxy(0);
		if (Proxy)
		{
			GEngine->AddOnScreenDebugMessage(15, 10, Proxy->WantsMouseCapture() ? FColor::Green : FColor::Red, TEXT("Handler Down"));
			return ToReply(Proxy->WantsMouseCapture());
		}
	}
	return ToReply(true);
}

@livingisgood
Copy link

I know it is not likely a proper way to do this, but it seems to work by just comment out those two lines of code in SImGuiWidget.cpp

if (bTransparentMouseInput)
{
	// If mouse is in transparent input mode and focus is lost to viewport, let viewport keep it and disable
	// the whole input to match that state.
	if (GameViewport->GetGameViewportWidget()->HasMouseCapture())
	{
		//Properties.SetInputEnabled(false);
		//UpdateInputState();
	}
}

I am wondering if we just don't disable the input when viewport has taken the focus, what could go wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants