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

Fix mouse-in-viewport state for Viewport in TextureRect #89868

Conversation

Sauermann
Copy link
Contributor

Pushing InputEventMouse to the Viewport used in a TextureRect didn't work, because of inconsistent mouse-over state. This PR sends the necessary notifications to the Viewport.

resolve #89757

While this PR fixes the referenced issue, which is considered a regression, this PR could be considered not necessary based on the following reason.

The referenced issue is, that a TextureRect is used for displaying and interacting with a Viewport. Godot provides SubViewportContainer for this functionality.

#88992 introduced a change, that made it a bit more inconvenient to use TextureRext for interacting with the displayed Viewport. This can be worked around with a few lines of GDScript by sending mouse-entered/exited notifications to the Viewport, when the mouse enters/exits the TextureRect.

So an alternative to this PR would be to better document the necessary adjustments for interacting with a Viewport in a TextureRect.

Pushing `InputEventMouse` to the `Viewport` used in a `TextureRect`
didn't work, because of inconsistent mouse-over state.
This PR sends the necessary notifications to the `Viewport`.
@Sauermann Sauermann force-pushed the fix-mouse-over-viewport-in-texturerect branch from abe96ef to 02af728 Compare March 24, 2024 23:41
@KoBeWi
Copy link
Member

KoBeWi commented Mar 25, 2024

Well, as you already noted, we have the SubViewportContainer, and it's the go-to way to display and interact with ViewportTextures. TextureRect is not meant by that. Not only because it's just not designed for it, but also it can display the texture in many different ways. It can be centered, stretched with various ratios or even tiled, and simply handling the entered event for the whole node does not account for that, which IMO makes it quite useless. I mean, if you display a viewport, you expect that the event positions are based on what is displayed, no?

So an alternative to this PR would be to better document the necessary adjustments for interacting with a Viewport in a TextureRect.

That would be the way to go IMO. Especially when we have more nodes that can potentially display a ViewportTexture (Sprite2D, NinePatchRect, or even a Panel with StyleBoxTexture), so adding a special code for one of them is rather odd.

@eviltrout
Copy link
Contributor

I posted this in the issue but TextureRect was only used for the minimum reproducible project. In the actual game the texture is rendered on a 3D object (a computer screen) using a shader, and I use push_input to send it events so you can interact with it in 3D using the mouse.

I think having a 2D interface displayed in a 3D world is a fairly common pattern and this allows you to push the mouse events to it.

@Sauermann
Copy link
Contributor Author

Superseded by #99890

@Sauermann Sauermann closed this Dec 1, 2024
@Sauermann Sauermann removed this from the 4.x milestone Dec 1, 2024
@Sauermann Sauermann deleted the fix-mouse-over-viewport-in-texturerect branch December 1, 2024 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pushing events to Viewports no longer triggers InputEventMouseMotion in _gui_input
3 participants