parent
dd13ccda4c
commit
21df84b7f4
3 changed files with 11 additions and 7 deletions
|
|
@ -56,6 +56,7 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
let custom_cursors = [
|
let custom_cursors = [
|
||||||
decode_cursor(include_bytes!("data/cross.png"), &event_loop),
|
decode_cursor(include_bytes!("data/cross.png"), &event_loop),
|
||||||
decode_cursor(include_bytes!("data/cross2.png"), &event_loop),
|
decode_cursor(include_bytes!("data/cross2.png"), &event_loop),
|
||||||
|
decode_cursor(include_bytes!("data/gradient.png"), &event_loop),
|
||||||
];
|
];
|
||||||
|
|
||||||
event_loop.run(move |event, _elwt| match event {
|
event_loop.run(move |event, _elwt| match event {
|
||||||
|
|
@ -72,7 +73,7 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
Key::Character("1") => {
|
Key::Character("1") => {
|
||||||
log::debug!("Setting cursor to {:?}", cursor_idx);
|
log::debug!("Setting cursor to {:?}", cursor_idx);
|
||||||
window.set_cursor(custom_cursors[cursor_idx].clone());
|
window.set_cursor(custom_cursors[cursor_idx].clone());
|
||||||
cursor_idx = (cursor_idx + 1) % 2;
|
cursor_idx = (cursor_idx + 1) % 3;
|
||||||
}
|
}
|
||||||
Key::Character("2") => {
|
Key::Character("2") => {
|
||||||
log::debug!("Setting cursor icon to default");
|
log::debug!("Setting cursor icon to default");
|
||||||
|
|
|
||||||
BIN
examples/data/gradient.png
Normal file
BIN
examples/data/gradient.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 229 B |
|
|
@ -37,12 +37,15 @@ impl CustomCursor {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
for (canvas_chunk, rgba_chunk) in canvas.chunks_exact_mut(4).zip(image.rgba.chunks_exact(4))
|
for (canvas_chunk, rgba) in canvas.chunks_exact_mut(4).zip(image.rgba.chunks_exact(4)) {
|
||||||
{
|
// Alpha in buffer is premultiplied.
|
||||||
canvas_chunk[0] = rgba_chunk[2];
|
let alpha = rgba[3] as f32 / 255.;
|
||||||
canvas_chunk[1] = rgba_chunk[1];
|
let r = (rgba[0] as f32 * alpha) as u32;
|
||||||
canvas_chunk[2] = rgba_chunk[0];
|
let g = (rgba[1] as f32 * alpha) as u32;
|
||||||
canvas_chunk[3] = rgba_chunk[3];
|
let b = (rgba[2] as f32 * alpha) as u32;
|
||||||
|
let color = ((rgba[3] as u32) << 24) + (r << 16) + (g << 8) + b;
|
||||||
|
let array: &mut [u8; 4] = canvas_chunk.try_into().unwrap();
|
||||||
|
*array = color.to_le_bytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
CustomCursor {
|
CustomCursor {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue