HostInterface: Add SaveScreenshot() method

This commit is contained in:
Connor McLaughlin 2020-03-16 00:03:57 +10:00
parent 2bb992a702
commit 6b68512ac1
2 changed files with 42 additions and 3 deletions

View file

@ -674,10 +674,11 @@ void HostInterface::CreateUserDirectorySubdirectories()
result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("bios").c_str(), false);
result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("cache").c_str(), false);
result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("savestates").c_str(), false);
result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("memcards").c_str(), false);
result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("dump").c_str(), false);
result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("dump/audio").c_str(), false);
result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("savestates").c_str(), false);
result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("screenshots").c_str(), false);
result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("memcards").c_str(), false);
if (!result)
ReportError("Failed to create one or more user directories. This may cause issues at runtime.");
@ -1140,3 +1141,38 @@ void HostInterface::StopDumpingAudio()
AddOSDMessage("Stopped dumping audio.", 5.0f);
}
bool HostInterface::SaveScreenshot(const char* filename /* = nullptr */, bool full_resolution /* = true */,
bool apply_aspect_ratio /* = true */)
{
if (!m_system)
return false;
std::string auto_filename;
if (!filename)
{
const auto& code = m_system->GetRunningCode();
const char* extension = "png";
if (code.empty())
{
auto_filename =
GetUserDirectoryRelativePath("screenshots/%s.%s", GetTimestampStringForFileName().GetCharArray(), extension);
}
else
{
auto_filename = GetUserDirectoryRelativePath("screenshots/%s_%s.%s", code.c_str(),
GetTimestampStringForFileName().GetCharArray(), extension);
}
filename = auto_filename.c_str();
}
if (!m_display->WriteDisplayTextureToFile(filename, full_resolution, apply_aspect_ratio))
{
AddFormattedOSDMessage(10.0f, "Failed to save screenshot to '%s'", filename);
return false;
}
AddFormattedOSDMessage(5.0f, "Screenshot saved to '%s'.", filename);
return true;
}

View file

@ -78,6 +78,9 @@ public:
/// Stops dumping audio to file if it has been started.
void StopDumpingAudio();
/// Saves a screenshot to the specified file. IF no file name is provided, one will be generated automatically.
bool SaveScreenshot(const char* filename = nullptr, bool full_resolution = true, bool apply_aspect_ratio = true);
virtual void ReportError(const char* message);
virtual void ReportMessage(const char* message);
virtual bool ConfirmMessage(const char* message);