diff --git a/src/meshs/default_mesh.rs b/src/meshs/default_mesh.rs index 3eba4e8..34e1196 100644 --- a/src/meshs/default_mesh.rs +++ b/src/meshs/default_mesh.rs @@ -1,8 +1,9 @@ use std::sync::Arc; use cgmath::prelude::*; +use winit::event::{WindowEvent, KeyboardInput, VirtualKeyCode, ElementState}; -use crate::render::{Mesh, Renderable, Vertex, Instance}; +use crate::{render::{Mesh, Renderable, Vertex, Instance}, input::Controllable}; const VERTICES: &[Vertex] = &[ Vertex { @@ -121,4 +122,30 @@ impl Renderable for DefaultMesh { fn render<'a>(&'a self, render_pass: &mut wgpu::RenderPass<'a>) { self.mesh.render(render_pass); } +} + +impl Controllable for DefaultMesh { + fn process_events(&mut self, event: &winit::event::WindowEvent) -> bool { + match event { + WindowEvent::KeyboardInput { + input: + KeyboardInput { + state, + virtual_keycode: Some(keycode), + .. + }, + .. + } => { + let is_pressed = *state == ElementState::Pressed; + match keycode { + VirtualKeyCode::Space => { + self.toggle(is_pressed); + true + } + _ => false, + } + } + _ => false, + } + } } \ No newline at end of file diff --git a/src/state.rs b/src/state.rs index 74d8f13..6d6318f 100644 --- a/src/state.rs +++ b/src/state.rs @@ -4,7 +4,7 @@ use super::render::{ Vertex, Camera, Texture, InstanceRaw }; use winit::{ - event::{KeyboardInput, VirtualKeyCode, WindowEvent, ElementState}, + event::WindowEvent, window::Window, }; @@ -186,27 +186,7 @@ impl State { } pub fn input(&mut self, event: &WindowEvent) -> bool { - match event { - WindowEvent::KeyboardInput { - input: - KeyboardInput { - state, - virtual_keycode: Some(keycode), - .. - }, - .. - } => { - let is_pressed = *state == ElementState::Pressed; - match keycode { - VirtualKeyCode::Space => { - self.mesh.toggle(is_pressed); - true - } - _ => self.camera.process_events(event), - } - } - _ => self.camera.process_events(event), - } + self.mesh.process_events(&event) || self.camera.process_events(&event) } pub fn update(&mut self) {