2016-01-30 06:16:00 +11:00
|
|
|
extern crate minifb;
|
|
|
|
|
2016-02-01 04:34:05 +11:00
|
|
|
use minifb::{MouseButton, MouseMode, Window, Key, Scale, WindowOptions};
|
2016-01-30 06:16:00 +11:00
|
|
|
|
|
|
|
const WIDTH: usize = 640;
|
|
|
|
const HEIGHT: usize = 360;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut buffer: Vec<u32> = vec![0; WIDTH * HEIGHT];
|
|
|
|
|
2016-02-01 04:34:05 +11:00
|
|
|
let mut window = match Window::new("Mouse Draw - Press ESC to exit", WIDTH, HEIGHT,
|
|
|
|
WindowOptions {
|
|
|
|
scale: Scale::X2,
|
|
|
|
..WindowOptions::default()
|
|
|
|
}) {
|
2016-01-30 06:16:00 +11:00
|
|
|
Ok(win) => win,
|
|
|
|
Err(err) => {
|
|
|
|
println!("Unable to create window {}", err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
while window.is_open() && !window.is_key_down(Key::Escape) {
|
|
|
|
window.get_mouse_pos(MouseMode::Discard).map(|mouse| {
|
|
|
|
let screen_pos = ((mouse.1 as usize) * WIDTH) + mouse.0 as usize;
|
|
|
|
|
|
|
|
if window.get_mouse_down(MouseButton::Left) {
|
|
|
|
buffer[screen_pos] = 0x00ffffff;
|
|
|
|
}
|
|
|
|
|
|
|
|
if window.get_mouse_down(MouseButton::Right) {
|
|
|
|
buffer[screen_pos] = 0;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
window.get_scroll_wheel().map(|scroll| {
|
|
|
|
println!("Scrolling {} - {}", scroll.0, scroll.1);
|
|
|
|
});
|
|
|
|
|
2016-02-01 04:34:05 +11:00
|
|
|
window.update_with_buffer(&buffer);
|
2016-01-30 06:16:00 +11:00
|
|
|
}
|
|
|
|
}
|