From 4b83240bed95131bdaa6a94536acd970102605e6 Mon Sep 17 00:00:00 2001 From: Vincent Yang Date: Thu, 17 Sep 2015 11:20:36 +0800 Subject: [PATCH] Fix bug: in ui::Widget::isClippingParentContainsPoint, _hittedByCamera may be null. --- cocos/ui/UIWidget.cpp | 6 ++++-- .../CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cocos/ui/UIWidget.cpp b/cocos/ui/UIWidget.cpp index a48baecba3..ac4c173e46 100644 --- a/cocos/ui/UIWidget.cpp +++ b/cocos/ui/UIWidget.cpp @@ -772,8 +772,8 @@ bool Widget::onTouchBegan(Touch *touch, Event *unusedEvent) auto camera = Camera::getVisitingCamera(); if(hitTest(_touchBeganPosition, camera, nullptr)) { - _hittedByCamera = camera; if (isClippingParentContainsPoint(_touchBeganPosition)) { + _hittedByCamera = camera; _hitted = true; } } @@ -976,7 +976,9 @@ bool Widget::isClippingParentContainsPoint(const Vec2 &pt) if (clippingParent) { bool bRet = false; - if (clippingParent->hitTest(pt, _hittedByCamera, nullptr)) + auto camera = Camera::getVisitingCamera(); + // Camera isn't null means in touch begin process, otherwise use _hittedByCamera instead. + if (clippingParent->hitTest(pt, (camera ? camera : _hittedByCamera), nullptr)) { bRet = true; } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp index 6170a0f2c2..b9e4655aed 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp @@ -430,6 +430,7 @@ bool Issue12692::init() Size widgetSize = _widget->getContentSize(); auto label = Text::create("Issue 12692", "fonts/Marker Felt.ttf", 32); + label->setName("Text Title"); label->setAnchorPoint(Vec2(0.5f, -1.0f)); label->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + label->getContentSize().height * 1.5f)); @@ -437,6 +438,7 @@ bool Issue12692::init() Text* alert = Text::create("ListView in ListView enable Scissor Clipping", "fonts/Marker Felt.ttf", 20); + alert->setName("Text Alert"); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f)); @@ -495,7 +497,7 @@ bool Issue12692::init() } { Button* default_button = Button::create("cocosui/backtotoppressed.png", "cocosui/backtotopnormal.png"); - default_button->setName("Title Button"); + default_button->setName("Title Button 2"); Layout* default_item = Layout::create(); default_item->setTouchEnabled(true); @@ -529,7 +531,6 @@ bool Issue8316::init() widgetSize.height / 2.0f + label->getContentSize().height * 1.5f)); _uiLayer->addChild(label); - Text* alert = Text::create("ListView Disable Touch", "fonts/Marker Felt.ttf", 20); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Vec2(widgetSize.width / 2.0f,