diff --git a/src/main.rs b/src/main.rs index ee053768..b79f339e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,7 @@ use vulkano::sync; use vulkano::sync::GpuFuture; use vulkano_win::VkSurfaceBuild; use winit::dpi::LogicalSize; -use winit::event::{DeviceEvent, ElementState, Event, MouseButton, VirtualKeyCode, WindowEvent}; +use winit::event::{DeviceEvent, ElementState, Event, MouseButton, StartCause, VirtualKeyCode, WindowEvent}; use winit::event_loop::{ControlFlow, EventLoop, EventLoopProxy}; use winit::platform::unix::WindowBuilderExtUnix; use winit::window::WindowBuilder; @@ -113,6 +113,13 @@ pub mod button_m { } } + + + + + + + pub fn main() { hprof::start_frame(); @@ -236,19 +243,24 @@ pub fn main() { }); - let mut canvas_frame = CanvasFrame::default(); - canvas_frame.draw(&funky_sprite); - canvas_frame.draw(&compu_sprite1); - canvas_frame.draw(&slider); + let mut compu_frame = CompuFrame::new(); + // Events loop is borrowed from the surface events_loop.run(move |event, _, control_flow| { *control_flow = ControlFlow::Poll; - let mut previous_canvas = CanvasFrame::default(); + funky_sprite.notify(&event); match event { + Event::NewEvents(cause) => { + if cause == StartCause::Init { + canvas_frame.draw(&funky_sprite); + canvas_frame.draw(&compu_sprite1); + canvas_frame.draw(&slider); + } + } Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => { *control_flow = ControlFlow::Exit } @@ -265,32 +277,39 @@ 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 { - funky_sprite.position.0 += 0.1; - } - } - 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::DeviceEvent { device_id, event } => { + match event { + DeviceEvent::Key(keyboard_input) => { + match keyboard_input.virtual_keycode.unwrap() { + VirtualKeyCode::A => { + if keyboard_input.state == ElementState::Pressed { + } + } + VirtualKeyCode::S => { + if keyboard_input.state == ElementState::Pressed { + + } + } + 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 => { - canvas_frame = CanvasFrame::default(); canvas_frame.draw(&funky_sprite); canvas_frame.draw(&compu_sprite1); canvas_frame.draw(&slider); - let mut compu_frame = CompuFrame::new(); + compu_frame = CompuFrame::new(); compu_frame.add_with_image_swap(compute_buffer.clone(), compute_kernel.clone(), &compu_sprite1); compu_frame.add(compute_buffer.clone(), compute_kernel.clone()); @@ -305,18 +324,19 @@ pub fn main() { } // bucket the events out, but not really - match event { - Event::NewEvents(_) => {} - Event::WindowEvent { window_id, event } => {} - Event::DeviceEvent { device_id, event } => {} - Event::UserEvent(tr_event) => {} - Event::Suspended => {} - Event::Resumed => {} - Event::MainEventsCleared => {} - Event::RedrawRequested(_) => {} - Event::RedrawEventsCleared => {} - Event::LoopDestroyed => {} - } + // match + // event { + // Event::NewEvents(_) => {} + // Event::WindowEvent { window_id, event } => {} + // Event::DeviceEvent { device_id, event } => {} + // Event::UserEvent(tr_event) => {} + // Event::Suspended => {} + // Event::Resumed => {} + // Event::MainEventsCleared => {} + // Event::RedrawRequested(_) => {} + // Event::RedrawEventsCleared => {} + // Event::LoopDestroyed => {} + // } }); drop(l); @@ -336,11 +356,6 @@ pub fn click_test(event_loop_proxy: EventLoopProxy, canvas_state: &Canv } - - - - - // while let true = processor.is_open() { // // // Take care of our timing