working on piping events through to the rendered sprites, ztesting, focus, etc.

master
mitchellhansen 4 years ago
parent ea98b7e7d6
commit 2ea20c4c0a

@ -386,13 +386,14 @@ impl CanvasState {
/// Consume and allocate the canvas frame data to the GPU /// Consume and allocate the canvas frame data to the GPU
pub fn allocate(&mut self, canvas_frame: CanvasFrame) -> CanvasFrameAllocation { pub fn allocate(&mut self, canvas_frame: CanvasFrame) -> CanvasFrameAllocation {
let mut colored_vertex_buffer: Vec<ColorVertex3D> = Vec::default(); let mut colored_vertex_buffer: Vec<ColorVertex3D> = Vec::default();
let mut textured_vertex_buffer: HashMap<Arc<CanvasTextureHandle>, Vec<TextureVertex3D>> = HashMap::new(); let mut textured_vertex_buffer: HashMap<Arc<CanvasTextureHandle>, Vec<TextureVertex3D>> = HashMap::new();
let mut image_vertex_buffer: HashMap<Arc<CanvasImageHandle>, Vec<ImageVertex3D>> = HashMap::new(); let mut image_vertex_buffer: HashMap<Arc<CanvasImageHandle>, Vec<ImageVertex3D>> = HashMap::new();
let mut text_instances: HashMap<Arc<CanvasFontHandle>, Vec<TextVertex3D>> = HashMap::new(); let mut text_instances: HashMap<Arc<CanvasFontHandle>, Vec<TextVertex3D>> = HashMap::new();
let mut text_vertex_buffer: Vec<ColorVertex3D> = Vec::new(); let mut text_vertex_buffer: Vec<ColorVertex3D> = Vec::new();
// separate the mux of vertex containers back out
for value in canvas_frame.map { for value in canvas_frame.map {
match value { match value {
VertexType::TextureType(vertices, handle) => { VertexType::TextureType(vertices, handle) => {

@ -18,8 +18,8 @@ use vulkano::sync;
use vulkano::sync::GpuFuture; use vulkano::sync::GpuFuture;
use vulkano_win::VkSurfaceBuild; use vulkano_win::VkSurfaceBuild;
use winit::dpi::LogicalSize; use winit::dpi::LogicalSize;
use winit::event::{DeviceEvent, ElementState, Event, VirtualKeyCode, WindowEvent}; use winit::event::{DeviceEvent, ElementState, Event, VirtualKeyCode, WindowEvent, MouseButton};
use winit::event_loop::{EventLoop, ControlFlow}; use winit::event_loop::{EventLoop, ControlFlow, EventLoopProxy};
use winit::platform::unix::WindowBuilderExtUnix; use winit::platform::unix::WindowBuilderExtUnix;
use winit::window::WindowBuilder; use winit::window::WindowBuilder;
@ -39,6 +39,7 @@ use std::path::Path;
use gilrs::{Gilrs, Button, Event as GilEvent, GamepadId, Gamepad}; use gilrs::{Gilrs, Button, Event as GilEvent, GamepadId, Gamepad};
use crate::util::tr_event::TrEvent; use crate::util::tr_event::TrEvent;
use crate::button_m::Slider; use crate::button_m::Slider;
use crate::canvas::canvas_state::CanvasState;
pub mod util; pub mod util;
pub mod vkprocessor; pub mod vkprocessor;
@ -103,8 +104,8 @@ pub mod button_m {
} }
} }
impl Eventable for Slider { impl<T> Eventable<T> for Slider {
fn notify(&mut self, event: &Event<'a, _>) -> () { fn notify(&mut self, event: &Event<T>) -> () {
unimplemented!() unimplemented!()
} }
} }
@ -200,45 +201,47 @@ pub fn main() {
let event_loop_proxy = events_loop.create_proxy(); let event_loop_proxy = events_loop.create_proxy();
// std::thread::spawn(move || { std::thread::spawn(move || {
//
// let mut gilrs = Gilrs::new().unwrap(); let mut gilrs = Gilrs::new().unwrap();
// // Iterate over all connected gamepads // Iterate over all connected gamepads
// let mut gamepad : Option<Gamepad> = None; let mut gamepad : Option<Gamepad> = None;
// for (_id, gamepad_) in gilrs.gamepads() { for (_id, gamepad_) in gilrs.gamepads() {
// if gamepad_.name() == "PS4" { if gamepad_.name() == "PS4" {
// gamepad = Some(gamepad_); gamepad = Some(gamepad_);
// } }
// println!("{} is {:?} {:?}", gamepad_.name(), gamepad_.power_info(), gamepad_.id()); println!("{} is {:?} {:?}", gamepad_.name(), gamepad_.power_info(), gamepad_.id());
// } }
// let mut active_gamepad = None; let mut active_gamepad = None;
//
// loop { loop {
//
// while let Some(GilEvent { id, event, time }) = gilrs.next_event() { while let Some(GilEvent { id, event, time }) = gilrs.next_event() {
// println!("{:?} New event from {}: {:?}", time, id, event); println!("{:?} New event from {}: {:?}", time, id, event);
// active_gamepad = Some(id); active_gamepad = Some(id);
// event_loop_proxy.send_event(TrEvent::GamepadEvent { event_loop_proxy.send_event(TrEvent::GamepadEvent {
// gil_event: GilEvent {id, event, time} gil_event: GilEvent {id, event, time}
// }).ok(); }).ok();
// } }
//
// // // You can also use cached gamepad state // // You can also use cached gamepad state
// // if let Some(gamepad) = active_gamepad.map(|id| gilrs.gamepad(id)) { // if let Some(gamepad) = active_gamepad.map(|id| gilrs.gamepad(id)) {
// // if gamepad.is_pressed(Button::South) { // if gamepad.is_pressed(Button::South) {
// // println!("Button South is pressed (XBox - A, PS - X)"); // println!("Button South is pressed (XBox - A, PS - X)");
// // } // }
// // } // }
//
// std::thread::sleep(std::time::Duration::from_millis(50)); std::thread::sleep(std::time::Duration::from_millis(50));
//
// } }
// }); });
// Events loop is borrowed from the surface // Events loop is borrowed from the surface
events_loop.run(move |event, _, control_flow| { events_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Poll; *control_flow = ControlFlow::Poll;
let mut previous_canvas = CanvasFrame::default();
match event { match event {
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => Event::WindowEvent { event: WindowEvent::CloseRequested, .. } =>
{ {
@ -249,6 +252,29 @@ pub fn main() {
} }
Event::UserEvent(TrEvent::KeyHeldEvent { }) => { 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 => { Event::MainEventsCleared => {
// while let true = processor.is_open() { // while let true = processor.is_open() {
@ -270,7 +296,6 @@ pub fn main() {
let mut canvas_frame = CanvasFrame::default(); let mut canvas_frame = CanvasFrame::default();
canvas_frame.draw(&funky_sprite); canvas_frame.draw(&funky_sprite);
// canvas_frame.draw(&text_sprite);
canvas_frame.draw(&compu_sprite1); canvas_frame.draw(&compu_sprite1);
canvas_frame.draw(&slider); canvas_frame.draw(&slider);
@ -285,24 +310,6 @@ pub fn main() {
compu_frame); 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();
}
}

@ -5,6 +5,13 @@ use winit::dpi::{PhysicalPosition, PhysicalSize};
use gilrs::Event as GilEvent; use gilrs::Event as GilEvent;
pub enum TrEvent { pub enum TrEvent {
MouseFocusEvent {
position : (f32, f32),
},
MouseClickEvent {
position : (f32, f32),
button : MouseButton,
},
MouseHeldEvent { MouseHeldEvent {
}, },

@ -44,6 +44,7 @@ pub struct VkProcessor {
/// State holding textures, images, and their related vertex buffers /// State holding textures, images, and their related vertex buffers
canvas_state: CanvasState, canvas_state: CanvasState,
/// State holding /// State holding
compute_state: CompuState, 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 /// Using the surface, we calculate the surface capabilities and create the swapchain and swapchain images
pub fn create_swapchain(&mut self, instance: Arc<Instance>, surface: Arc<Surface<Window>>) { pub fn create_swapchain(&mut self, instance: Arc<Instance>, surface: Arc<Surface<Window>>) {
let (mut swapchain, images) = { let (mut swapchain, images) = {

Loading…
Cancel
Save