Merge pull request #6907 from visiblelight/screenshot_refactor

adding comments for the new utility
This commit is contained in:
minggo 2014-05-27 14:52:09 +08:00
commit 0b661d8192
3 changed files with 23 additions and 18 deletions

View File

@ -44,16 +44,11 @@ int ccNextPOT(int x)
return x + 1; return x + 1;
} }
namespace Utilities namespace utils
{ {
void captureScreen(const std::function<void(bool, const std::string&)>& afterCaptured, const std::string& filename) /**
{ * Capture screen implementation, don't use it directly.
static CustomCommand captureScreenCommand; */
captureScreenCommand.init(std::numeric_limits<float>::max());
captureScreenCommand.func = std::bind(onCaptureScreen, afterCaptured, filename);
Director::getInstance()->getRenderer()->addCommand(&captureScreenCommand);
}
void onCaptureScreen(const std::function<void(bool, const std::string&)>& afterCaptured, const std::string& filename) void onCaptureScreen(const std::function<void(bool, const std::string&)>& afterCaptured, const std::string& filename)
{ {
auto glView = Director::getInstance()->getOpenGLView(); auto glView = Director::getInstance()->getOpenGLView();
@ -112,6 +107,16 @@ void onCaptureScreen(const std::function<void(bool, const std::string&)>& afterC
afterCaptured(succeed, outputFile); afterCaptured(succeed, outputFile);
} }
} }
/*
* Capture screen interface
*/
void captureScreen(const std::function<void(bool, const std::string&)>& afterCaptured, const std::string& filename)
{
static CustomCommand captureScreenCommand;
captureScreenCommand.init(std::numeric_limits<float>::max());
captureScreenCommand.func = std::bind(onCaptureScreen, afterCaptured, filename);
Director::getInstance()->getRenderer()->addCommand(&captureScreenCommand);
}
} }
NS_CC_END NS_CC_END

View File

@ -47,17 +47,17 @@ Examples:
int ccNextPOT(int value); int ccNextPOT(int value);
namespace Utilities namespace utils
{ {
/** /** Capture the entire screen
* Capture screen interface * To ensure the snapshot is applied after everything is updated and rendered in the current frame,
* we need to wrap the operation with a custom command which is then inserted into the tail of the render queue.
* @param afterCaptured, specify the callback function which will be invoked after the snapshot is done.
* @param filename, specify a filename where the snapshot is stored. This parameter can be either an absolute path or a simple
* base filename ("hello.png" etc.), don't use a relative path containing directory names.("mydir/hello.png" etc.)
* @since v3.2
*/ */
void captureScreen(const std::function<void(bool, const std::string&)>& afterCaptured, const std::string& filename); void captureScreen(const std::function<void(bool, const std::string&)>& afterCaptured, const std::string& filename);
/**
* The implementation of capturing screen
*/
void onCaptureScreen(const std::function<void(bool, const std::string&)>& afterCaptured, const std::string& filename);
} }
NS_CC_END NS_CC_END

View File

@ -609,7 +609,7 @@ void CaptureScreenTest::onCaptured(Ref*)
Director::getInstance()->getTextureCache()->removeTextureForKey(_filename); Director::getInstance()->getTextureCache()->removeTextureForKey(_filename);
removeChildByTag(childTag); removeChildByTag(childTag);
_filename = "CaptureScreenTest.png"; _filename = "CaptureScreenTest.png";
Utilities::captureScreen(CC_CALLBACK_2(CaptureScreenTest::afterCaptured, this), _filename); utils::captureScreen(CC_CALLBACK_2(CaptureScreenTest::afterCaptured, this), _filename);
} }
void CaptureScreenTest::afterCaptured(bool succeed, const std::string& outputFile) void CaptureScreenTest::afterCaptured(bool succeed, const std::string& outputFile)