|
|
|
@ -1,17 +1,25 @@
|
|
|
|
|
use winit::window::{WindowId, Theme};
|
|
|
|
|
use winit::event::{WindowEvent, DeviceId, DeviceEvent, KeyboardInput, ModifiersState, MouseScrollDelta, TouchPhase, ElementState, MouseButton, AxisId, Touch, StartCause, Event};
|
|
|
|
|
use winit::dpi::{PhysicalPosition, PhysicalSize};
|
|
|
|
|
use gilrs::Event as GilEvent;
|
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
|
|
use gilrs::Event as GilEvent;
|
|
|
|
|
use legion::world::SubWorld;
|
|
|
|
|
use legion::*;
|
|
|
|
|
use winit::dpi::{PhysicalPosition, PhysicalSize};
|
|
|
|
|
use winit::event::DeviceEvent::MouseMotion;
|
|
|
|
|
use winit::event::{
|
|
|
|
|
AxisId, DeviceEvent, DeviceId, ElementState, Event, KeyboardInput, ModifiersState, MouseButton,
|
|
|
|
|
MouseScrollDelta, StartCause, Touch, TouchPhase, WindowEvent,
|
|
|
|
|
};
|
|
|
|
|
use winit::window::{Theme, WindowId};
|
|
|
|
|
|
|
|
|
|
use crate::camera::{Camera, CameraController};
|
|
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
|
pub enum TrUIEvent<T> {
|
|
|
|
|
UIEvent(T)
|
|
|
|
|
pub enum OwnedUIEvent<T> {
|
|
|
|
|
UIEvent(T),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
|
pub enum TrEventExtension {
|
|
|
|
|
|
|
|
|
|
pub enum OwnedEventExtension {
|
|
|
|
|
/// Custom events here
|
|
|
|
|
MouseHeldEvent {},
|
|
|
|
|
KeyHeldEvent {},
|
|
|
|
@ -21,8 +29,7 @@ pub enum TrEventExtension {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
|
pub enum TrEvent<T> {
|
|
|
|
|
|
|
|
|
|
pub enum OwnedEvent<T> {
|
|
|
|
|
/// Custom events here
|
|
|
|
|
MouseHeldEvent {},
|
|
|
|
|
KeyHeldEvent {},
|
|
|
|
@ -34,7 +41,7 @@ pub enum TrEvent<T> {
|
|
|
|
|
NewEvents(StartCause),
|
|
|
|
|
WindowEvent {
|
|
|
|
|
window_id: WindowId,
|
|
|
|
|
event: TrWindowEvent,
|
|
|
|
|
event: OwnedWindowEvent,
|
|
|
|
|
},
|
|
|
|
|
DeviceEvent {
|
|
|
|
|
device_id: DeviceId,
|
|
|
|
@ -49,114 +56,127 @@ pub enum TrEvent<T> {
|
|
|
|
|
LoopDestroyed,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl<T> From<Event<'_, T>> for TrEvent<T> {
|
|
|
|
|
impl<T> From<Event<'_, T>> for OwnedEvent<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::NewEvents(cause) => OwnedEvent::NewEvents(cause),
|
|
|
|
|
Event::WindowEvent {
|
|
|
|
|
window_id: window_id,
|
|
|
|
|
event: event,
|
|
|
|
|
} => OwnedEvent::WindowEvent {
|
|
|
|
|
window_id: window_id,
|
|
|
|
|
event: match event {
|
|
|
|
|
WindowEvent::AxisMotion {
|
|
|
|
|
device_id,
|
|
|
|
|
axis,
|
|
|
|
|
value,
|
|
|
|
|
} => OwnedWindowEvent::AxisMotion {
|
|
|
|
|
device_id,
|
|
|
|
|
axis,
|
|
|
|
|
value,
|
|
|
|
|
},
|
|
|
|
|
WindowEvent::Resized(physical_size) => OwnedWindowEvent::Resized(physical_size),
|
|
|
|
|
WindowEvent::Moved(physical_position) => {
|
|
|
|
|
OwnedWindowEvent::Moved(physical_position)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
WindowEvent::CloseRequested => OwnedWindowEvent::CloseRequested,
|
|
|
|
|
WindowEvent::Destroyed => OwnedWindowEvent::Destroyed,
|
|
|
|
|
WindowEvent::DroppedFile(path_buf) => OwnedWindowEvent::DroppedFile(path_buf),
|
|
|
|
|
WindowEvent::HoveredFile(path_buf) => OwnedWindowEvent::HoveredFile(path_buf),
|
|
|
|
|
WindowEvent::HoveredFileCancelled => OwnedWindowEvent::HoveredFileCancelled,
|
|
|
|
|
WindowEvent::ReceivedCharacter(char) => {
|
|
|
|
|
OwnedWindowEvent::ReceivedCharacter(char)
|
|
|
|
|
}
|
|
|
|
|
WindowEvent::Focused(bool) => OwnedWindowEvent::Focused(bool),
|
|
|
|
|
WindowEvent::KeyboardInput {
|
|
|
|
|
device_id: device_id,
|
|
|
|
|
input: input,
|
|
|
|
|
is_synthetic: is_synthetic,
|
|
|
|
|
} => OwnedWindowEvent::KeyboardInput {
|
|
|
|
|
device_id,
|
|
|
|
|
input,
|
|
|
|
|
is_synthetic,
|
|
|
|
|
},
|
|
|
|
|
WindowEvent::ModifiersChanged(modifiers_state) => {
|
|
|
|
|
OwnedWindowEvent::ModifiersChanged(modifiers_state)
|
|
|
|
|
}
|
|
|
|
|
WindowEvent::CursorMoved {
|
|
|
|
|
device_id: device_id,
|
|
|
|
|
position: position,
|
|
|
|
|
modifiers: modifiers,
|
|
|
|
|
} => OwnedWindowEvent::CursorMoved {
|
|
|
|
|
device_id,
|
|
|
|
|
position,
|
|
|
|
|
modifiers,
|
|
|
|
|
},
|
|
|
|
|
WindowEvent::CursorEntered {
|
|
|
|
|
device_id: device_id,
|
|
|
|
|
} => OwnedWindowEvent::CursorEntered { device_id },
|
|
|
|
|
WindowEvent::CursorLeft {
|
|
|
|
|
device_id: device_id,
|
|
|
|
|
} => OwnedWindowEvent::CursorLeft { device_id },
|
|
|
|
|
WindowEvent::MouseWheel {
|
|
|
|
|
device_id: device_id,
|
|
|
|
|
delta: delta,
|
|
|
|
|
phase: phase,
|
|
|
|
|
modifiers: modifiers,
|
|
|
|
|
} => OwnedWindowEvent::MouseWheel {
|
|
|
|
|
device_id,
|
|
|
|
|
delta,
|
|
|
|
|
phase,
|
|
|
|
|
modifiers,
|
|
|
|
|
},
|
|
|
|
|
WindowEvent::MouseInput {
|
|
|
|
|
device_id: device_id,
|
|
|
|
|
state: state,
|
|
|
|
|
button: button,
|
|
|
|
|
modifiers: modifiers,
|
|
|
|
|
} => OwnedWindowEvent::MouseInput {
|
|
|
|
|
device_id,
|
|
|
|
|
state,
|
|
|
|
|
button,
|
|
|
|
|
modifiers,
|
|
|
|
|
},
|
|
|
|
|
WindowEvent::TouchpadPressure {
|
|
|
|
|
device_id: device_id,
|
|
|
|
|
pressure: pressure,
|
|
|
|
|
stage: stage,
|
|
|
|
|
} => OwnedWindowEvent::TouchpadPressure {
|
|
|
|
|
device_id,
|
|
|
|
|
pressure,
|
|
|
|
|
stage,
|
|
|
|
|
},
|
|
|
|
|
WindowEvent::Touch(touch) => OwnedWindowEvent::Touch(touch),
|
|
|
|
|
WindowEvent::ScaleFactorChanged {
|
|
|
|
|
scale_factor: scale_factor,
|
|
|
|
|
new_inner_size: new_inner_size,
|
|
|
|
|
} => OwnedWindowEvent::ScaleFactorChanged {
|
|
|
|
|
scale_factor,
|
|
|
|
|
new_inner_size: PhysicalSize {
|
|
|
|
|
width: new_inner_size.width,
|
|
|
|
|
height: new_inner_size.height,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
WindowEvent::ThemeChanged(theme) => OwnedWindowEvent::ThemeChanged(theme),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
Event::DeviceEvent {
|
|
|
|
|
device_id: device_id,
|
|
|
|
|
event: event,
|
|
|
|
|
} => OwnedEvent::DeviceEvent { device_id, event },
|
|
|
|
|
Event::UserEvent(user_event) => OwnedEvent::UserEvent(user_event),
|
|
|
|
|
Event::Suspended => OwnedEvent::Suspended,
|
|
|
|
|
Event::Resumed => OwnedEvent::Resumed,
|
|
|
|
|
Event::MainEventsCleared => OwnedEvent::MainEventsCleared,
|
|
|
|
|
Event::RedrawRequested(window_id) => OwnedEvent::RedrawRequested(window_id),
|
|
|
|
|
Event::RedrawEventsCleared => OwnedEvent::RedrawEventsCleared,
|
|
|
|
|
Event::LoopDestroyed => OwnedEvent::LoopDestroyed,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq, Clone)]
|
|
|
|
|
pub enum TrWindowEvent {
|
|
|
|
|
|
|
|
|
|
pub enum OwnedWindowEvent {
|
|
|
|
|
Resized(PhysicalSize<u32>),
|
|
|
|
|
Moved(PhysicalPosition<i32>),
|
|
|
|
|
CloseRequested,
|
|
|
|
@ -178,8 +198,12 @@ pub enum TrWindowEvent {
|
|
|
|
|
#[deprecated = "Deprecated in favor of WindowEvent::ModifiersChanged"]
|
|
|
|
|
modifiers: ModifiersState,
|
|
|
|
|
},
|
|
|
|
|
CursorEntered { device_id: DeviceId },
|
|
|
|
|
CursorLeft { device_id: DeviceId },
|
|
|
|
|
CursorEntered {
|
|
|
|
|
device_id: DeviceId,
|
|
|
|
|
},
|
|
|
|
|
CursorLeft {
|
|
|
|
|
device_id: DeviceId,
|
|
|
|
|
},
|
|
|
|
|
MouseWheel {
|
|
|
|
|
device_id: DeviceId,
|
|
|
|
|
delta: MouseScrollDelta,
|
|
|
|
@ -210,4 +234,61 @@ pub enum TrWindowEvent {
|
|
|
|
|
new_inner_size: PhysicalSize<u32>,
|
|
|
|
|
},
|
|
|
|
|
ThemeChanged(Theme),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Because I am a glutton for punishment I am going to just do a mono-event-dispatch-magoooo
|
|
|
|
|
#[system]
|
|
|
|
|
#[write_component(Camera)]
|
|
|
|
|
#[write_component(CameraController)]
|
|
|
|
|
pub fn event_dispatch(
|
|
|
|
|
world: &mut SubWorld,
|
|
|
|
|
#[resource] event_stack: &mut Vec<OwnedEvent<OwnedEventExtension>>,
|
|
|
|
|
) {
|
|
|
|
|
use winit::event::Event::DeviceEvent;
|
|
|
|
|
|
|
|
|
|
for event in event_stack {
|
|
|
|
|
match event {
|
|
|
|
|
OwnedEvent::DeviceEvent {
|
|
|
|
|
event: MouseMotion { delta },
|
|
|
|
|
..
|
|
|
|
|
} => {
|
|
|
|
|
let mut query = <(&mut CameraController)>::query();
|
|
|
|
|
for (camera_controller) in query.iter_mut(world) {
|
|
|
|
|
camera_controller.process_mouse(delta.0, delta.1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OwnedEvent::DeviceEvent { device_id, event } => {
|
|
|
|
|
match event {
|
|
|
|
|
winit::event::DeviceEvent::Key(keyboard_input) => {
|
|
|
|
|
let mut query = <(&mut CameraController)>::query();
|
|
|
|
|
for (camera_controller) in query.iter_mut(world) {
|
|
|
|
|
camera_controller.process_keyboard(
|
|
|
|
|
keyboard_input.virtual_keycode.unwrap(),
|
|
|
|
|
keyboard_input.state,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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));
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// _ => ()
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
_ => {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_ => {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|