added screenshot key F12 (from spongie)
authorPerttu Ahola <celeron55@gmail.com>
Sun, 26 Jun 2011 16:33:40 +0000 (19:33 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Sun, 26 Jun 2011 16:33:40 +0000 (19:33 +0300)
src/defaultsettings.cpp
src/game.cpp

index 84fac75eca7980ef8ef16732f7fe3dae0b0adf47..435eefd86339850349ed5e4e7d676e051cadfed4 100644 (file)
@@ -43,6 +43,7 @@ void set_default_settings()
        g_settings.setDefault("keymap_freemove", "KEY_KEY_K");
        g_settings.setDefault("keymap_fastmove", "KEY_KEY_J");
        g_settings.setDefault("keymap_frametime_graph", "KEY_F1");
+       g_settings.setDefault("keymap_screenshot", "KEY_F12");
        // Some (temporary) keys for debugging
        g_settings.setDefault("keymap_special1", "KEY_KEY_E");
        g_settings.setDefault("keymap_print_debug_stacks", "KEY_KEY_P");
@@ -71,6 +72,7 @@ void set_default_settings()
        g_settings.setDefault("enable_farmesh", "false");
        g_settings.setDefault("enable_clouds", "true");
        g_settings.setDefault("invisible_stone", "false");
+       g_settings.setDefault("screenshot_path", ".");
 
        // Server stuff
        g_settings.setDefault("enable_experimental", "false");
index 59f14d37dc0126eb5941a03d3f54195e2b0484b2..3197985e6230b818c447ba32e5fcb8ba665ad6c7 100644 (file)
@@ -1246,6 +1246,25 @@ void the_game(
                                chat_lines.push_back(ChatLine(L"frametime_graph enabled"));
                        }
                }
+               else if(input->wasKeyDown(getKeySetting("keymap_screenshot")))
+               {
+                       irr::video::IImage* const image = driver->createScreenShot(); 
+                       if (image) { 
+                               irr::c8 filename[256]; 
+                               snprintf(filename, 256, "%s/screenshot_%u.png", 
+                                                g_settings.get("screenshot_path").c_str(),
+                                                device->getTimer()->getRealTime()); 
+                               if (driver->writeImageToFile(image, filename)) {
+                                       std::wstringstream sstr;
+                                       sstr<<"Saved screenshot to '"<<filename<<"'";
+                                       dstream<<"Saved screenshot to '"<<filename<<"'"<<std::endl;
+                                       chat_lines.push_back(ChatLine(sstr.str()));
+                               } else{
+                                       dstream<<"Failed to save screenshot '"<<filename<<"'"<<std::endl;
+                               }
+                               image->drop(); 
+                       }                        
+               }
 
                // Item selection with mouse wheel
                {