diff options
author | Yohann Ferreira <bertram@cegetel.net> | 2005-09-18 01:31:33 +0000 |
---|---|---|
committer | Yohann Ferreira <bertram@cegetel.net> | 2005-09-18 01:31:33 +0000 |
commit | 06221a4cb3f44e7532e185bc775c73741d32cbf2 (patch) | |
tree | 4258a21d641e6810173f6c936db8d34d9e109313 /src/resources | |
parent | 8a8086d758d7618f3900df057ac840667e867d0c (diff) | |
download | mana-06221a4cb3f44e7532e185bc775c73741d32cbf2.tar.gz mana-06221a4cb3f44e7532e185bc775c73741d32cbf2.tar.bz2 mana-06221a4cb3f44e7532e185bc775c73741d32cbf2.tar.xz mana-06221a4cb3f44e7532e185bc775c73741d32cbf2.zip |
Made the saveScreenShot makes its screenshots under user home dir in *nices, made it more C++ way to avoid a leak, and made it check for existence of a file with same name before writing; In that case the screenshot's number is incremented until it finds an adequate name.
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/imagewriter.cpp | 15 | ||||
-rw-r--r-- | src/resources/imagewriter.h | 2 |
2 files changed, 9 insertions, 8 deletions
diff --git a/src/resources/imagewriter.cpp b/src/resources/imagewriter.cpp index a6fb3d97..98219e44 100644 --- a/src/resources/imagewriter.cpp +++ b/src/resources/imagewriter.cpp @@ -29,15 +29,15 @@ #include "../log.h" -void ImageWriter::writePNG(SDL_Surface *surface, +bool ImageWriter::writePNG(SDL_Surface *surface, const std::string &filename) { // TODO Maybe someone can make this look nice? FILE *fp = fopen(filename.c_str(), "wb"); if (!fp) { - logger->log("could not open file &s for writing", filename.c_str()); - return; + logger->log("could not open file %s for writing", filename.c_str()); + return false; } png_structp png_ptr; @@ -53,7 +53,7 @@ void ImageWriter::writePNG(SDL_Surface *surface, if (!png_ptr) { logger->log("Had trouble creating png_structp"); - return; + return false; } info_ptr = png_create_info_struct(png_ptr); @@ -61,14 +61,14 @@ void ImageWriter::writePNG(SDL_Surface *surface, { png_destroy_write_struct(&png_ptr, (png_infopp)NULL); logger->log("Could not create png_info"); - return; + return false; } if (setjmp(png_jmpbuf(png_ptr))) { png_destroy_write_struct(&png_ptr, (png_infopp)NULL); logger->log("problem writing to %s", filename.c_str()); - return; + return false; } png_init_io(png_ptr, fp); @@ -87,7 +87,7 @@ void ImageWriter::writePNG(SDL_Surface *surface, if (!row_pointers) { logger->log("Had trouble converting surface to row pointers"); - return; + return false; } for (int i = 0; i < surface->h; i++) @@ -105,4 +105,5 @@ void ImageWriter::writePNG(SDL_Surface *surface, if (SDL_MUSTLOCK(surface)) { SDL_UnlockSurface(surface); } + return true; } diff --git a/src/resources/imagewriter.h b/src/resources/imagewriter.h index edda723f..205e4584 100644 --- a/src/resources/imagewriter.h +++ b/src/resources/imagewriter.h @@ -28,6 +28,6 @@ struct SDL_Surface; class ImageWriter { public: - static void writePNG(SDL_Surface *surface, + static bool writePNG(SDL_Surface *surface, const std::string &filename); }; |