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

WIP custom cursors #14196

Closed
wants to merge 1 commit into from
Closed

WIP custom cursors #14196

wants to merge 1 commit into from

Conversation

amytimed
Copy link

@amytimed amytimed commented Jul 6, 2024

hello, this PR is a wip draft PR to add custom cursor support to bevy

Objective

Solution

  • Splits CursorIcon into two enum variants: SystemCursor and CustomCursor

Testing

As this is an unfinished draft PR, it has not yet been tested

@alice-i-cecile alice-i-cecile added this to the 0.15 milestone Jul 6, 2024
@alice-i-cecile alice-i-cecile added A-Assets Load files from disk to use for things like images, models, and sounds A-Windowing Platform-agnostic interface layer to run your app in C-Feature A new feature, making something new possible and removed A-Assets Load files from disk to use for things like images, models, and sounds labels Jul 6, 2024
@SpecificProtagonist
Copy link
Contributor

Does it make sense to flatten SystemCursor into CursorIcon?

Also, we might want CustomCursor to consist of a Handle<Image> + hotspot for easy use with assets, though that means you need bevy_render for custom cursors, so maybe a convenience method that converts the image to Rgba will have to do.

@alice-i-cecile alice-i-cecile added X-Contentious There are nontrivial implications that should be thought through S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Aug 5, 2024
@alice-i-cecile
Copy link
Member

Closing in favor of #14284.

github-merge-queue bot pushed a commit that referenced this pull request Aug 12, 2024
# Objective

- Add custom images as cursors
- Fixes #9557 

## Solution

- Change cursor type to accommodate both native and image cursors
- I don't really like this solution because I couldn't use
`Handle<Image>` directly. I would need to import `bevy_assets` and that
causes a circular dependency. Alternatively we could use winit's
`CustomCursor` smart pointers, but that seems hard because the event
loop is needed to create those and is not easily accessable for users.
So now I need to copy around rgba buffers which is sad.
- I use a cache because especially on the web creating cursor images is
really slow
- Sorry to #14196 for yoinking, I just wanted to make a quick solution
for myself and thought that I should probably share it too.

Update:
- Now uses `Handle<Image>`, reads rgba data in `bevy_render` and uses
resources to send the data to `bevy_winit`, where the final cursors are
created.

## Testing

- Added example which works fine at least on Linux Wayland (winit side
has been tested with all platforms).
- I haven't tested if the url cursor works.

## Migration Guide

- `CursorIcon` is no longer a field in `Window`, but a separate
component can be inserted to a window entity. It has been changed to an
enum that can hold custom images in addition to system icons.
- `Cursor` is renamed to `CursorOptions` and `cursor` field of `Window`
is renamed to `cursor_options`
- `CursorIcon` is renamed to `SystemCursorIcon`

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: Jan Hohenheim <jan@hohenheim.ch>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Windowing Platform-agnostic interface layer to run your app in C-Feature A new feature, making something new possible S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged X-Contentious There are nontrivial implications that should be thought through
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add first-party asset-based cursor icons to Bevy
3 participants