Added a variant of love.graphics.captureScreenshot which takes a single filename parameter. Resolves issue #1293.

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2017-07-29 12:54:53 -03:00
parent 2c80cce00b
commit 5ef6730497
6 changed files with 76 additions and 16 deletions
+24 -1
View File
@@ -22,6 +22,8 @@
#include "ImageData.h"
#include "Image.h"
#include "filesystem/Filesystem.h"
namespace love
{
namespace image
@@ -154,7 +156,7 @@ void ImageData::decode(love::filesystem::FileData *data)
decodeHandler = decoder;
}
love::filesystem::FileData *ImageData::encode(EncodedFormat encodedFormat, const char *filename)
love::filesystem::FileData *ImageData::encode(EncodedFormat encodedFormat, const char *filename, bool writefile)
{
FormatHandler *encoder = nullptr;
FormatHandler::EncodedImage encodedimage;
@@ -208,6 +210,27 @@ love::filesystem::FileData *ImageData::encode(EncodedFormat encodedFormat, const
memcpy(filedata->getData(), encodedimage.data, encodedimage.size);
encoder->free(encodedimage.data);
if (writefile)
{
auto fs = Module::getInstance<filesystem::Filesystem>(Module::M_FILESYSTEM);
if (fs == nullptr)
{
filedata->release();
throw love::Exception("love.filesystem must be loaded in order to write an encoded ImageData to a file.");
}
try
{
fs->write(filename, filedata->getData(), filedata->getSize());
}
catch (love::Exception &)
{
filedata->release();
throw;
}
}
return filedata;
}
+1 -1
View File
@@ -47,7 +47,7 @@ public:
// Implements image::ImageData.
virtual love::image::ImageData *clone() const;
virtual love::filesystem::FileData *encode(EncodedFormat encodedFormat, const char *filename);
virtual love::filesystem::FileData *encode(EncodedFormat encodedFormat, const char *filename, bool writefile);
private: