winit-core: move cursor

This commit is contained in:
Kirill Chibisov 2025-05-01 20:16:34 +09:00
parent cbb29ab526
commit 446482367b
8 changed files with 77 additions and 38 deletions

View file

@ -39,14 +39,14 @@ impl CustomCursor {
let image = &image.0;
let (buffer, canvas) = pool
.create_buffer(
image.width as i32,
image.height as i32,
4 * (image.width as i32),
image.width() as i32,
image.height() as i32,
4 * (image.width() as i32),
Format::Argb8888,
)
.unwrap();
for (canvas_chunk, rgba) in canvas.chunks_exact_mut(4).zip(image.rgba.chunks_exact(4)) {
for (canvas_chunk, rgba) in canvas.chunks_exact_mut(4).zip(image.buffer().chunks_exact(4)) {
// Alpha in buffer is premultiplied.
let alpha = rgba[3] as f32 / 255.;
let r = (rgba[0] as f32 * alpha) as u32;
@ -59,10 +59,10 @@ impl CustomCursor {
CustomCursor {
buffer,
w: image.width as i32,
h: image.height as i32,
hotspot_x: image.hotspot_x as i32,
hotspot_y: image.hotspot_y as i32,
w: image.width() as i32,
h: image.height() as i32,
hotspot_x: image.hotspot_x() as i32,
hotspot_y: image.hotspot_y() as i32,
}
}
}

View file

@ -208,7 +208,7 @@ impl CustomCursor {
};
// Reverse RGBA order to BGRA.
cursor.rgba.chunks_mut(4).for_each(|chunk| {
cursor.buffer_mut().chunks_mut(4).for_each(|chunk| {
let chunk: &mut [u8; 4] = chunk.try_into().unwrap();
chunk[0..3].reverse();
@ -222,11 +222,11 @@ impl CustomCursor {
let cursor = event_loop
.xconn
.create_cursor_from_image(
cursor.width,
cursor.height,
cursor.hotspot_x,
cursor.hotspot_y,
&cursor.rgba,
cursor.width(),
cursor.height(),
cursor.hotspot_x(),
cursor.hotspot_y(),
cursor.buffer(),
)
.map_err(|err| os_error!(err))?;