summaryrefslogtreecommitdiff
path: root/src/game/GameView.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-08-17 22:09:48 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-08-17 22:09:48 (GMT)
commit5b51e670447ea175fb9b0b7035403b274e16972e (patch)
tree6f9c9d0a6eb6434ba26eb2f03b5e8e3d8ec179f4 /src/game/GameView.cpp
parent706bd0fa97b5f3da67d44f570a18f9f45ae4fad7 (diff)
downloadpowder-5b51e670447ea175fb9b0b7035403b274e16972e.zip
powder-5b51e670447ea175fb9b0b7035403b274e16972e.tar.gz
PPM screen recording
Diffstat (limited to 'src/game/GameView.cpp')
-rw-r--r--src/game/GameView.cpp69
1 files changed, 67 insertions, 2 deletions
diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp
index 5b6629b..f743d5a 100644
--- a/src/game/GameView.cpp
+++ b/src/game/GameView.cpp
@@ -175,7 +175,11 @@ GameView::GameView():
showDebug(false),
introText(2048),
introTextMessage(introTextData),
- wallBrush(false)
+ wallBrush(false),
+ doScreenshot(false),
+ recording(false),
+ screenshotIndex(0),
+ recordingIndex(0)
{
int currentX = 1;
@@ -927,6 +931,35 @@ void GameView::NotifyBrushChanged(GameModel * sender)
activeBrush = sender->GetBrush();
}
+void GameView::screenshot()
+{
+ doScreenshot = true;
+}
+
+void GameView::record()
+{
+ if(recording)
+ {
+ recording = false;
+ }
+ else
+ {
+ class RecordingConfirmation: public ConfirmDialogueCallback {
+ public:
+ GameView * v;
+ RecordingConfirmation(GameView * v): v(v) {}
+ virtual void ConfirmCallback(ConfirmPrompt::DialogueResult result) {
+ if (result == ConfirmPrompt::ResultOkay)
+ {
+ v->recording = true;
+ }
+ }
+ virtual ~RecordingConfirmation() { }
+ };
+ new ConfirmPrompt("Recording", "You're about to start recording all drawn frames. This may use a load of hard disk space.", new RecordingConfirmation(this));
+ }
+}
+
void GameView::setToolButtonOffset(int offset)
{
int offset_ = offset;
@@ -1246,6 +1279,12 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
case '`':
c->ShowConsole();
break;
+ case 'p':
+ screenshot();
+ break;
+ case 'r':
+ record();
+ break;
case 'e':
c->OpenElementSearch();
break;
@@ -1782,6 +1821,22 @@ void GameView::OnDraw()
}
ren->RenderEnd();
+ if(doScreenshot)
+ {
+ VideoBuffer screenshot(ren->DumpFrame());
+ std::vector<char> data = format::VideoBufferToPNG(screenshot);
+ Client::Ref().WriteFile(data, "screenshot_" + format::NumberToString<int>(screenshotIndex++) + ".png");
+ doScreenshot = false;
+ }
+
+ if(recording)
+ {
+ VideoBuffer screenshot(ren->DumpFrame());
+ std::vector<char> data = format::VideoBufferToPPM(screenshot);
+ Client::Ref().WriteFile(data, "frame_" + format::NumberToString<int>(recordingIndex++) + ".ppm");
+ }
+
+
if(selectMode!=SelectNone)
{
if(selectMode==PlaceSave)
@@ -1856,7 +1911,17 @@ void GameView::OnDraw()
}
}
- if(showHud && !introText)
+ if(recording)
+ {
+ std::stringstream sampleInfo;
+ sampleInfo << recordingIndex;
+ sampleInfo << ". \x8E REC";
+
+ int textWidth = Graphics::textwidth((char*)sampleInfo.str().c_str());
+ g->fillrect(XRES-20-textWidth, 12, textWidth+8, 15, 0, 0, 0, 255*0.5);
+ g->drawtext(XRES-16-textWidth, 16, (const char*)sampleInfo.str().c_str(), 255, 50, 20, 255);
+ }
+ else if(showHud && !introText)
{
//Draw info about simulation under cursor
int wavelengthGfx = 0;