From 29c57568bfb21896da6269bca9d420a4fa238c2b Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 6 May 2014 14:38:45 +0800 Subject: [PATCH] issue #4861, add nested focus test --- .../CocoStudioGUITest/CocosGUIScene.cpp | 2 +- .../UIFocusTest/UIFocusTest.cpp | 87 +++++++++++++++++++ .../CocoStudioGUITest/UISceneManager.cpp | 5 +- .../CocoStudioGUITest/UISceneManager.h | 1 + 4 files changed, 93 insertions(+), 2 deletions(-) diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CocosGUIScene.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CocosGUIScene.cpp index 3461af2e8f..d6f33210a6 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CocosGUIScene.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CocosGUIScene.cpp @@ -274,7 +274,7 @@ g_guisTests[] = UISceneManager* pManager = UISceneManager::sharedUISceneManager(); pManager->setCurrentUISceneId(KUIFocusTest_HBox); pManager->setMinUISceneId(KUIFocusTest_HBox); - pManager->setMaxUISceneId(KUIFocusTest_VBox); + pManager->setMaxUISceneId(KUIFocusTest_NestedLayout1); Scene* pScene = pManager->currentUIScene(); Director::getInstance()->replaceScene(pScene); } diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIFocusTest/UIFocusTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIFocusTest/UIFocusTest.cpp index 3abd184f64..a52eddacad 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIFocusTest/UIFocusTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIFocusTest/UIFocusTest.cpp @@ -255,3 +255,90 @@ void UIFocusTestVertical::toggleFocusLoop(cocos2d::Ref * pObjc, TouchEventType t } //UIFocusTestNestedLayout1 +UIFocusTestNestedLayout1::UIFocusTestNestedLayout1() +{ + +} + +UIFocusTestNestedLayout1::~UIFocusTestNestedLayout1() +{ + +} + +bool UIFocusTestNestedLayout1::init() +{ + if (UIFocusTestBase::init()) { + + Size winSize = Director::getInstance()->getVisibleSize(); + + _verticalLayout = VBox::create(); + _verticalLayout->setPosition(Vector2(winSize.width/2 - 100, winSize.height - 70)); + _uiLayer->addChild(_verticalLayout); + _verticalLayout->setScale(0.8); + + _verticalLayout->setFocused(true); + _verticalLayout->setLoopFocus(true); + _firstFocusedWidget = _verticalLayout; + + int count = 1; + for (int i=0; isetTouchEnabled(true); + w->addTouchEventListener(this, toucheventselector(UIFocusTestVertical::onImageViewClicked)); + _verticalLayout->addChild(w); + } + + //add HBox into VBox + HBox *hbox = HBox::create(); + hbox->setScale(0.8); + _verticalLayout->addChild(hbox); + + count = 2; + for (int i=0; i < count; ++i) { + ImageView *w = ImageView::create("cocosui/scrollviewbg.png"); + w->setTouchEnabled(true); + w->addTouchEventListener(this, toucheventselector(UIFocusTestVertical::onImageViewClicked)); + hbox->addChild(w); + } + + VBox *innerVBox = VBox::create(); + hbox->addChild(innerVBox); + + count = 2; + for (int i=0; isetTouchEnabled(true); + w->addTouchEventListener(this, toucheventselector(UIFocusTestVertical::onImageViewClicked)); + innerVBox->addChild(w); + } + + _loopText = Text::create("loop enabled", "Airal", 20); + _loopText->setPosition(Vector2(winSize.width/2, winSize.height - 50)); + _loopText->setColor(Color3B::GREEN); + this->addChild(_loopText); + + auto btn = Button::create("cocosui/switch-mask.png"); + btn->setTitleText("Toggle Loop"); + btn->setPosition(Vector2(60, winSize.height - 50)); + btn->setTitleColor(Color3B::RED); + btn->addTouchEventListener(this, toucheventselector(UIFocusTestHorizontal::toggleFocusLoop)); + this->addChild(btn); + + + return true; + } + return false; +} + + +void UIFocusTestNestedLayout1::toggleFocusLoop(cocos2d::Ref * pObjc, TouchEventType type) +{ + if (type == TouchEventType::TOUCH_EVENT_ENDED) { + _verticalLayout->setLoopFocus(!_verticalLayout->getLoopFocus()); + if (_verticalLayout->getLoopFocus()) { + _loopText->setText("loop enabled"); + }else{ + _loopText->setText("loop disabled"); + } + } +} \ No newline at end of file diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UISceneManager.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UISceneManager.cpp index 164e204836..0b75d201f5 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UISceneManager.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UISceneManager.cpp @@ -111,7 +111,8 @@ static const char* s_testArray[] = "UIWidgetAddNodeTest", "UIRichTextTest", "UIFocusTest-HBox", - "UIFocusTest-VBox" + "UIFocusTest-VBox", + "UIFocusTest-NestedLayout1" }; static UISceneManager *sharedInstance = NULL; @@ -366,6 +367,8 @@ Scene *UISceneManager::currentUIScene() return UIFocusTestHorizontal::sceneWithTitle(s_testArray[_currentUISceneId]); case KUIFocusTest_VBox: return UIFocusTestVertical::sceneWithTitle(s_testArray[_currentUISceneId]); + case KUIFocusTest_NestedLayout1: + return UIFocusTestNestedLayout1::sceneWithTitle(s_testArray[_currentUISceneId]); } return NULL; diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UISceneManager.h b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UISceneManager.h index 767dd161f8..0389ec4f41 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UISceneManager.h +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UISceneManager.h @@ -103,6 +103,7 @@ enum kUIRichTextTest, KUIFocusTest_HBox, KUIFocusTest_VBox, + KUIFocusTest_NestedLayout1, kUITestMax };