mirror of
https://github.com/exoticorn/microw8.git
synced 2026-01-20 11:16:42 +01:00
implement input for gpu window
This commit is contained in:
@@ -300,6 +300,9 @@ impl Window {
|
|||||||
|
|
||||||
surface.configure(&device, &surface_config);
|
surface.configure(&device, &surface_config);
|
||||||
|
|
||||||
|
let mut reset = false;
|
||||||
|
let mut gamepad = 0;
|
||||||
|
|
||||||
event_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
let _ = (&window, &instance, &surface, &adapter, &device);
|
let _ = (&window, &instance, &surface, &adapter, &device);
|
||||||
|
|
||||||
@@ -314,6 +317,19 @@ impl Window {
|
|||||||
}
|
}
|
||||||
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
||||||
WindowEvent::KeyboardInput { input, .. } => {
|
WindowEvent::KeyboardInput { input, .. } => {
|
||||||
|
fn gamepad_button(input: &winit::event::KeyboardInput) -> u32 {
|
||||||
|
match input.scancode {
|
||||||
|
103 => 1,
|
||||||
|
108 => 2,
|
||||||
|
105 => 4,
|
||||||
|
106 => 8,
|
||||||
|
44 => 16,
|
||||||
|
45 => 32,
|
||||||
|
30 => 64,
|
||||||
|
31 => 128,
|
||||||
|
_ => 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
if input.state == winit::event::ElementState::Pressed {
|
if input.state == winit::event::ElementState::Pressed {
|
||||||
match input.virtual_keycode {
|
match input.virtual_keycode {
|
||||||
Some(VirtualKeyCode::Escape) => *control_flow = ControlFlow::Exit,
|
Some(VirtualKeyCode::Escape) => *control_flow = ControlFlow::Exit,
|
||||||
@@ -324,8 +340,13 @@ impl Window {
|
|||||||
Some(Fullscreen::Borderless(None))
|
Some(Fullscreen::Borderless(None))
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Some(VirtualKeyCode::R) => reset = true,
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gamepad |= gamepad_button(&input);
|
||||||
|
} else {
|
||||||
|
gamepad &= !gamepad_button(&input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
@@ -342,9 +363,10 @@ impl Window {
|
|||||||
framebuffer: &framebuffer_texture,
|
framebuffer: &framebuffer_texture,
|
||||||
palette: &palette_texture,
|
palette: &palette_texture,
|
||||||
},
|
},
|
||||||
0,
|
gamepad,
|
||||||
false,
|
reset,
|
||||||
);
|
);
|
||||||
|
reset = false;
|
||||||
*control_flow = ControlFlow::WaitUntil(next_frame);
|
*control_flow = ControlFlow::WaitUntil(next_frame);
|
||||||
|
|
||||||
let output = surface.get_current_texture().unwrap();
|
let output = surface.get_current_texture().unwrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user