Exemple #1
0
/**
 * clip this view so that outside of the visible bounds can be hidden.
 */
void ScrollView::onBeforeDraw()
{
    if (_clippingToBounds)
    {
		_scissorRestored = false;
        Rect frame = getViewRect();
        auto glview = Director::getInstance()->getOpenGLView();

        if (glview->isScissorEnabled()) {
            _scissorRestored = true;
            _parentScissorRect = glview->getScissorRect();
            //set the intersection of _parentScissorRect and frame as the new scissor rect
            if (frame.intersectsRect(_parentScissorRect)) {
                float x = MAX(frame.origin.x, _parentScissorRect.origin.x);
                float y = MAX(frame.origin.y, _parentScissorRect.origin.y);
                float xx = MIN(frame.origin.x+frame.size.width, _parentScissorRect.origin.x+_parentScissorRect.size.width);
                float yy = MIN(frame.origin.y+frame.size.height, _parentScissorRect.origin.y+_parentScissorRect.size.height);
                glview->setScissorInPoints(x, y, xx-x, yy-y);
            }
        }
        else {
            glEnable(GL_SCISSOR_TEST);
            glview->setScissorInPoints(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);
        }
    }
}
/**
 * retract what's done in beforeDraw so that there's no side effect to
 * other nodes.
 */
void ScrollView::onAfterDraw()
{
    if (_clippingToBounds)
    {
        if (_scissorRestored) {//restore the parent's scissor rect
            auto glview = Director::getInstance()->getOpenGLView();

            glview->setScissorInPoints(_parentScissorRect.origin.x, _parentScissorRect.origin.y, _parentScissorRect.size.width, _parentScissorRect.size.height);
        }
        else {
            glDisable(GL_SCISSOR_TEST);
        }
    }
}
Exemple #3
0
void ClippingNodeRect::visit()
{
    kmGLPushMatrix();
    glEnable(GL_SCISSOR_TEST);


    auto glView = cocos2d::Director::getInstance()->getOpenGLView();
    glView->setScissorInPoints(
        getPositionX(), getPositionY(),
        getContentSize().width, getContentSize().height
    );
    Node::visit();

    glDisable(GL_SCISSOR_TEST);
    kmGLPopMatrix();
}
void Layout::onAfterVisitScissor()
{
    if (_scissorOldState)
    {
        // revert scissor box
        if (false == _clippingOldRect.equals(_clippingRect))
        {
            auto glview = Director::DirectorInstance->getOpenGLView();
            glview->setScissorInPoints(_clippingOldRect.origin.x,
                                       _clippingOldRect.origin.y,
                                       _clippingOldRect.size.width,
                                       _clippingOldRect.size.height);
        }
    }
    else
    {
        // revert scissor test
        glDisable(GL_SCISSOR_TEST);
    }
}
void Layout::onBeforeVisitScissor()
{
    auto glview = Director::DirectorInstance->getOpenGLView();
    // apply scissor test
    _scissorOldState = glview->isScissorEnabled();
    if (false == _scissorOldState)
    {
        glEnable(GL_SCISSOR_TEST);
    }

    // apply scissor box
    Rect clippingRect = getClippingRect();
    _clippingOldRect = glview->getScissorRect();
    if (false == _clippingOldRect.equals(clippingRect))
    {
        glview->setScissorInPoints(clippingRect.origin.x,
                                   clippingRect.origin.y,
                                   clippingRect.size.width,
                                   clippingRect.size.height);
    }
}