92 lines
2.9 KiB
Rust
92 lines
2.9 KiB
Rust
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<Touch>
|
|
}
|
|
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<Vertex>, indices: &mut Vec<u32>) {
|
|
let vs = [
|
|
// Terrain
|
|
Vertex::new_tex([-1., -1.+(BOTTOM_TAB_BAR_HEIGHT*2.)], [0, 1], 0),
|
|
Vertex::new_tex([-1., -1.], [0, 12], 0),
|
|
Vertex::new_tex([0., -1.], [11, 12], 0),
|
|
Vertex::new_tex([0., -1.+(BOTTOM_TAB_BAR_HEIGHT*2.)], [11, 1], 0),
|
|
|
|
// Entities
|
|
// Vertex::new_tex([0., -1.+(BOTTOM_TAB_BAR_HEIGHT*2.)], [12, 1], 0),
|
|
// Vertex::new_tex([0., -1.], [11, 12], 0),
|
|
// Vertex::new_tex([1., -1.], [] 0),
|
|
// Vertex::new_tex([1., -1.+(BOTTOM_TAB_BAR_HEIGHT*2.)], 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));
|
|
}
|
|
}
|