Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically transform cursor hotspot user asks to flip cursor image (…
…#17540) # Objective - As discussed in #17276 (comment), we should transform the cursor's hotspot if the user is asking for the image to be flipped. - This becomes more important when a `scale` transform option exists. It's harder for users to transform the hotspot themselves when using `scale` because they'd need to look up the image to get its dimensions. Instead, we let Bevy handle the hotspot transforms and make the `hotspot` field the "original/source" hotspot. - Refs #17276. ## Solution - When the image needs to be transformed, also transform the hotspot. If the image does not need to be transformed (i.e. fast path), no hotspot transformation is applied. ## Testing - Ran the example: `cargo run --example custom_cursor_image --features=custom_cursor`. - Add unit tests for the hotspot transform function. - I also ran the example I have in my `bevy_cursor_kit` crate, which I think is a good illustration of the reason for this PR. - In the following videos, there is an arrow pointing up. The button hover event fires as I move the mouse over it. - When I press `Y`, the cursor flips. - In the first video, on `bevy@main` **before** this PR, notice how the hotspot is wrong after flipping and no longer hovering the button. The arrow head and hotspot are no longer synced. - In the second video, on the branch of **this** PR, notice how the hotspot gets flipped as soon as I press `Y` and the cursor arrow head is in the correct position on the screen and still hovering the button. Speaking back to the objective listed at the start: The user originally defined the _source_ hotspot for the arrow. Later, they decide they want to flip the cursor vertically: It's nice that Bevy can automatically flip the _source_ hotspot for them at the same time it flips the _source_ image. First video (main): https://github.com/user-attachments/assets/1955048c-2f85-4951-bfd6-f0e7cfef0cf8 Second video (this PR): https://github.com/user-attachments/assets/73cb9095-ecb5-4bfd-af5b-9f772e92bd16
- Loading branch information