Implement mouse panning and streamline keyboard movement.
[mandelwow.git] / main.rs
diff --git a/main.rs b/main.rs
index 71495b41d09f310d0d051ae51e5bff0b78b4677f..5507f4a7fc09b01340f33f223c754e05ba57c79c 100644 (file)
--- a/main.rs
+++ b/main.rs
@@ -4,6 +4,7 @@
 
 extern crate glium;
 extern crate glutin;
+extern crate image;
 extern crate libxm;
 extern crate sdl2;
 
@@ -19,6 +20,14 @@ mod mandelwow;
 mod sound;
 mod support;
 
+fn screenshot(display : &glium::Display) {
+    let image: glium::texture::RawImage2d<u8> = display.read_front_buffer();
+    let image = image::ImageBuffer::from_raw(image.width, image.height, image.data.into_owned()).unwrap();
+    let image = image::DynamicImage::ImageRgba8(image).flipv();
+    let mut output = std::fs::File::create(&std::path::Path::new("screenshot.png")).unwrap();
+    image.save(&mut output, image::ImageFormat::PNG).unwrap();
+}
+
 fn main() {
     let _soundplayer = sound::start();
 
@@ -101,17 +110,6 @@ fn main() {
                 KeyboardInput(Pressed, _, Some(VirtualKeyCode::B)) => {
                     bounding_box_enabled ^= true;
                 },
-                KeyboardInput(Pressed, _, Some(VirtualKeyCode::F)) => {
-                    fullscreen ^= true;
-                    if fullscreen {
-                        glutin::WindowBuilder::new()
-                            .with_fullscreen(glutin::get_primary_monitor())
-                            .rebuild_glium(&display).unwrap();
-                    } else {
-                        glutin::WindowBuilder::new()
-                            .rebuild_glium(&display).unwrap();
-                    }
-                },
                 KeyboardInput(Pressed, _, Some(VirtualKeyCode::P)) => {
                     pause ^= true;
                 },
@@ -121,6 +119,22 @@ fn main() {
                 KeyboardInput(Pressed, _, Some(VirtualKeyCode::PageDown)) => {
                     t -= 0.01;
                 },
+                KeyboardInput(Pressed, _, Some(VirtualKeyCode::F10)) => {
+                    screenshot(&display);
+                },
+                KeyboardInput(Pressed, _, Some(VirtualKeyCode::F11)) => {
+                    fullscreen ^= true;
+                    if fullscreen {
+                        // Not implemented on Linux
+                        glutin::WindowBuilder::new()
+                            .with_fullscreen(glutin::get_primary_monitor())
+                            .with_depth_buffer(24)
+                            .rebuild_glium(&display).unwrap();
+                    } else {
+                        //glutin::WindowBuilder::new()
+                        //    .rebuild_glium(&display).unwrap();
+                    }
+                },
                 ev => camera.process_input(&ev),
             }
         }