Skip to content

Commit

Permalink
Add toggling full screen mode with F11 hotkey (#31)
Browse files Browse the repository at this point in the history
* Detect when F11 is pressed

* Change mutability of window in handle_window_event()

* Toggle fullscreen between Desktop and Off
  • Loading branch information
iceiix authored Nov 21, 2018
1 parent 58ea344 commit 47d1878
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ fn main() {

let sdl = sdl2::init().unwrap();
let sdl_video = sdl.video().unwrap();
let window = sdl2::video::WindowBuilder::new(&sdl_video, "Steven", 854, 480)
let mut window = sdl2::video::WindowBuilder::new(&sdl_video, "Steven", 854, 480)
.opengl()
.resizable()
.build()
Expand Down Expand Up @@ -262,12 +262,12 @@ fn main() {
window.gl_swap_window();

for event in events.poll_iter() {
handle_window_event(&window, &mut game, &mut ui_container, event);
handle_window_event(&mut window, &mut game, &mut ui_container, event);
}
}
}

fn handle_window_event(window: &sdl2::video::Window,
fn handle_window_event(window: &mut sdl2::video::Window,
game: &mut Game,
ui_container: &mut ui::Container,
event: sdl2::event::Event) {
Expand Down Expand Up @@ -346,6 +346,15 @@ fn handle_window_event(window: &sdl2::video::Window,
Event::KeyDown{keycode: Some(Keycode::Backquote), ..} => {
game.console.lock().unwrap().toggle();
}
Event::KeyDown{keycode: Some(Keycode::F11), ..} => { // TODO: configurable binding in settings::Stevenkey
let state = match window.fullscreen_state() {
sdl2::video::FullscreenType::Off => sdl2::video::FullscreenType::Desktop,
sdl2::video::FullscreenType::True => sdl2::video::FullscreenType::Off,
sdl2::video::FullscreenType::Desktop => sdl2::video::FullscreenType::Off,
};

window.set_fullscreen(state).expect(&format!("failed to set fullscreen to {:?}", state));
}
Event::KeyDown{keycode: Some(key), keymod, ..} => {
if game.focused {
if let Some(steven_key) = settings::Stevenkey::get_by_keycode(key, &game.vars) {
Expand Down

0 comments on commit 47d1878

Please sign in to comment.