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; }
void ListView::remedyLayoutParameter(Widget *item) { if (!item) { return; } switch (_direction) { case SCROLLVIEW_DIR_VERTICAL: { LinearLayoutParameter* llp = (LinearLayoutParameter*)(item->getLayoutParameter(LAYOUT_PARAMETER_LINEAR)); if (!llp) { LinearLayoutParameter* defaultLp = LinearLayoutParameter::create(); switch (_gravity) { case LISTVIEW_GRAVITY_LEFT: defaultLp->setGravity(LINEAR_GRAVITY_LEFT); break; case LISTVIEW_GRAVITY_RIGHT: defaultLp->setGravity(LINEAR_GRAVITY_RIGHT); break; case LISTVIEW_GRAVITY_CENTER_HORIZONTAL: defaultLp->setGravity(LINEAR_GRAVITY_CENTER_HORIZONTAL); break; default: break; } if (getIndex(item) == 0) { defaultLp->setMargin(MarginZero); } else { defaultLp->setMargin(Margin(0.0f, _itemsMargin, 0.0f, 0.0f)); } item->setLayoutParameter(defaultLp); } else { if (getIndex(item) == 0) { llp->setMargin(MarginZero); } else { llp->setMargin(Margin(0.0f, _itemsMargin, 0.0f, 0.0f)); } switch (_gravity) { case LISTVIEW_GRAVITY_LEFT: llp->setGravity(LINEAR_GRAVITY_LEFT); break; case LISTVIEW_GRAVITY_RIGHT: llp->setGravity(LINEAR_GRAVITY_RIGHT); break; case LISTVIEW_GRAVITY_CENTER_HORIZONTAL: llp->setGravity(LINEAR_GRAVITY_CENTER_HORIZONTAL); break; default: break; } } break; } case SCROLLVIEW_DIR_HORIZONTAL: { LinearLayoutParameter* llp = (LinearLayoutParameter*)(item->getLayoutParameter(LAYOUT_PARAMETER_LINEAR)); if (!llp) { LinearLayoutParameter* defaultLp = LinearLayoutParameter::create(); switch (_gravity) { case LISTVIEW_GRAVITY_TOP: defaultLp->setGravity(LINEAR_GRAVITY_TOP); break; case LISTVIEW_GRAVITY_BOTTOM: defaultLp->setGravity(LINEAR_GRAVITY_BOTTOM); break; case LISTVIEW_GRAVITY_CENTER_VERTICAL: defaultLp->setGravity(LINEAR_GRAVITY_CENTER_VERTICAL); break; default: break; } if (getIndex(item) == 0) { defaultLp->setMargin(MarginZero); } else { defaultLp->setMargin(Margin(_itemsMargin, 0.0f, 0.0f, 0.0f)); } item->setLayoutParameter(defaultLp); } else { if (getIndex(item) == 0) { llp->setMargin(MarginZero); } else { llp->setMargin(Margin(_itemsMargin, 0.0f, 0.0f, 0.0f)); } switch (_gravity) { case LISTVIEW_GRAVITY_TOP: llp->setGravity(LINEAR_GRAVITY_TOP); break; case LISTVIEW_GRAVITY_BOTTOM: llp->setGravity(LINEAR_GRAVITY_BOTTOM); break; case LISTVIEW_GRAVITY_CENTER_VERTICAL: llp->setGravity(LINEAR_GRAVITY_CENTER_VERTICAL); break; default: break; } } break; } default: break; } }
bool WindowProtocol::init(){ bool ret = false; //super init if(!Layer::init()) return ret; //Put blocker Layer* blocker = LayerColor::create(Color4B(0, 0, 0, 255*0.5), VisibleRect::getVisibleRect().size.width, VisibleRect::getVisibleRect().size.height); blocker->setAnchorPoint(Vec2::ZERO); blocker->setPosition(Vec2(VisibleRect::getVisibleRect().origin.x, VisibleRect::getVisibleRect().origin.y)); //Base window _baseWindow = Scale9Sprite::createWithSpriteFrameName("WindowBase.psd",BASE_WINDOW_INSET_RECT); _baseWindow->setContentSize(Size(850,490-10-10)); _baseWindow->setAnchorPoint(Vec2(0.0, 1.0)); _baseWindow->setPosition(Vec2(55, VisibleRect::getVisibleRect().size.height-60)); //Put base window _baseLayout = Layout::create(); CCASSERT(_baseLayout!=nullptr, "_baseLayout cannot be null."); _baseLayout->setLayoutType(Layout::Type::VERTICAL); _baseLayout->setContentSize(_baseWindow->getCapInsets().size); _baseLayout->setAnchorPoint(Vec2(0.0, 1.0)); _baseLayout->setPosition(Vec2(2,_baseWindow->getContentSize().height-2)); //PutLayout on sprite _baseWindow->addChild(_baseLayout,0); //---Title--- //Layout _titleLayout = Layout::create(); CCASSERT(_titleLayout!=nullptr, "_titleLayer cannot be null."); //_titleLayout->setAnchorPoint(Vec2(0.0, 1.0)); _titleLayout->setLayoutType(Layout::Type::HORIZONTAL); _titleLayout->setContentSize(Size(850-2*2, 55)); _titleLayout->setPosition(Vec2(_baseLayout->getContentSize().width/2, _baseLayout->getContentSize().height/2)); //set baseTitle as titleLayout background //No longer need title base image... _titleLayout->setBackGroundColorType(Layout::BackGroundColorType::SOLID); _titleLayout->setBackGroundColor(Color3B(200, 200, 169)); //Close Button LinearLayoutParameter* lpCloseButton = LinearLayoutParameter::create(); _closeButton = Button::create("MainUI_Windows_Close_Normal.png","MainUI_Windows_Close_Pressed.png","",TextureResType::PLIST); CCASSERT(_closeButton!=nullptr, "_closeButton cannot be null."); _closeButton->setPosition(Vec2(_titleLayout->getContentSize().width/2, _titleLayout->getContentSize().height/2)); lpCloseButton->setGravity(LinearLayoutParameter::LinearGravity::LEFT); lpCloseButton->setMargin(Margin(0, 0, 0, 0)); _closeButton->setLayoutParameter(lpCloseButton); if(_closeCallback!=nullptr) _closeButton->addTouchEventListener(_closeCallback); //Title text LinearLayoutParameter* lpTitleText = LinearLayoutParameter::create(); _titleText = Text::create(_titleString, "fonts/Apple_LiGothic_Medium.ttf", computeFontSize(42)); CCASSERT(_titleText!=nullptr, "_titletext cannot be null."); _titleText->setColor(Color3B(59,134,134)); _titleText->setPosition(Vec2(_titleLayout->getContentSize().width/2, _titleLayout->getContentSize().height/2)); lpTitleText->setGravity(LinearLayoutParameter::LinearGravity::CENTER_VERTICAL); lpTitleText->setMargin(Margin(_titleLayout->getContentSize().width/2-_titleText->getContentSize().width/2-_closeButton->getContentSize().width, 0, 0, 0)); _titleText->setLayoutParameter(lpTitleText); //Add component to title layout _titleLayout->addChild(_closeButton,1); _titleLayout->addChild(_titleText,2); //---add to base layout--- _baseLayout->addChild(_titleLayout); //setBlockerTouchDispatcher auto touchBlocker = EventListenerTouchOneByOne::create(); touchBlocker->setSwallowTouches(true); //lambda decide later touchBlocker->onTouchBegan= [](Touch* touch,Event* e){ return true; }; _eventDispatcher->addEventListenerWithSceneGraphPriority(touchBlocker, blocker); //addChild addChild(blocker,0); addChild(_baseWindow,1); ret = true; return ret; }
void ListView::remedyLayoutParameter(Widget *item) { if (!item) { return; } switch (_direction) { case Direction::VERTICAL: { LinearLayoutParameter* llp = (LinearLayoutParameter*)(item->getLayoutParameter()); if (!llp) { LinearLayoutParameter* defaultLp = LinearLayoutParameter::create(); switch (_gravity) { case Gravity::LEFT: defaultLp->setGravity(LinearLayoutParameter::LinearGravity::LEFT); break; case Gravity::RIGHT: defaultLp->setGravity(LinearLayoutParameter::LinearGravity::RIGHT); break; case Gravity::CENTER_HORIZONTAL: defaultLp->setGravity(LinearLayoutParameter::LinearGravity::CENTER_HORIZONTAL); break; default: break; } if (getIndex(item) == 0) { defaultLp->setMargin(Margin::ZERO); } else { defaultLp->setMargin(Margin(0.0f, _itemsMargin, 0.0f, 0.0f)); } item->setLayoutParameter(defaultLp); } else { if (getIndex(item) == 0) { llp->setMargin(Margin::ZERO); } else { llp->setMargin(Margin(0.0f, _itemsMargin, 0.0f, 0.0f)); } switch (_gravity) { case Gravity::LEFT: llp->setGravity(LinearLayoutParameter::LinearGravity::LEFT); break; case Gravity::RIGHT: llp->setGravity(LinearLayoutParameter::LinearGravity::RIGHT); break; case Gravity::CENTER_HORIZONTAL: llp->setGravity(LinearLayoutParameter::LinearGravity::CENTER_HORIZONTAL); break; default: break; } } break; } case Direction::HORIZONTAL: { LinearLayoutParameter* llp = (LinearLayoutParameter*)(item->getLayoutParameter()); if (!llp) { LinearLayoutParameter* defaultLp = LinearLayoutParameter::create(); switch (_gravity) { case Gravity::TOP: defaultLp->setGravity(LinearLayoutParameter::LinearGravity::TOP); break; case Gravity::BOTTOM: defaultLp->setGravity(LinearLayoutParameter::LinearGravity::BOTTOM); break; case Gravity::CENTER_VERTICAL: defaultLp->setGravity(LinearLayoutParameter::LinearGravity::CENTER_VERTICAL); break; default: break; } if (getIndex(item) == 0) { defaultLp->setMargin(Margin::ZERO); } else { defaultLp->setMargin(Margin(_itemsMargin, 0.0f, 0.0f, 0.0f)); } item->setLayoutParameter(defaultLp); } else { if (getIndex(item) == 0) { llp->setMargin(Margin::ZERO); } else { llp->setMargin(Margin(_itemsMargin, 0.0f, 0.0f, 0.0f)); } switch (_gravity) { case Gravity::TOP: llp->setGravity(LinearLayoutParameter::LinearGravity::TOP); break; case Gravity::BOTTOM: llp->setGravity(LinearLayoutParameter::LinearGravity::BOTTOM); break; case Gravity::CENTER_VERTICAL: llp->setGravity(LinearLayoutParameter::LinearGravity::CENTER_VERTICAL); break; default: break; } } break; } default: break; } }
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; }