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

Add first-party asset-based cursor icons to Bevy #9557

Open
alice-i-cecile opened this issue Aug 24, 2023 · 9 comments
Open

Add first-party asset-based cursor icons to Bevy #9557

alice-i-cecile opened this issue Aug 24, 2023 · 9 comments
Labels
A-Rendering Drawing game state to the screen A-UI Graphical user interfaces, styles, layouts, and widgets A-Windowing Platform-agnostic interface layer to run your app in C-Enhancement A new feature

Comments

@alice-i-cecile
Copy link
Member

FYI, winit's existing set_cursor_icon method is inadequate for games: it only supports a fixed, unstyled list and relies on OS support. In games, you often need new options (a mining pick! an axe! a sword!), and virtually always want custom assets.

This isn't something winit can fix, since it doesn't come with an asset / rendering solution. Instead, we should build our own cursor icon solution, with a "native" variant that just uses the OS ones provided by winit.

Originally posted by @alice-i-cecile in #9538 (reply in thread)

@alice-i-cecile alice-i-cecile added C-Enhancement A new feature A-Rendering Drawing game state to the screen A-UI Graphical user interfaces, styles, layouts, and widgets labels Aug 24, 2023
@alice-i-cecile
Copy link
Member Author

The first PR for this should be quite simple: just create a UI element from an image, and keep it synced with the mouse while disabling the built in cursor.

Probably have a CursorBundle or something, and then just let users manually swap the image handle as needed.

Picking-integrated reactivity can come later.

@aevyrie
Copy link
Member

aevyrie commented Nov 11, 2023

We actually need winit support to do this correctly. Relying on the rendered window to draw a cursor is never going to have the same low latency as the OS cursor.

rust-windowing/winit#3005

I've noticed other games with custom cursors have properties that prove this:

  • during game streaming, the custom cursor will become visible before the rendered output is visible
  • the cursor can leave the frame of the window when the cursor is positioned in the bottom right
  • the latency and update rate is perfect even when the game is not running amazingly well

Regardless, I agree an asset-based solution would be nice, but I wanted to point out we do need to use OS APIs to do this without jank.

@aevyrie
Copy link
Member

aevyrie commented Nov 11, 2023

More proof this is possible, navigate to this page and hover over the demo to get the rainbow icon.

https://webdesign.tutsplus.com/how-to-create-a-custom-mouse-cursor-with-css-or-javascript--cms-106724t

Scroll up so the demo is at the bottom edge of the screen. You will be able to see the custom cursor image hanging outside the bounds of the browser window. Additionally, the latency is perfect.

@alice-i-cecile
Copy link
Member Author

Definitely agree that we should hook into the OS layer.

Unsure if there's a sensible way to do this with winit itself though 🤔 It's not asset or graphics aware. Same sort of problem we ran into with window icons.

@aevyrie
Copy link
Member

aevyrie commented Nov 12, 2023

The winit API should just accept image bytes for the Custom variant. We just need a layer of indirection on the current Window cursor setting that accepts an asset handle once winit supports the feature, and a plugin that updates it with the data in the Handle<Image>.

@Friz64
Copy link
Contributor

Friz64 commented Dec 16, 2023

rust-windowing/winit#3218 has just been merged 🎉

@alice-i-cecile alice-i-cecile added the A-Windowing Platform-agnostic interface layer to run your app in label Dec 17, 2023
@djeedai
Copy link
Contributor

djeedai commented Dec 21, 2023

Came to say the same :) Is there a tracking issue for upgrading winit itself, or a process, or someone usually handling it? Note that a winit version with that feature did not release yet, but that should happen soon I guess.

@alice-i-cecile
Copy link
Member Author

#10702 just bumped the winit version to the latest release :) For the next release, whoever wants to can claim it. Just split apart the "minimal migration" from the "use new feature" for easier reviews.

@eero-lehtinen
Copy link
Contributor

Winit maintainers said that the changes won't be released in a patch version, so we might need to wait for a while. They also want to bake the feature a little bit more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen A-UI Graphical user interfaces, styles, layouts, and widgets A-Windowing Platform-agnostic interface layer to run your app in C-Enhancement A new feature
Projects
None yet
Development

No branches or pull requests

5 participants