From bf18201b303b9210dd0111b1488194d7bac40a5d Mon Sep 17 00:00:00 2001 From: auria Date: Tue, 31 Jul 2012 23:28:23 +0000 Subject: [PATCH] Add feature to save screenshot. Try Right-Alt + PrintScreen git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@11452 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/graphics/irr_driver.cpp | 44 +++++++++++++++++++++++++++++++++++++ src/graphics/irr_driver.hpp | 3 +++ src/input/input_manager.cpp | 10 ++++++++- 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index 2c4f6ff09..9bcea8906 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -84,6 +84,7 @@ IrrDriver::IrrDriver() { m_resolution_changing = RES_CHANGE_NONE; m_device = createDevice(video::EDT_NULL); + m_request_screenshot = false; } // IrrDriver // ---------------------------------------------------------------------------- @@ -1601,6 +1602,42 @@ void IrrDriver::update(float dt) m_video_driver->endScene(); + + if (m_request_screenshot) + { + m_request_screenshot = false; + + video::IImage* image = m_video_driver->createScreenShot(); + if (image) + { + static int screenshot_id = 1; + + #if defined(WIN32) + std::string path = StringUtils::insertValues("C:\\Temp\\supertuxkart_%s_%i.png", race_manager->getTrackName().c_str(), screenshot_id++); + #else + std::string path = StringUtils::insertValues("/tmp/supertuxkart_%s_%i.png", race_manager->getTrackName().c_str(), screenshot_id++); + #endif + + if (irr_driver->getVideoDriver()->writeImageToFile(image, io::path(path.c_str()), 0)) + { + RaceGUIBase* base = World::getWorld()->getRaceGUI(); + if (base != NULL) + { + base->addMessage(core::stringw(("Screenshot saved to\n" + path).c_str()), NULL, 2.0f, video::SColor(255,255,255,255), true, false); + } + } + else + { + RaceGUIBase* base = World::getWorld()->getRaceGUI(); + if (base != NULL) + { + base->addMessage(core::stringw(("FAILED saving screenshot to\n" + path + "\n:(").c_str()), NULL, 2.0f, video::SColor(255,255,255,255), true, false); + } + } + image->drop(); + } + } + getPostProcessing()->update(dt); // Enable this next print statement to get render information printed @@ -1612,6 +1649,13 @@ void IrrDriver::update(float dt) // printRenderStats(); } // update +// ---------------------------------------------------------------------------- + +void IrrDriver::requestScreenshot() +{ + m_request_screenshot = true; +} + // ---------------------------------------------------------------------------- // Irrlicht Event handler. bool IrrDriver::OnEvent(const irr::SEvent &event) diff --git a/src/graphics/irr_driver.hpp b/src/graphics/irr_driver.hpp index c99915a38..752aca61c 100644 --- a/src/graphics/irr_driver.hpp +++ b/src/graphics/irr_driver.hpp @@ -107,6 +107,7 @@ private: void applyResolutionSettings(); void createListOfVideoModes(); + bool m_request_screenshot; public: IrrDriver(); @@ -214,6 +215,8 @@ public: bool supportsSplatting(); + void requestScreenshot(); + // --------------------- RTT -------------------- /** * Class that provides RTT (currently, only when no other 3D rendering diff --git a/src/input/input_manager.cpp b/src/input/input_manager.cpp index dc64d380c..5bc2087e6 100644 --- a/src/input/input_manager.cpp +++ b/src/input/input_manager.cpp @@ -156,8 +156,16 @@ void InputManager::handleStaticAction(int key, int value) kart->flyDown(); break; } + case KEY_PRINT: + irr_driver->requestScreenshot(); + break; + case KEY_F1: - if (UserConfigParams::m_artist_debug_mode && world) + if (control_is_pressed) + { + irr_driver->requestScreenshot(); + } + else if (UserConfigParams::m_artist_debug_mode && world) { AbstractKart* kart = world->getLocalPlayerKart(0); kart->setPowerup(PowerupManager::POWERUP_BUBBLEGUM, 10000);