From 0cfb8c6469f75202bec2c14801aa68963901a97c Mon Sep 17 00:00:00 2001 From: DENPEN Date: Fri, 5 Sep 2014 20:49:15 +0900 Subject: [PATCH] fix ScrollView bug I Fixed a bug that scroll view hidden picks up the touch events. --- extensions/GUI/CCScrollView/CCScrollView.cpp | 15 ++++++++++++++- extensions/GUI/CCScrollView/CCScrollView.h | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/extensions/GUI/CCScrollView/CCScrollView.cpp b/extensions/GUI/CCScrollView/CCScrollView.cpp index e97d2672be..68181bd899 100644 --- a/extensions/GUI/CCScrollView/CCScrollView.cpp +++ b/extensions/GUI/CCScrollView/CCScrollView.cpp @@ -343,6 +343,19 @@ void ScrollView::setContainer(Node * pContainer) this->setViewSize(this->_viewSize); } +bool ScrollView::hasVisibleParents() const +{ + auto parent = this->getParent(); + for( auto c = parent; c != nullptr; c = c->getParent() ) + { + if( !c->isVisible() ) + { + return false; + } + } + return true; +} + void ScrollView::relocateContainer(bool animated) { Vec2 oldPoint, min, max; @@ -625,7 +638,7 @@ void ScrollView::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t bool ScrollView::onTouchBegan(Touch* touch, Event* event) { - if (!this->isVisible()) + if (!this->isVisible() || !this->hasVisibleParents()) { return false; } diff --git a/extensions/GUI/CCScrollView/CCScrollView.h b/extensions/GUI/CCScrollView/CCScrollView.h index 72695df5c7..36f94d39f8 100644 --- a/extensions/GUI/CCScrollView/CCScrollView.h +++ b/extensions/GUI/CCScrollView/CCScrollView.h @@ -256,6 +256,8 @@ public: * CCActionTweenDelegate */ void updateTweenAction(float value, const std::string& key); + + bool hasVisibleParents() const; protected: /** * Relocates the container at the proper offset, in bounds of max/min offsets.