diff options
Diffstat (limited to 'src/render')
-rw-r--r-- | src/render/screenshot.cc | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/src/render/screenshot.cc b/src/render/screenshot.cc index 043756b..dcbada4 100644 --- a/src/render/screenshot.cc +++ b/src/render/screenshot.cc @@ -4,6 +4,8 @@ the terms of the GNU General Public License version 2 */ +#include <iomanip> + #include "auxiliary/functions.h" #include "core/core.h" #include "filesystem/filesystem.h" @@ -20,12 +22,12 @@ namespace render { core::Cvar *Screenshot::screenshotformat = 0; core::Cvar *Screenshot::screenshotquality = 0; + int Screenshot::number = 0; void Screenshot::save() { bool available = false; - std::string shortname; std::string filename; const int TYPETGA = 0; const int TYPEPNG = 1; @@ -44,7 +46,9 @@ void Screenshot::save() if ((screenshotformat->str().compare("jpg") == 0) || (screenshotformat->str().compare("jpeg") == 0)) { filetype = TYPEJPG; - if (screenshotquality->value() < 10) { + if (screenshotquality->value() == 0 ) { + (*screenshotquality) = 85; + } else if (screenshotquality->value() < 10) { (*screenshotquality) = 10; } else if (screenshotquality->value() > 100) { (*screenshotquality) = 100; @@ -61,27 +65,34 @@ void Screenshot::save() (*screenshotformat) = "tga"; } - // find the first available screenshotxxxx + // find the first available screenshots/osirion-yyyymmdd-hhmm-xxxx.ext + std::stringstream filenamestr; + int day, month, year, hour, min; + + sys::get_datetime(year, month, day, hour, min); + + filenamestr << filesystem::writedir() << "screenshots/osirion" << '-'; + // date + filenamestr << std::setfill('0') << std::setw(4) << year << std::setw(2) << month << std::setw(2) << day << '-'; + // time + filenamestr << std::setfill('0') << std::setw(2) << hour << std::setw(2) << min << '-'; + do { std::stringstream nstr; - nstr << number; - shortname.assign(nstr.str()); - - while(shortname.size() < 4) - shortname.insert(0, 1, '0'); - - shortname.insert(0, "screenshots/osirion"); - shortname.append("."); - shortname.append(screenshotformat->str()); + nstr << std::setw(4) << std::setfill('0') << number; - filename.assign(filesystem::writedir()); - filename.append(shortname); + // sequence number + filename.assign(filenamestr.str()); + filename.append(nstr.str()); + // extension + filename.append("."); + filename.append(screenshotformat->str()); FILE *handle = fopen(filename.c_str(), "r"); if (handle) { fclose(handle); } else { - available = true; + available = true; } number++; } while (!available); |