working on piping events through to the rendered sprites, ztesting, focus, etc.
This commit is contained in:
133
src/main.rs
133
src/main.rs
@@ -18,8 +18,8 @@ use vulkano::sync;
|
||||
use vulkano::sync::GpuFuture;
|
||||
use vulkano_win::VkSurfaceBuild;
|
||||
use winit::dpi::LogicalSize;
|
||||
use winit::event::{DeviceEvent, ElementState, Event, VirtualKeyCode, WindowEvent};
|
||||
use winit::event_loop::{EventLoop, ControlFlow};
|
||||
use winit::event::{DeviceEvent, ElementState, Event, VirtualKeyCode, WindowEvent, MouseButton};
|
||||
use winit::event_loop::{EventLoop, ControlFlow, EventLoopProxy};
|
||||
use winit::platform::unix::WindowBuilderExtUnix;
|
||||
use winit::window::WindowBuilder;
|
||||
|
||||
@@ -39,6 +39,7 @@ use std::path::Path;
|
||||
use gilrs::{Gilrs, Button, Event as GilEvent, GamepadId, Gamepad};
|
||||
use crate::util::tr_event::TrEvent;
|
||||
use crate::button_m::Slider;
|
||||
use crate::canvas::canvas_state::CanvasState;
|
||||
|
||||
pub mod util;
|
||||
pub mod vkprocessor;
|
||||
@@ -103,8 +104,8 @@ pub mod button_m {
|
||||
}
|
||||
}
|
||||
|
||||
impl Eventable for Slider {
|
||||
fn notify(&mut self, event: &Event<'a, _>) -> () {
|
||||
impl<T> Eventable<T> for Slider {
|
||||
fn notify(&mut self, event: &Event<T>) -> () {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
@@ -200,45 +201,47 @@ pub fn main() {
|
||||
|
||||
let event_loop_proxy = events_loop.create_proxy();
|
||||
|
||||
// std::thread::spawn(move || {
|
||||
//
|
||||
// let mut gilrs = Gilrs::new().unwrap();
|
||||
// // Iterate over all connected gamepads
|
||||
// let mut gamepad : Option<Gamepad> = None;
|
||||
// for (_id, gamepad_) in gilrs.gamepads() {
|
||||
// if gamepad_.name() == "PS4" {
|
||||
// gamepad = Some(gamepad_);
|
||||
// }
|
||||
// println!("{} is {:?} {:?}", gamepad_.name(), gamepad_.power_info(), gamepad_.id());
|
||||
// }
|
||||
// let mut active_gamepad = None;
|
||||
//
|
||||
// loop {
|
||||
//
|
||||
// while let Some(GilEvent { id, event, time }) = gilrs.next_event() {
|
||||
// println!("{:?} New event from {}: {:?}", time, id, event);
|
||||
// active_gamepad = Some(id);
|
||||
// event_loop_proxy.send_event(TrEvent::GamepadEvent {
|
||||
// gil_event: GilEvent {id, event, time}
|
||||
// }).ok();
|
||||
// }
|
||||
//
|
||||
// // // You can also use cached gamepad state
|
||||
// // if let Some(gamepad) = active_gamepad.map(|id| gilrs.gamepad(id)) {
|
||||
// // if gamepad.is_pressed(Button::South) {
|
||||
// // println!("Button South is pressed (XBox - A, PS - X)");
|
||||
// // }
|
||||
// // }
|
||||
//
|
||||
// std::thread::sleep(std::time::Duration::from_millis(50));
|
||||
//
|
||||
// }
|
||||
// });
|
||||
std::thread::spawn(move || {
|
||||
|
||||
let mut gilrs = Gilrs::new().unwrap();
|
||||
// Iterate over all connected gamepads
|
||||
let mut gamepad : Option<Gamepad> = None;
|
||||
for (_id, gamepad_) in gilrs.gamepads() {
|
||||
if gamepad_.name() == "PS4" {
|
||||
gamepad = Some(gamepad_);
|
||||
}
|
||||
println!("{} is {:?} {:?}", gamepad_.name(), gamepad_.power_info(), gamepad_.id());
|
||||
}
|
||||
let mut active_gamepad = None;
|
||||
|
||||
loop {
|
||||
|
||||
while let Some(GilEvent { id, event, time }) = gilrs.next_event() {
|
||||
println!("{:?} New event from {}: {:?}", time, id, event);
|
||||
active_gamepad = Some(id);
|
||||
event_loop_proxy.send_event(TrEvent::GamepadEvent {
|
||||
gil_event: GilEvent {id, event, time}
|
||||
}).ok();
|
||||
}
|
||||
|
||||
// // You can also use cached gamepad state
|
||||
// if let Some(gamepad) = active_gamepad.map(|id| gilrs.gamepad(id)) {
|
||||
// if gamepad.is_pressed(Button::South) {
|
||||
// println!("Button South is pressed (XBox - A, PS - X)");
|
||||
// }
|
||||
// }
|
||||
|
||||
std::thread::sleep(std::time::Duration::from_millis(50));
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
// Events loop is borrowed from the surface
|
||||
events_loop.run(move |event, _, control_flow| {
|
||||
*control_flow = ControlFlow::Poll;
|
||||
|
||||
let mut previous_canvas = CanvasFrame::default();
|
||||
|
||||
match event {
|
||||
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } =>
|
||||
{
|
||||
@@ -249,6 +252,29 @@ pub fn main() {
|
||||
}
|
||||
Event::UserEvent(TrEvent::KeyHeldEvent { }) => {
|
||||
}
|
||||
Event::UserEvent(TrEvent::MouseHeldEvent { }) => {
|
||||
}
|
||||
Event::UserEvent(TrEvent::GamepadEvent { gil_event }) => {
|
||||
}
|
||||
Event::DeviceEvent { event: DeviceEvent::Key(keyboard_input), .. } => {
|
||||
|
||||
|
||||
match keyboard_input.virtual_keycode.unwrap() {
|
||||
VirtualKeyCode::A => {
|
||||
if keyboard_input.state == ElementState::Pressed {
|
||||
// processor.save_edges_image();
|
||||
}
|
||||
},
|
||||
VirtualKeyCode::P => {
|
||||
if keyboard_input.state == ElementState::Pressed {
|
||||
let data = processor.read_compute_buffer(compute_buffer.clone());
|
||||
image::save_buffer(&Path::new("image.png"), data.as_slice(), (image_data.1).0, (image_data.1).1, image::RGBA(8));
|
||||
}
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
|
||||
Event::MainEventsCleared => {
|
||||
|
||||
// while let true = processor.is_open() {
|
||||
@@ -270,7 +296,6 @@ pub fn main() {
|
||||
|
||||
let mut canvas_frame = CanvasFrame::default();
|
||||
canvas_frame.draw(&funky_sprite);
|
||||
// canvas_frame.draw(&text_sprite);
|
||||
canvas_frame.draw(&compu_sprite1);
|
||||
canvas_frame.draw(&slider);
|
||||
|
||||
@@ -285,24 +310,6 @@ pub fn main() {
|
||||
compu_frame);
|
||||
}
|
||||
|
||||
}
|
||||
Event::DeviceEvent { event: DeviceEvent::Key(keyboard_input), .. } => {
|
||||
match keyboard_input.virtual_keycode.unwrap() {
|
||||
VirtualKeyCode::A => {
|
||||
if keyboard_input.state == ElementState::Pressed {
|
||||
// processor.save_edges_image();
|
||||
}
|
||||
},
|
||||
VirtualKeyCode::P => {
|
||||
if keyboard_input.state == ElementState::Pressed {
|
||||
let data = processor.read_compute_buffer(compute_buffer.clone());
|
||||
image::save_buffer(&Path::new("image.png"), data.as_slice(), (image_data.1).0, (image_data.1).1, image::RGBA(8));
|
||||
}
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
Event::UserEvent(TrEvent::GamepadEvent { gil_event }) => {
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
@@ -337,7 +344,17 @@ pub fn main() {
|
||||
|
||||
|
||||
|
||||
|
||||
pub fn click_test(event_loop_proxy : EventLoopProxy<TrEvent>, canvas_state: &CanvasState) {
|
||||
|
||||
for i in canvas_state. {
|
||||
|
||||
event_loop_proxy.send_event(TrEvent::MouseClickEvent {
|
||||
position: (0.0, 0.0),
|
||||
button: MouseButton::Left
|
||||
}).ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user