veloren/voxygen/src/menu/title.rs

54 lines
1.4 KiB
Rust
Raw Normal View History

2019-01-02 22:08:13 +00:00
// Library
use vek::*;
// Crate
use crate::{
PlayState,
2019-01-07 21:10:31 +00:00
PlayStateResult,
GlobalState,
window::Event,
session::SessionState,
};
pub struct TitleState;
impl TitleState {
/// Create a new `TitleState`
pub fn new() -> Self {
Self
}
}
// The background colour
const BG_COLOR: Rgba<f32> = Rgba { r: 0.8, g: 1.0, b: 0.8, a: 1.0 };
2019-01-11 20:14:37 +00:00
impl PlayState for TitleState {
2019-01-07 21:10:31 +00:00
fn play(&mut self, global_state: &mut GlobalState) -> PlayStateResult {
loop {
// Handle window events
2019-01-07 21:10:31 +00:00
for event in global_state.window.fetch_events() {
match event {
Event::Close => return PlayStateResult::Shutdown,
// When space is pressed, start a session
Event::Char(' ') => return PlayStateResult::Push(
Box::new(SessionState::from_renderer(global_state.window.renderer_mut())),
),
// Ignore all other events
_ => {},
2019-01-07 21:10:31 +00:00
}
}
// Clear the screen
2019-01-11 20:14:37 +00:00
global_state.window.renderer_mut().clear(BG_COLOR);
// Finish the frame
2019-01-07 21:10:31 +00:00
global_state.window.renderer_mut().flush();
global_state.window
.swap_buffers()
.expect("Failed to swap window buffers");
}
}
fn name(&self) -> &'static str { "Title" }
}