parent
84999130bb
commit
aaef25f710
@ -0,0 +1,64 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use specs::{Component, Entities, Join, System, VecStorage, Write, WriteStorage};
|
||||
use vulkano::swapchain::Surface;
|
||||
use winit::window::Window;
|
||||
|
||||
use crate::canvas::canvas_frame::CanvasFrame;
|
||||
use crate::canvas::compu_frame::CompuFrame;
|
||||
use crate::PersistentState;
|
||||
use crate::render_system::Position;
|
||||
use crate::util::tr_event::{TrEvent, TrEventExtension, TrWindowEvent};
|
||||
use crate::vkprocessor::VkProcessor;
|
||||
use winit::event::ElementState;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Evented {
|
||||
pub subscribed: fn(event: TrEvent<TrEventExtension>) -> bool,
|
||||
}
|
||||
|
||||
impl Component for Evented {
|
||||
type Storage = VecStorage<Self>;
|
||||
}
|
||||
|
||||
pub struct EventSystem;
|
||||
|
||||
impl<'a> System<'a> for EventSystem {
|
||||
type SystemData = (
|
||||
Entities<'a>,
|
||||
WriteStorage<'a, Position>,
|
||||
WriteStorage<'a, Evented>,
|
||||
Write<'a, PersistentState>,
|
||||
Write<'a, VkProcessor>,
|
||||
Write<'a, Vec<TrEvent<TrEventExtension>>>
|
||||
);
|
||||
|
||||
fn run(&mut self, (
|
||||
entity,
|
||||
mut position_list,
|
||||
mut evented_list,
|
||||
mut state,
|
||||
mut vk_processor,
|
||||
event_stack
|
||||
): Self::SystemData) {
|
||||
|
||||
for (position, evented) in (&mut position_list, &evented_list).join() {
|
||||
for event in &*event_stack {
|
||||
match event {
|
||||
TrEvent::WindowEvent { window_id, event } => {
|
||||
match event {
|
||||
TrWindowEvent::MouseInput { device_id, state, button, modifiers } => {
|
||||
if *state == ElementState::Pressed {
|
||||
position.x += 100.0;
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (entity, evented) in (&*entity, &mut evented_list).join() {}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue