remove the parameter rect

This commit is contained in:
vision 2014-05-26 13:42:47 +08:00
parent e263c5f2de
commit 7edfe78f7d
4 changed files with 14 additions and 38 deletions

View File

@ -1216,45 +1216,24 @@ void Director::setEventDispatcher(EventDispatcher* dispatcher)
}
}
void Director::captureScreen(const std::function<void(bool, const std::string&)>& afterCaptured, const std::string& filename, const Rect& rect)
void Director::captureScreen(const std::function<void(bool, const std::string&)>& afterCaptured, const std::string& filename)
{
_captureScreen.init(std::numeric_limits<float>::max());
_captureScreen.func = CC_CALLBACK_0(Director::onCaptureScreen, this, afterCaptured, filename, rect);
_captureScreen.func = CC_CALLBACK_0(Director::onCaptureScreen, this, afterCaptured, filename);
Director::getInstance()->getRenderer()->addCommand(&_captureScreen);
}
void Director::onCaptureScreen(const std::function<void(bool, const std::string&)>& afterCaptured, const std::string& filename, const Rect& rect)
void Director::onCaptureScreen(const std::function<void(bool, const std::string&)>& afterCaptured, const std::string& filename)
{
// the rect is specified based on the design resolution
Size designSize = _openGLView->getDesignResolutionSize();
int originx = 0;
int originy = 0;
int width = designSize.width;
int height = designSize.height;
if (!rect.equals(Rect::ZERO))
{
originx = (int)rect.origin.x;
originy = (int)rect.origin.y;
width = (int)rect.size.width;
height = (int)rect.size.height;
auto clip = [](int in, int min, int max) { return std::max(std::min(in, max), min); };
originx = clip(originx, 0, (int)designSize.width);
originy = clip(originy, 0, (int)designSize.height);
width = clip(width, 0, designSize.width - originx);
height = clip(height, 0, designSize.height - originy);
}
// the frame buffer size is based on the device pixel resolution
Size frameSize = _openGLView->getFrameSize();
#if CC_TARGET_PLATFORM == CC_PLATFORM_MAC
frameSize = frameSize * _openGLView->getFrameZoomFactor() * _openGLView->getRetinaFactor();
#endif
originx = static_cast<int>(float(originx) / designSize.width * frameSize.width);
originy = static_cast<int>(float(originy) / designSize.height * frameSize.height);
width = static_cast<int>(float(width) / designSize.width * frameSize.width);
height = static_cast<int>(float(height) / designSize.height * frameSize.height);
int originx = 0;
int originy = 0;
int width = static_cast<int>(frameSize.width);
int height = static_cast<int>(frameSize.height);
bool succeed = false;
std::string outputFile = "";

View File

@ -408,7 +408,7 @@ public:
/**
* Capture screen
*/
void captureScreen(const std::function<void(bool, const std::string&)>& afterCaptued, const std::string& filename, const Rect& rect = Rect::ZERO);
void captureScreen(const std::function<void(bool, const std::string&)>& afterCaptued, const std::string& filename);
protected:
void purgeDirector();
@ -429,7 +429,7 @@ protected:
void destroyTextureCache();
/* Captrue screen implementation */
void onCaptureScreen(const std::function<void(bool, const std::string&)>& afterCaptued, const std::string& fileanme, const Rect& rect);
void onCaptureScreen(const std::function<void(bool, const std::string&)>& afterCaptued, const std::string& fileanme);
/** Scheduler associated with this director
@since v2.0

View File

@ -581,11 +581,8 @@ CaptureScreenTest::CaptureScreenTest()
sp2->runAction(seq2);
auto label1 = Label::createWithTTF(TTFConfig("fonts/arial.ttf"), "capture all");
auto mi1 = MenuItemLabel::create(label1, CC_CALLBACK_1(CaptureScreenTest::onCaptured, this, Rect::ZERO));
auto label2 = Label::createWithTTF(TTFConfig("fonts/arial.ttf"), "capture half");
auto mi2 = MenuItemLabel::create(label2, CC_CALLBACK_1(CaptureScreenTest::onCaptured, this, Rect(0, 0, s.width/2, s.height)));
mi2->setPosition(0, -15);
auto menu = Menu::create(mi1, mi2, nullptr);
auto mi1 = MenuItemLabel::create(label1, CC_CALLBACK_1(CaptureScreenTest::onCaptured, this));
auto menu = Menu::create(mi1, nullptr);
addChild(menu);
menu->setPosition(s.width / 2, s.height / 4);
@ -607,12 +604,12 @@ std::string CaptureScreenTest::subtitle() const
return "Capture screen test, press the munu items to capture the screen";
}
void CaptureScreenTest::onCaptured(Ref*, const Rect& rect)
void CaptureScreenTest::onCaptured(Ref*)
{
Director::getInstance()->getTextureCache()->removeTextureForKey(_filename);
removeChildByTag(ChildTag);
_filename = "CaptureScreenTest.png";
Director::getInstance()->captureScreen(CC_CALLBACK_2(CaptureScreenTest::afterCaptured, this), _filename, rect);
Director::getInstance()->captureScreen(CC_CALLBACK_2(CaptureScreenTest::afterCaptured, this), _filename);
}
void CaptureScreenTest::afterCaptured(bool succeed, const std::string& outputFile)

View File

@ -158,7 +158,7 @@ protected:
CaptureScreenTest();
~CaptureScreenTest();
void onCaptured(Ref*, const Rect& rect);
void onCaptured(Ref*);
void afterCaptured(bool succeed, const std::string& outputFile);
std::string _filename;