diff --git a/src/canvas/canvas_state.rs b/src/canvas/canvas_state.rs index 120e4953..046b14ae 100644 --- a/src/canvas/canvas_state.rs +++ b/src/canvas/canvas_state.rs @@ -386,13 +386,14 @@ impl CanvasState { /// Consume and allocate the canvas frame data to the GPU pub fn allocate(&mut self, canvas_frame: CanvasFrame) -> CanvasFrameAllocation { + let mut colored_vertex_buffer: Vec = Vec::default(); let mut textured_vertex_buffer: HashMap, Vec> = HashMap::new(); let mut image_vertex_buffer: HashMap, Vec> = HashMap::new(); let mut text_instances: HashMap, Vec> = HashMap::new(); - let mut text_vertex_buffer: Vec = Vec::new(); + // separate the mux of vertex containers back out for value in canvas_frame.map { match value { VertexType::TextureType(vertices, handle) => { diff --git a/src/main.rs b/src/main.rs index 87698ff4..97890eae 100644 --- a/src/main.rs +++ b/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 Eventable for Slider { + fn notify(&mut self, event: &Event) -> () { 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 = 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 = 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, canvas_state: &CanvasState) { + + for i in canvas_state. { + event_loop_proxy.send_event(TrEvent::MouseClickEvent { + position: (0.0, 0.0), + button: MouseButton::Left + }).ok(); + } + +} diff --git a/src/util/tr_event.rs b/src/util/tr_event.rs index 63f3cd69..9d53bbc7 100644 --- a/src/util/tr_event.rs +++ b/src/util/tr_event.rs @@ -5,6 +5,13 @@ use winit::dpi::{PhysicalPosition, PhysicalSize}; use gilrs::Event as GilEvent; pub enum TrEvent { + MouseFocusEvent { + position : (f32, f32), + }, + MouseClickEvent { + position : (f32, f32), + button : MouseButton, + }, MouseHeldEvent { }, diff --git a/src/vkprocessor.rs b/src/vkprocessor.rs index 3cb6acfe..b2f64176 100644 --- a/src/vkprocessor.rs +++ b/src/vkprocessor.rs @@ -44,6 +44,7 @@ pub struct VkProcessor { /// State holding textures, images, and their related vertex buffers canvas_state: CanvasState, + /// State holding compute_state: CompuState, @@ -89,6 +90,10 @@ impl VkProcessor { } } + pub fn get_canvas_state(&self) -> &CanvasState { + &self.canvas_state + } + /// Using the surface, we calculate the surface capabilities and create the swapchain and swapchain images pub fn create_swapchain(&mut self, instance: Arc, surface: Arc>) { let (mut swapchain, images) = {