Fix the display bug when a scrollView nested in another scrollView

This commit is contained in:
sjchao 2013-03-29 16:05:28 +08:00
parent 18c43e29b2
commit f1f31deb98
2 changed files with 29 additions and 6 deletions

View File

@ -492,13 +492,26 @@ void CCScrollView::beforeDraw()
{ {
if (m_bClippingToBounds) if (m_bClippingToBounds)
{ {
m_bScissorRestored = false;
CCRect frame = getViewRect(); CCRect frame = getViewRect();
if (CCEGLView::sharedOpenGLView()->isScissorEnable()) {
m_bScissorRestored = true;
m_tParentScissorRect = CCEGLView::sharedOpenGLView()->getScissorRect();
//set the intersection of m_tParentScissorRect and frame as the new scissor rect
if (frame.intersectsRect(m_tParentScissorRect)) {
float x = MAX(frame.origin.x, m_tParentScissorRect.origin.x);
float y = MAX(frame.origin.y, m_tParentScissorRect.origin.y);
float xx = MIN(frame.origin.x+frame.size.width, m_tParentScissorRect.origin.x+m_tParentScissorRect.size.width);
float yy = MIN(frame.origin.y+frame.size.height, m_tParentScissorRect.origin.y+m_tParentScissorRect.size.height);
CCEGLView::sharedOpenGLView()->setScissorInPoints(x, y, xx-x, yy-y);
}
}
else {
glEnable(GL_SCISSOR_TEST); glEnable(GL_SCISSOR_TEST);
CCEGLView::sharedOpenGLView()->setScissorInPoints(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height); CCEGLView::sharedOpenGLView()->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 * retract what's done in beforeDraw so that there's no side effect to
@ -508,9 +521,14 @@ void CCScrollView::afterDraw()
{ {
if (m_bClippingToBounds) if (m_bClippingToBounds)
{ {
if (m_bScissorRestored) {//restore the parent's scissor rect
CCEGLView::sharedOpenGLView()->setScissorInPoints(m_tParentScissorRect.origin.x, m_tParentScissorRect.origin.y, m_tParentScissorRect.size.width, m_tParentScissorRect.size.height);
}
else {
glDisable(GL_SCISSOR_TEST); glDisable(GL_SCISSOR_TEST);
} }
} }
}
void CCScrollView::visit() void CCScrollView::visit()
{ {

View File

@ -317,6 +317,11 @@ protected:
* max and min scale * max and min scale
*/ */
float m_fMinScale, m_fMaxScale; float m_fMinScale, m_fMaxScale;
/**
* scissor rect for parent, just for restoring GL_SCISSOR_BOX
*/
CCRect m_tParentScissorRect;
bool m_bScissorRestored;
}; };
// end of GUI group // end of GUI group