added event translation

a-star
mitchellhansen 4 years ago
parent 2e33c9c75e
commit 9719675465

@ -36,7 +36,7 @@ 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::tr_event::{TrEventExtension, TrEvent};
use crate::util::vertex::{TextureVertex3D, VertexTypeContainer};
use crate::vkprocessor::VkProcessor;
use crate::drawables::slider::Slider;
@ -53,7 +53,7 @@ use specs::prelude::*;
use vulkano::swapchain::Surface;
struct Draws(Box<dyn Drawable + Sync + Send>, Box<dyn Eventable<TrEvent> + Sync + Send>);
struct Draws(Box<dyn Drawable + Sync + Send>, Box<dyn Eventable<TrEventExtension> + Sync + Send>);
impl Component for Draws {
type Storage = VecStorage<Self>;
@ -125,7 +125,6 @@ impl<'a> System<'a> for RenderSystem {
for draw_data in (&draw).join() {
let size = state.window_size.clone();
}
vk_processor.run(&state.surface.clone().unwrap(),
@ -145,13 +144,13 @@ impl<'a> System<'a> for EventSystem {
);
fn run(&mut self, (mut draw, mut state, mut vk_processor): Self::SystemData) {
for draw_data in (&draw).join() {
draw_data.1.notify()
//draw_data.1.notify()
}
}
}
struct Eventt(u32);
pub fn main() {
//hprof::start_frame();
@ -167,7 +166,7 @@ pub fn main() {
println!("Debug callback: {:?}", msg.description);
}).ok();
let mut events_loop = EventLoop::<TrEvent>::with_user_event();
let mut events_loop = EventLoop::<TrEventExtension>::with_user_event();
let mut surface = WindowBuilder::new()
.with_inner_size(LogicalSize::new(800, 800))
@ -223,6 +222,7 @@ pub fn main() {
world.register::<Geom>();
world.register::<Draws>();
world.insert::<VkProcessor>(processor);
world.insert::<Vec<TrEvent<TrEventExtension>>>(Vec::new());
world.insert::<PersistentState>(PersistentState {
surface: Some(surface.clone()),
window_size: (0, 0),
@ -279,7 +279,7 @@ pub fn main() {
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 {
event_loop_proxy.send_event(TrEventExtension::GamepadEvent {
gil_event: GilEvent { id, event, time }
}).ok();
}
@ -295,16 +295,18 @@ pub fn main() {
}
});
// Events loop is borrowed from the surface
events_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Poll;
match event {
Event::NewEvents(cause) => {
if cause == StartCause::Init {
world.write_resource::<PersistentState>()
.window_size = surface.window().inner_size().into();
} else {
world.write_resource::<Vec<TrEvent<TrEventExtension>>>().clear();
}
}
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => {
@ -316,37 +318,6 @@ pub fn main() {
world.write_resource::<PersistentState>()
.window_size = (new_size.width, new_size.height);
}
Event::WindowEvent {
event: WindowEvent::MouseInput {
device_id, state, button, modifiers
}, ..
} => {}
Event::UserEvent(TrEvent::KeyHeldEvent {}) => {}
Event::UserEvent(TrEvent::MouseHeldEvent {}) => {}
Event::UserEvent(TrEvent::GamepadEvent { gil_event }) => {}
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 = world.write_resource::<VkProcessor>().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 => {
elapsed_time = timer.elap_time();
delta_time = elapsed_time - current_time;
@ -357,16 +328,51 @@ pub fn main() {
accumulator_time += delta_time;
// This dispatches all the systems in parallel (but blocking).
world.write_resource::<PersistentState>().delta_time = delta_time;
world.write_resource::<PersistentState>()
.delta_time = delta_time;
dispatcher.dispatch(&mut world);
// while (accumulator_time - step_size) >= step_size {
// accumulator_time -= step_size;
// }
}
_ => ()
_ => {}
}
world.write_resource::<Vec<TrEvent<TrEventExtension>>>().push(event.into());
//
// match event {
// Event::UserEvent(TrEventExtension::KeyHeldEvent {}) => {}
// Event::UserEvent(TrEventExtension::MouseHeldEvent {}) => {}
// Event::UserEvent(TrEventExtension::GamepadEvent { gil_event }) => {}
// 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 = world.write_resource::<VkProcessor>().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));
// }
// }
// _ => ()
// }
// }
// _ => {}
// }
// }
//
// _ => ()
// }
// bucket the events out, but not really
// match
// event {

@ -1,25 +1,209 @@
use winit::window::WindowId;
use winit::event::{WindowEvent, DeviceId, DeviceEvent, KeyboardInput, ModifiersState, MouseScrollDelta, TouchPhase, ElementState, MouseButton, AxisId, Touch};
use winit::window::{WindowId, Theme};
use winit::event::{WindowEvent, DeviceId, DeviceEvent, KeyboardInput, ModifiersState, MouseScrollDelta, TouchPhase, ElementState, MouseButton, AxisId, Touch, StartCause, Event};
use std::path::PathBuf;
use winit::dpi::{PhysicalPosition, PhysicalSize};
use gilrs::Event as GilEvent;
use vulkano::pipeline::shader::GeometryShaderExecutionMode::TrianglesWithAdjacency;
pub enum TrEvent {
MouseFocusEvent {
position : (f32, f32),
},
MouseClickEvent {
position : (f32, f32),
button : MouseButton,
},
MouseHeldEvent {
#[derive(Clone)]
pub enum TrEventExtension {
/// Custom events here
MouseHeldEvent {},
KeyHeldEvent {},
GamepadEvent {
gil_event: GilEvent,
},
KeyHeldEvent {
}
},
#[derive(Clone)]
pub enum TrEvent<T> {
/// Custom events here
MouseHeldEvent {},
KeyHeldEvent {},
GamepadEvent {
gil_event: GilEvent,
},
/// Winit events here
NewEvents(StartCause),
WindowEvent {
window_id: WindowId,
event: TrWindowEvent,
},
DeviceEvent {
device_id: DeviceId,
event: DeviceEvent,
},
UserEvent(T),
Suspended,
Resumed,
MainEventsCleared,
RedrawRequested(WindowId),
RedrawEventsCleared,
LoopDestroyed,
}
impl<T> From<Event<'_, T>> for TrEvent<T> {
fn from(event: Event<T>) -> Self {
match event {
Event::NewEvents(cause) => {
TrEvent::NewEvents(cause)
},
Event::WindowEvent { window_id: window_id, event: event } => {
TrEvent::WindowEvent {
window_id: window_id,
event: match event {
WindowEvent::AxisMotion { device_id, axis, value } => {
TrWindowEvent::AxisMotion { device_id, axis, value }
},
WindowEvent::Resized(physical_size) => {
TrWindowEvent::Resized(physical_size)
}
WindowEvent::Moved(physical_position) => {
TrWindowEvent::Moved(physical_position)
}
WindowEvent::CloseRequested => {
TrWindowEvent::CloseRequested
}
WindowEvent::Destroyed => {
TrWindowEvent::Destroyed
}
WindowEvent::DroppedFile(path_buf) => {
TrWindowEvent::DroppedFile(path_buf)
}
WindowEvent::HoveredFile(path_buf) => {
TrWindowEvent::HoveredFile(path_buf)
}
WindowEvent::HoveredFileCancelled => {
TrWindowEvent::HoveredFileCancelled
}
WindowEvent::ReceivedCharacter(char) => {
TrWindowEvent::ReceivedCharacter(char)
}
WindowEvent::Focused(bool) => {
TrWindowEvent::Focused(bool)
}
WindowEvent::KeyboardInput { device_id: device_id, input: input, is_synthetic: is_synthetic } => {
TrWindowEvent::KeyboardInput { device_id, input, is_synthetic }
}
WindowEvent::ModifiersChanged(modifiers_state) => {
TrWindowEvent::ModifiersChanged(modifiers_state)
}
WindowEvent::CursorMoved { device_id: device_id, position: position, modifiers: modifiers } => {
TrWindowEvent::CursorMoved { device_id, position, modifiers }
}
WindowEvent::CursorEntered { device_id: device_id } => {
TrWindowEvent::CursorEntered { device_id }
}
WindowEvent::CursorLeft { device_id: device_id } => {
TrWindowEvent::CursorLeft { device_id }
}
WindowEvent::MouseWheel { device_id: device_id, delta: delta, phase: phase, modifiers: modifiers } => {
TrWindowEvent::MouseWheel { device_id, delta, phase, modifiers }
}
WindowEvent::MouseInput { device_id: device_id, state: state, button: button, modifiers: modifiers } => {
TrWindowEvent::MouseInput { device_id, state, button, modifiers }
}
WindowEvent::TouchpadPressure { device_id: device_id, pressure: pressure, stage: stage } => {
TrWindowEvent::TouchpadPressure { device_id, pressure, stage }
}
WindowEvent::Touch(touch) => {
TrWindowEvent::Touch(touch)
}
WindowEvent::ScaleFactorChanged { scale_factor: scale_factor, new_inner_size: new_inner_size } => {
TrWindowEvent::ScaleFactorChanged { scale_factor, new_inner_size: PhysicalSize { width: new_inner_size.width, height: new_inner_size.height } }
}
WindowEvent::ThemeChanged(theme) => {
TrWindowEvent::ThemeChanged(theme)
}
}
}
}
Event::DeviceEvent { device_id: device_id, event: event } => {
TrEvent::DeviceEvent { device_id, event }
}
Event::UserEvent(user_event) => {
TrEvent::UserEvent(user_event)
}
Event::Suspended => {
TrEvent::Suspended
}
Event::Resumed => {
TrEvent::Resumed
}
Event::MainEventsCleared => {
TrEvent::MainEventsCleared
}
Event::RedrawRequested(window_id) => {
TrEvent::RedrawRequested(window_id)
}
Event::RedrawEventsCleared => {
TrEvent::RedrawEventsCleared
}
Event::LoopDestroyed => {
TrEvent::LoopDestroyed
}
}
}
}
#[derive(Debug, PartialEq, Clone)]
pub enum TrWindowEvent {
Resized(PhysicalSize<u32>),
Moved(PhysicalPosition<i32>),
CloseRequested,
Destroyed,
DroppedFile(PathBuf),
HoveredFile(PathBuf),
HoveredFileCancelled,
ReceivedCharacter(char),
Focused(bool),
KeyboardInput {
device_id: DeviceId,
input: KeyboardInput,
is_synthetic: bool,
},
ModifiersChanged(ModifiersState),
CursorMoved {
device_id: DeviceId,
position: PhysicalPosition<f64>,
#[deprecated = "Deprecated in favor of WindowEvent::ModifiersChanged"]
modifiers: ModifiersState,
},
CursorEntered { device_id: DeviceId },
CursorLeft { device_id: DeviceId },
MouseWheel {
device_id: DeviceId,
delta: MouseScrollDelta,
phase: TouchPhase,
#[deprecated = "Deprecated in favor of WindowEvent::ModifiersChanged"]
modifiers: ModifiersState,
},
MouseInput {
device_id: DeviceId,
state: ElementState,
button: MouseButton,
#[deprecated = "Deprecated in favor of WindowEvent::ModifiersChanged"]
modifiers: ModifiersState,
},
TouchpadPressure {
device_id: DeviceId,
pressure: f32,
stage: i64,
},
AxisMotion {
device_id: DeviceId,
axis: AxisId,
value: f64,
},
Touch(Touch),
ScaleFactorChanged {
scale_factor: f64,
new_inner_size: PhysicalSize<u32>,
},
ThemeChanged(Theme),
}
Loading…
Cancel
Save