From f1f31deb987db188bc27cf222da23931da2294db Mon Sep 17 00:00:00 2001 From: sjchao Date: Fri, 29 Mar 2013 16:05:28 +0800 Subject: [PATCH] Fix the display bug when a scrollView nested in another scrollView --- extensions/GUI/CCScrollView/CCScrollView.cpp | 30 ++++++++++++++++---- extensions/GUI/CCScrollView/CCScrollView.h | 5 ++++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/extensions/GUI/CCScrollView/CCScrollView.cpp b/extensions/GUI/CCScrollView/CCScrollView.cpp index e90ec50fd4..dbce3012d2 100644 --- a/extensions/GUI/CCScrollView/CCScrollView.cpp +++ b/extensions/GUI/CCScrollView/CCScrollView.cpp @@ -492,11 +492,24 @@ void CCScrollView::beforeDraw() { if (m_bClippingToBounds) { - CCRect frame = getViewRect(); - - glEnable(GL_SCISSOR_TEST); - - CCEGLView::sharedOpenGLView()->setScissorInPoints(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height); + m_bScissorRestored = false; + 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); + CCEGLView::sharedOpenGLView()->setScissorInPoints(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height); + } } } @@ -508,7 +521,12 @@ void CCScrollView::afterDraw() { if (m_bClippingToBounds) { - glDisable(GL_SCISSOR_TEST); + 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); + } } } diff --git a/extensions/GUI/CCScrollView/CCScrollView.h b/extensions/GUI/CCScrollView/CCScrollView.h index 9c9955a3f9..00602374ac 100644 --- a/extensions/GUI/CCScrollView/CCScrollView.h +++ b/extensions/GUI/CCScrollView/CCScrollView.h @@ -317,6 +317,11 @@ protected: * max and min scale */ 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