You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.9 KiB
64 lines
1.9 KiB
5 years ago
|
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() {}
|
||
|
}
|
||
|
}
|