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

Expose a CursorPosition resource #5034

Open
alice-i-cecile opened this issue Jun 17, 2022 · 10 comments
Open

Expose a CursorPosition resource #5034

alice-i-cecile opened this issue Jun 17, 2022 · 10 comments
Labels
A-Input Player input via keyboard, mouse, gamepad, and more C-Usability A targeted quality-of-life change that makes Bevy easier to use

Comments

@alice-i-cecile
Copy link
Member

alice-i-cecile commented Jun 17, 2022

What problem does this solve or what need does it fill?

Knowing where your mouse is is useful and should be ergonomic.

What solution would you like?

Store and update a CursorPosition resource, which reads from the Window resource to store an Option<Vec2> representing the physical position of the mouse (or other cursor).

What alternative(s) have you considered?

Compute this manually every time it's needed.

Additional context

This will be impacted by #4530, which will move where this data is stored.

Better APIs to convert between world space and screen space coordinates will make this functionality even more useful; we should add methods on MousePosition to do this once those are established.

@alice-i-cecile alice-i-cecile added D-Trivial Nice and easy! A great choice to get started with Bevy A-Input Player input via keyboard, mouse, gamepad, and more C-Usability A targeted quality-of-life change that makes Bevy easier to use labels Jun 17, 2022
@alice-i-cecile
Copy link
Member Author

We probably want to also record which window the mouse position is associated with, and iterate through all of the windows to check if it's on any of the open windows.

@alice-i-cecile alice-i-cecile changed the title Expose a MousePosition resource Expose a CursorPosition resource Jun 17, 2022
@mockersf
Copy link
Member

right now, such a resource would be equivalent to the resources Windows and getting windows.primary().cursor_position(). I'm not sure it's worth it before #4530

@alice-i-cecile
Copy link
Member Author

The ergonomics and discoverability of that solution are really poor though.

Every time i need to do these or to teach someone how to do this I need to link to the Cheatbook page.

This solution would also be robust to those changes, which would provide a nicer migration path.

@Edwox
Copy link
Contributor

Edwox commented Sep 20, 2022

Hi! I was just wondering if this issue has been resolved or not?

@alice-i-cecile
Copy link
Member Author

Has not been resolved, but Francois's workaround still works :) I'd be happy to review a PR that tackled this before #4530, as that work is shockingly complex.

@mockersf
Copy link
Member

There was a first attempt in #5079 and people decided to wait for #4530 in it

@Edwox
Copy link
Contributor

Edwox commented Sep 20, 2022

Ok, so the best option would probably be to wait for #4530 to be resolved. I have never contributed before, but If there is anything that I could possibly try and improve upon then I would like to give it a try.

@alice-i-cecile alice-i-cecile removed the D-Trivial Nice and easy! A great choice to get started with Bevy label Sep 21, 2022
@wilk10
Copy link
Contributor

wilk10 commented Feb 6, 2023

#4530 has been closed by #5589 . Can this issue also be closed now?

@alice-i-cecile
Copy link
Member Author

I don't think this can be closed: instead, it's no longer blocked.

@dennisorlando
Copy link

dennisorlando commented Aug 20, 2023

right now, such a resource would be equivalent to the resources Windows and getting windows.primary().cursor_position(). I'm not sure it's worth it before #4530

I'm currently implementing "ExtractResource" for a "MousePosition" struct, but given that the "Windows" resource is no longer a resource, I cannot put "Windows" as the associated type of the ExtractResource trait anymore which kind of hurts my feelings (I'm following #6550 to fiddle with compute shaders)
Thus, a cursorposition resource would be useful, even if just as really simple and trivial plugin that you can add to the app like "CursorPositionResourcePlugin", as ugly as that might sound :,)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Input Player input via keyboard, mouse, gamepad, and more C-Usability A targeted quality-of-life change that makes Bevy easier to use
Projects
None yet
Development

No branches or pull requests

5 participants