brainstorming on how to bucket and hand out events

master
mitchellhansen 4 years ago
parent 2ea20c4c0a
commit 0caa685b23

@ -10,20 +10,24 @@ extern crate nalgebra as na;
extern crate rand;
extern crate time;
use std::path::Path;
use std::sync::Arc;
use gilrs::{Button, Event as GilEvent, Gamepad, GamepadId, Gilrs};
use vulkano::instance::debug::DebugCallback;
use vulkano::instance::Instance;
use vulkano::sync;
use vulkano::sync::GpuFuture;
use vulkano_win::VkSurfaceBuild;
use winit::dpi::LogicalSize;
use winit::event::{DeviceEvent, ElementState, Event, VirtualKeyCode, WindowEvent, MouseButton};
use winit::event_loop::{EventLoop, ControlFlow, EventLoopProxy};
use winit::event::{DeviceEvent, ElementState, Event, MouseButton, VirtualKeyCode, WindowEvent};
use winit::event_loop::{ControlFlow, EventLoop, EventLoopProxy};
use winit::platform::unix::WindowBuilderExtUnix;
use winit::window::WindowBuilder;
use crate::button_m::Slider;
use crate::canvas::canvas_frame::{CanvasFrame, Drawable, Eventable};
use crate::canvas::canvas_state::CanvasState;
use crate::canvas::managed::handles::{CanvasFontHandle, CanvasTextureHandle, Handle};
use crate::compute::compu_frame::CompuFrame;
use crate::compute::managed::handles::{CompuBufferHandle, CompuKernelHandle};
@ -33,13 +37,9 @@ use crate::drawables::sprite::Sprite;
use crate::drawables::text::Text;
use crate::util::load_raw;
use crate::util::timer::Timer;
use crate::util::tr_event::TrEvent;
use crate::util::vertex::{TextureVertex3D, VertexType};
use crate::vkprocessor::VkProcessor;
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;
@ -48,12 +48,14 @@ pub mod canvas;
pub mod compute;
pub mod button_m {
use crate::drawables::rect::Rect;
use crate::drawables::sprite::Sprite;
use std::collections::HashSet;
use winit::event::Event;
use crate::canvas::canvas_frame::{Drawable, Eventable};
use crate::drawables::rect::Rect;
use crate::drawables::sprite::Sprite;
use crate::util::vertex::VertexType;
use winit::event::Event;
pub struct Slider {
handle: Rect,
@ -89,7 +91,7 @@ pub mod button_m {
scaler: 255,
position,
size,
value
value,
}
}
}
@ -109,8 +111,8 @@ pub mod button_m {
unimplemented!()
}
}
}
pub fn main() {
hprof::start_frame();
@ -188,7 +190,7 @@ pub fn main() {
let slider = button_m::Slider::new((0.3, 0.04), (-0.5, -0.3), 30000);
// how do i register a sprite to get events...
// explicit is much easier
// explicit is much easieri.lo
//let sfml_sprite = Sprite::new((0.0, -0.5), (0.5, 0.5), 1, sfml_handle.clone());
// let text_sprite = Text::new((-0.1, -0.1), (10.0, 10.0), 1);
@ -202,7 +204,6 @@ 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;
@ -215,7 +216,6 @@ pub fn main() {
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);
@ -232,10 +232,11 @@ pub fn main() {
// }
std::thread::sleep(std::time::Duration::from_millis(50));
}
});
let mut event_stack = Vec::new();
// Events loop is borrowed from the surface
events_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Poll;
@ -243,28 +244,32 @@ pub fn main() {
let mut previous_canvas = CanvasFrame::default();
match event {
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } =>
{
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => {
*control_flow = ControlFlow::Exit
}
Event::WindowEvent { event: WindowEvent::Resized(_), .. } => {
processor.swapchain_recreate_needed = true;
}
Event::UserEvent(TrEvent::KeyHeldEvent { }) => {
}
Event::UserEvent(TrEvent::MouseHeldEvent { }) => {
}
Event::UserEvent(TrEvent::GamepadEvent { gil_event }) => {
Event::WindowEvent {
event: WindowEvent::MouseInput {
device_id, state, button, modifiers
}, ..
} => {
event_stack.push(event.clone());
}
Event::UserEvent(TrEvent::KeyHeldEvent {}) => {}
Event::UserEvent(TrEvent::MouseHeldEvent {}) => {}
Event::UserEvent(TrEvent::GamepadEvent { gil_event }) => {}
Event::DeviceEvent { event: DeviceEvent::Key(keyboard_input), .. } => {
event_stack.push(event);
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());
@ -309,29 +314,22 @@ pub fn main() {
canvas_frame,
compu_frame);
}
}
_ => ()
}
// 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 => {},
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 => {}
}
});
@ -342,18 +340,13 @@ 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();
}
// for i in canvas_state. {
// event_loop_proxy.send_event(TrEvent::MouseClickEvent {
// position: (0.0, 0.0),
// button: MouseButton::Left,
// }).ok();
// }
}

Loading…
Cancel
Save