Add WindowClosed event to experimental fb

This commit is contained in:
Mark McCaskey 2020-01-09 12:11:34 -05:00
parent 8e6015f231
commit b08b65913b
2 changed files with 6 additions and 0 deletions

View File

@ -114,6 +114,9 @@ impl FrameBufferState {
pub fn fill_input_buffer(&mut self) -> Option<()> {
let keys_pressed = self.keys_pressed.iter().cloned().collect::<Vec<Key>>();
if !self.window.is_open() {
self.push_input_event(InputEvent::WindowClosed)?;
}
for key in keys_pressed {
if self.window.is_key_released(key) {
self.keys_pressed.remove(&key);

View File

@ -6,6 +6,7 @@ pub const KEY_RELEASE: u8 = 3;
pub const MOUSE_PRESS_LEFT: u8 = 4;
pub const MOUSE_PRESS_RIGHT: u8 = 5;
pub const MOUSE_PRESS_MIDDLE: u8 = 7;
pub const WINDOW_CLOSED: u8 = 8;
use minifb::{Key, MouseButton};
@ -15,6 +16,7 @@ pub enum InputEvent {
KeyRelease(Key),
MouseEvent(u32, u32, MouseButton),
MouseMoved(u32, u32),
WindowClosed,
}
/// Returns the tag as the first return value
@ -58,6 +60,7 @@ pub fn bytes_for_input_event(input_event: InputEvent) -> (u8, [u8; 8], usize) {
}
(MOUSE_MOVE, data, 8)
}
InputEvent::WindowClosed => (WINDOW_CLOSED, data, 0),
}
}