Revert "remove CCClippingRectangleNode transform error support."

This commit is contained in:
偶尔e网事 2015-09-18 11:31:37 +08:00
parent 731373b93d
commit eb480fb021
3 changed files with 16 additions and 7 deletions

View File

@ -42,11 +42,21 @@ void ClippingRectangleNode::onBeforeVisitScissor()
if (_clippingEnabled) {
glEnable(GL_SCISSOR_TEST);
float scaleX = _scaleX;
float scaleY = _scaleY;
Node *parent = this->getParent();
while (parent) {
scaleX *= parent->getScaleX();
scaleY *= parent->getScaleY();
parent = parent->getParent();
}
const Point pos = convertToWorldSpace(Point(_clippingRegion.origin.x, _clippingRegion.origin.y));
GLView* glView = Director::getInstance()->getOpenGLView();
glView->setScissorInPoints(_clippingRegion.origin.x,
_clippingRegion.origin.y,
_clippingRegion.size.width,
_clippingRegion.size.height);
glView->setScissorInPoints(pos.x * scaleX,
pos.y * scaleY,
_clippingRegion.size.width * scaleX,
_clippingRegion.size.height * scaleY);
}
}

View File

@ -67,7 +67,7 @@ public:
return _clippingRegion;
}
/**
@brief Set the clipping rectangle. The rectangle is base on screen coordinate, so ClippingRectangleNode's region doesn't support any transforms, such as setScale, setRotate and so on.
@brief Set the clipping rectangle.
@param clippingRegion Specify the clipping rectangle.
*/
void setClippingRegion(const Rect& clippingRegion);

View File

@ -1059,7 +1059,6 @@ std::string ClippingRectangleNodeTest::subtitle() const
void ClippingRectangleNodeTest::setup()
{
//Notice: The rectangle is base on screen coordinate, so ClippingRectangleNode's region doesn't support any transforms, such as setScale, setRotate and so on.
auto clipper = ClippingRectangleNode::create();
clipper->setClippingRegion(Rect(this->getContentSize().width / 2 - 100, this->getContentSize().height / 2 - 100, 200, 200));
clipper->setTag( kTagClipperNode );
@ -1068,6 +1067,6 @@ void ClippingRectangleNodeTest::setup()
auto content = Sprite::create(s_back2);
content->setTag( kTagContentNode );
content->setAnchorPoint( Vec2(0.5, 0.5) );
clipper->setPosition(this->getContentSize().width / 2, this->getContentSize().height / 2);
content->setPosition(this->getContentSize().width / 2, this->getContentSize().height / 2);
clipper->addChild(content);
}