use winit::event::{Touch, TouchPhase, WindowEvent}; use crate::graphics::Vertex; const BOTTOM_TAB_BAR_HEIGHT: f32 = 0.2; const SECONDARY_COLOR: [f32; 4] = [84./255., 33./255., 32./255., 1.]; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Kind { None, Terrain, Entities } pub struct UI { pub kind_selected: Kind, touch: Option } impl UI { pub fn new() -> Self { Self { kind_selected: Kind::Entities, touch: None } } // Returns true if event was handled by UI pub fn window_event(&mut self, event: &WindowEvent) -> bool { match event { WindowEvent::Touch(ref t) => { match t.phase { TouchPhase::Started => { if !self.touch.is_some() { self.touch = Some(*t); true } else { false } }, TouchPhase::Moved => { if let Some(old_t) = self.touch { if old_t.id == t.id { // TODO true } else { false } } else { false } }, TouchPhase::Cancelled | TouchPhase::Ended => { if let Some(old_t) = self.touch { if old_t.id == t.id { self.touch = None; true } else { false } } else { false } } } }, _ => false } } pub fn render(&self, vertices: &mut Vec, indices: &mut Vec) { let vs = [ // Terrain Vertex { color: SECONDARY_COLOR, pos: [-1., -1.+(BOTTOM_TAB_BAR_HEIGHT*2.)], effect: 0 }, Vertex { color: SECONDARY_COLOR, pos: [-1., -1.], effect: 0 }, Vertex { color: SECONDARY_COLOR, pos: [0., -1.], effect: 0 }, Vertex { color: SECONDARY_COLOR, pos: [0., -1.+(BOTTOM_TAB_BAR_HEIGHT*2.)], effect: 0 }, // Entities // 3, // 2, Vertex { color: SECONDARY_COLOR, pos: [1., -1.], effect: 0 }, Vertex { color: SECONDARY_COLOR, pos: [1., -1.+(BOTTOM_TAB_BAR_HEIGHT*2.)], effect: 0 } ]; let ids = [ 0,1,2, 2,3,0, 3,2,4, 4,5,3 ]; let i = vertices.len() as u32; vertices.extend_from_slice(&vs); indices.extend_from_slice(&ids.map(|id| id+i)); } }