mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Clean up makeScreenshot() and make message translateable
This commit is contained in:
parent
b9af44b194
commit
38255cb6bb
2 changed files with 22 additions and 23 deletions
|
@ -1897,39 +1897,38 @@ float Client::getCurRate()
|
||||||
|
|
||||||
void Client::makeScreenshot()
|
void Client::makeScreenshot()
|
||||||
{
|
{
|
||||||
irr::video::IVideoDriver *driver = m_rendering_engine->get_video_driver();
|
video::IVideoDriver *driver = m_rendering_engine->get_video_driver();
|
||||||
irr::video::IImage* const raw_image = driver->createScreenShot();
|
video::IImage* const raw_image = driver->createScreenShot();
|
||||||
|
|
||||||
if (!raw_image)
|
if (!raw_image) {
|
||||||
|
errorstream << "Could not take screenshot" << std::endl;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const struct tm tm = mt_localtime();
|
const struct tm tm = mt_localtime();
|
||||||
|
|
||||||
char timetstamp_c[64];
|
char timestamp_c[64];
|
||||||
strftime(timetstamp_c, sizeof(timetstamp_c), "%Y%m%d_%H%M%S", &tm);
|
strftime(timestamp_c, sizeof(timestamp_c), "%Y%m%d_%H%M%S", &tm);
|
||||||
|
|
||||||
std::string screenshot_dir;
|
std::string screenshot_dir = g_settings->get("screenshot_path");
|
||||||
|
if (!fs::IsPathAbsolute(screenshot_dir))
|
||||||
if (fs::IsPathAbsolute(g_settings->get("screenshot_path")))
|
screenshot_dir = porting::path_user + DIR_DELIM + screenshot_dir;
|
||||||
screenshot_dir = g_settings->get("screenshot_path");
|
|
||||||
else
|
|
||||||
screenshot_dir = porting::path_user + DIR_DELIM + g_settings->get("screenshot_path");
|
|
||||||
|
|
||||||
std::string filename_base = screenshot_dir
|
std::string filename_base = screenshot_dir
|
||||||
+ DIR_DELIM
|
+ DIR_DELIM
|
||||||
+ std::string("screenshot_")
|
+ std::string("screenshot_")
|
||||||
+ std::string(timetstamp_c);
|
+ timestamp_c;
|
||||||
std::string filename_ext = "." + g_settings->get("screenshot_format");
|
std::string filename_ext = "." + g_settings->get("screenshot_format");
|
||||||
std::string filename;
|
|
||||||
|
|
||||||
// Create the directory if it doesn't already exist.
|
// Create the directory if it doesn't already exist.
|
||||||
// Otherwise, saving the screenshot would fail.
|
// Otherwise, saving the screenshot would fail.
|
||||||
fs::CreateDir(screenshot_dir);
|
fs::CreateAllDirs(screenshot_dir);
|
||||||
|
|
||||||
u32 quality = (u32)g_settings->getS32("screenshot_quality");
|
u32 quality = (u32)g_settings->getS32("screenshot_quality");
|
||||||
quality = MYMIN(MYMAX(quality, 0), 100) / 100.0 * 255;
|
quality = rangelim(quality, 0, 100) / 100.0f * 255;
|
||||||
|
|
||||||
// Try to find a unique filename
|
// Try to find a unique filename
|
||||||
|
std::string filename;
|
||||||
unsigned serial = 0;
|
unsigned serial = 0;
|
||||||
|
|
||||||
while (serial < SCREENSHOT_MAX_SERIAL_TRIES) {
|
while (serial < SCREENSHOT_MAX_SERIAL_TRIES) {
|
||||||
|
@ -1940,23 +1939,23 @@ void Client::makeScreenshot()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (serial == SCREENSHOT_MAX_SERIAL_TRIES) {
|
if (serial == SCREENSHOT_MAX_SERIAL_TRIES) {
|
||||||
infostream << "Could not find suitable filename for screenshot" << std::endl;
|
errorstream << "Could not find suitable filename for screenshot" << std::endl;
|
||||||
} else {
|
} else {
|
||||||
irr::video::IImage* const image =
|
video::IImage* const image =
|
||||||
driver->createImage(video::ECF_R8G8B8, raw_image->getDimension());
|
driver->createImage(video::ECF_R8G8B8, raw_image->getDimension());
|
||||||
|
|
||||||
if (image) {
|
if (image) {
|
||||||
raw_image->copyTo(image);
|
raw_image->copyTo(image);
|
||||||
|
|
||||||
std::ostringstream sstr;
|
std::string msg;
|
||||||
if (driver->writeImageToFile(image, filename.c_str(), quality)) {
|
if (driver->writeImageToFile(image, filename.c_str(), quality)) {
|
||||||
sstr << "Saved screenshot to '" << filename << "'";
|
msg = fmtgettext("Saved screenshot to \"%s\"", filename.c_str());
|
||||||
} else {
|
} else {
|
||||||
sstr << "Failed to save screenshot '" << filename << "'";
|
msg = fmtgettext("Failed to save screenshot to \"%s\"", filename.c_str());
|
||||||
}
|
}
|
||||||
pushToChatQueue(new ChatMessage(CHATMESSAGE_TYPE_SYSTEM,
|
pushToChatQueue(new ChatMessage(CHATMESSAGE_TYPE_SYSTEM,
|
||||||
utf8_to_wide(sstr.str())));
|
utf8_to_wide(msg)));
|
||||||
infostream << sstr.str() << std::endl;
|
infostream << msg << std::endl;
|
||||||
image->drop();
|
image->drop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ inline struct tm mt_localtime()
|
||||||
#endif
|
#endif
|
||||||
});
|
});
|
||||||
|
|
||||||
struct tm ret;
|
struct tm ret{};
|
||||||
time_t t = time(NULL);
|
time_t t = time(NULL);
|
||||||
// TODO we should check if the function returns NULL, which would mean error
|
// TODO we should check if the function returns NULL, which would mean error
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue