39 lines
1.2 KiB
Rust
39 lines
1.2 KiB
Rust
use kernel_macros::include_bitmap_image;
|
|
|
|
use crate::draw::{Color, Draw};
|
|
|
|
pub const CURSOR_WIDTH: usize = 8;
|
|
pub const CURSOR_HEIGHT: usize = 10;
|
|
pub const CURSOR_SIZE: usize = (CURSOR_HEIGHT * CURSOR_WIDTH) / 8;
|
|
pub static CURSOR: [u8; CURSOR_SIZE] = include_bitmap_image! {"assets/cursor.png"};
|
|
|
|
pub fn draw_cursor<T: Draw>(drawer: &mut T, x: u16, y: u16) {
|
|
for i in 0..CURSOR_HEIGHT {
|
|
for j in 0..CURSOR_WIDTH {
|
|
let pos = i * CURSOR_WIDTH + j;
|
|
if CURSOR[pos / 8] & (1 << (pos % 8)) != 0 {
|
|
unsafe {
|
|
drawer.write_pixel_unsafe(
|
|
x.saturating_add(j as u16),
|
|
y.saturating_add(i as u16),
|
|
Color::WHITE,
|
|
)
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|
|
pub fn clear_cursor<T: Draw>(drawer: &mut T, x: u16, y: u16) {
|
|
for i in 0..CURSOR_HEIGHT {
|
|
for j in 0..CURSOR_WIDTH {
|
|
unsafe {
|
|
drawer.write_pixel_unsafe(
|
|
x.saturating_add(j as u16),
|
|
y.saturating_add(i as u16),
|
|
Color::BLACK,
|
|
)
|
|
};
|
|
}
|
|
}
|
|
}
|