bool PlayVideoLayer::init() { if (! Layer::init()){ return false; } MenuItemFont::setFontSize(16); _visibleRect = Director::getInstance()->getOpenGLView()->getVisibleRect(); //createVideo(); playResourceVideo(); /* ==============test============== */ LinearLayoutParameter *layoutParams = LinearLayoutParameter::create(); layoutParams->setMargin(Margin(59,40,0,0)); //first layout ��剧ず涓����涓���������� HBox HBox *layoutHeader = HBox::create(); // layoutHeader->setLoopFocus(true); layoutHeader->setLayoutParameter(layoutParams); layoutHeader->setFocused(true); _widget = layoutHeader; /* ==============test============== */ //register focus event _eventListener = EventListenerFocus::create(); _eventListener->onFocusChanged = CC_CALLBACK_2(PlayVideoLayer::onFocusChanged, this); _eventDispatcher->addEventListenerWithFixedPriority(_eventListener, 1); //register the keyboard event _keyboardListener = EventListenerKeyboard::create(); _keyboardListener->onKeyReleased = CC_CALLBACK_2(PlayVideoLayer::onKeyboardReleased, this); _eventDispatcher->addEventListenerWithFixedPriority(_keyboardListener, 2); return true; }
bool UIFocusTestNestedLayout3::init() { if (UIFocusTestBase::init()) { Size winSize = Director::getInstance()->getVisibleSize(); _verticalLayout = VBox::create(); _verticalLayout->setPosition(Vec2(40, winSize.height - 70)); _uiLayer->addChild(_verticalLayout); _verticalLayout->setScale(0.8f); _verticalLayout->setFocused(true); _verticalLayout->setLoopFocus(true); _verticalLayout->setTag(-1000); _firstFocusedWidget = _verticalLayout; HBox *upperHBox = HBox::create(); upperHBox->setTag(-200); _verticalLayout->addChild(upperHBox); LinearLayoutParameter *params = LinearLayoutParameter::create(); params->setMargin(Margin(0,0,50,0)); LinearLayoutParameter *vparams = LinearLayoutParameter::create(); vparams->setMargin(Margin(10, 0, 0, 140)); upperHBox->setLayoutParameter(vparams); int count = 3; for (int i=0; i<count; ++i) { VBox *firstVbox = VBox::create(); firstVbox->setScale(0.5); firstVbox->setLayoutParameter(params); firstVbox->setTag((i+1) * 100); int count1 = 3; for (int j=0; j<count1; ++j) { ImageView *w = ImageView::create("cocosui/scrollviewbg.png"); w->setTouchEnabled(true); w->setTag(j+firstVbox->getTag()+1); w->addTouchEventListener(CC_CALLBACK_2(UIFocusTestBase::onImageViewClicked, this)); firstVbox->addChild(w); } upperHBox->addChild(firstVbox); } HBox *bottomHBox = HBox::create(); bottomHBox->setScale(0.5); bottomHBox->setTag(600); bottomHBox->setLayoutParameter(vparams); count = 3; LinearLayoutParameter *bottomParams = LinearLayoutParameter::create(); bottomParams->setMargin(Margin(0, 0, 8, 0)); for (int i=0; i < count; ++i) { ImageView *w = ImageView::create("cocosui/scrollviewbg.png"); w->setLayoutParameter(bottomParams); w->setTouchEnabled(true); w->setTag(i+601); w->addTouchEventListener(CC_CALLBACK_2(UIFocusTestBase::onImageViewClicked, this)); bottomHBox->addChild(w); } _verticalLayout->addChild(bottomHBox); _loopText = Text::create("loop enabled", "Arial", 20); _loopText->setPosition(Vec2(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(Vec2(60, winSize.height - 50)); btn->setTitleColor(Color3B::RED); btn->addTouchEventListener(CC_CALLBACK_2(UIFocusTestNestedLayout3::toggleFocusLoop, this)); this->addChild(btn); return true; } return false; }