summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Steinbrink <B.Steinbrink@gmx.de>2005-09-18 11:22:27 +0000
committerBjörn Steinbrink <B.Steinbrink@gmx.de>2005-09-18 11:22:27 +0000
commitf22625d0e79cd943acf117c1e5bd32e4bbef5a2a (patch)
tree6996be4ae3914affbc40bdec951beba55d9e6603
parent7329e1e48c9366695121eb32a18eecd91846354b (diff)
downloadmana-f22625d0e79cd943acf117c1e5bd32e4bbef5a2a.tar.gz
mana-f22625d0e79cd943acf117c1e5bd32e4bbef5a2a.tar.bz2
mana-f22625d0e79cd943acf117c1e5bd32e4bbef5a2a.tar.xz
mana-f22625d0e79cd943acf117c1e5bd32e4bbef5a2a.zip
Move the writing logic out of the Graphics class once again... Some cleanups in the screenshot filename selection code.
-rw-r--r--ChangeLog3
-rw-r--r--src/game.cpp38
-rw-r--r--src/graphics.cpp45
-rw-r--r--src/graphics.h7
4 files changed, 40 insertions, 53 deletions
diff --git a/ChangeLog b/ChangeLog
index fb4de56c..103a0a9a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -17,6 +17,9 @@
2005-09-18 Björn Steinbrink <B.Steinbrink@gmx.de>
+ * src/game.cpp, src/graphics.cpp, src/graphics.h: Move the writing
+ logic out of the Graphics class once again... Some cleanups in the
+ screenshot filename selection code.
* src/resources/imagewriter.cpp: Small cleanups.
* src/Makefile.am, src/game.cpp, src/graphics.cpp, src/graphics.h,
src/openglgraphics.cpp, src/openglgraphics.h: Changed saveScreenshot
diff --git a/src/game.cpp b/src/game.cpp
index 5506947d..98dbb318 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -23,7 +23,10 @@
#include "game.h"
+#include <fstream>
+#include <physfs.h>
#include <sstream>
+#include <string>
#include <guichan/sdl/sdlinput.hpp>
@@ -69,6 +72,8 @@
#include "net/network.h"
#include "net/protocol.h"
+#include "resources/imagewriter.h"
+
extern Graphics *graphics;
std::string map_path;
@@ -326,6 +331,30 @@ void do_init()
}
}
+bool saveScreenshot(SDL_Surface *screenshot)
+{
+ static unsigned int screenshotCount = 0;
+
+ // Search for an unused screenshot name
+ std::stringstream filename;
+ std::fstream testExists;
+ bool found = false;
+
+ do {
+ screenshotCount++;
+ filename.str("");
+ #ifdef __USE_UNIX98
+ filename << PHYSFS_getUserDir() << "/";
+ #endif
+ filename << "TMW_Screenshot_" << screenshotCount << ".png";
+ testExists.open(filename.str().c_str(), std::ios::in);
+ found = !testExists.is_open();
+ testExists.close();
+ } while (!found);
+
+ return ImageWriter::writePNG(screenshot, filename.str());
+}
+
void game()
{
// Needs to be initialised _before_ the engine is created...
@@ -578,11 +607,16 @@ void do_input()
*/
// screenshot (picture, hence the p)
case SDLK_p:
- if (!graphics->saveScreenshot())
{
- logger->log("Error: could not save Screenshot.");
+ SDL_Surface *screenshot = graphics->getScreenshot();
+ if (!saveScreenshot(screenshot))
+ {
+ logger->log("Error: could not save Screenshot.");
+ }
+ SDL_FreeSurface(screenshot);
}
break;
+
// Skill window
case SDLK_k:
skillDialog->setVisible(!skillDialog->isVisible());
diff --git a/src/graphics.cpp b/src/graphics.cpp
index f179eff2..33f25468 100644
--- a/src/graphics.cpp
+++ b/src/graphics.cpp
@@ -28,17 +28,11 @@
#include "graphic/imagerect.h"
#include "resources/image.h"
-#include <physfs.h>
-#include <sstream>
-#include <string>
-#include <fstream>
-#include "resources/imagewriter.h"
extern volatile int framesToDraw;
Graphics::Graphics():
- mScreen(0),
- screenshotsCount(1)
+ mScreen(0)
{
}
@@ -246,43 +240,6 @@ void Graphics::updateScreen()
}
}
-bool Graphics::saveScreenshot()
-{
- std::stringstream pictureFilename;
- // Write it under user home dir on *nices.
- #ifdef __USE_UNIX98
- pictureFilename << PHYSFS_getUserDir() << "/";
- #endif
- pictureFilename << "TMW_Screenshot_" << screenshotsCount << ".png";
-
- // While these screenshots files already exists, increment the
- // screenshots count.
- std::fstream testExists;
- testExists.open(std::string(pictureFilename.str()).c_str(), std::ios::in);
- while ( testExists.is_open() )
- {
- testExists.close();
- screenshotsCount++;
- pictureFilename.str("");
- #ifdef __USE_UNIX98
- pictureFilename << PHYSFS_getUserDir() << "/";
- #endif
- pictureFilename << "TMW_Screenshot_" << screenshotsCount << ".png";
- testExists.open(std::string(pictureFilename.str()).c_str(), std::ios::in);
- }
- testExists.close();
-
- if ( ImageWriter::writePNG(getScreenshot(), pictureFilename.str()) )
- {
- screenshotsCount++;
- return true;
- }
- else
- {
- return false;
- }
-}
-
SDL_Surface* Graphics::getScreenshot()
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
diff --git a/src/graphics.h b/src/graphics.h
index 18a3be51..a0749795 100644
--- a/src/graphics.h
+++ b/src/graphics.h
@@ -120,11 +120,6 @@ class Graphics : public gcn::SDLGraphics {
int getHeight();
/**
- * takes a screenshot, and saves it as a png
- */
- bool saveScreenshot();
-
- /**
* takes a screenshot and returns it as SDL surface
*/
virtual SDL_Surface* getScreenshot();
@@ -132,8 +127,6 @@ class Graphics : public gcn::SDLGraphics {
protected:
SDL_Surface *mScreen;
bool mFullscreen, mHWAccel;
- private:
- int screenshotsCount;
};
#endif