Layout* UI::createLayout(int i){ auto lo=Layout::create(); lo->setBackGroundImage("HelloWorld.png"); lo->setBackGroundImageScale9Enabled(true); lo->setContentSize(Size(480,320)*1.5); for (int i=0; i<5; i++) { for (int j=0; j<7; j++) { auto ub=Button::create(); ub->loadTextureNormal("editBG.png"); ub->loadTexturePressed("editBG.png"); ub->loadTextureDisabled("editBg.png"); ub->setScale9Enabled(true); ub->setContentSize(Size(100,50)); ub->setPressedActionEnabled(true); ub->setZoomScale(0.5f); ub->setTitleFontName("fonts/Marker Felt.ttf"); ub->setTitleFontSize(30); ub->setTitleColor(Color3B::GREEN); ub->setTitleText(StringUtils::format("%d--%d",i,j)); ub->addClickEventListener(CC_CALLBACK_1(UI::buttonClick, this)); ub->setTag(i); ub->setPosition(Vec2(70+120*i, 35+j*60)); lo->addChild(ub); } } return lo; }
void UILayout::copySpecialProperties(UIWidget *widget) { UILayout* layout = dynamic_cast<UILayout*>(widget); if (layout) { setBackGroundImageScale9Enabled(layout->m_bBackGroundScale9Enabled); setBackGroundImage(layout->m_strBackGroundImageFileName.c_str(),layout->m_eBGImageTexType); setBackGroundImageCapInsets(layout->m_backGroundImageCapInsets); setBackGroundColorType(layout->m_colorType); setBackGroundColor(layout->m_cColor); setBackGroundColor(layout->m_gStartColor, layout->m_gEndColor); setBackGroundColorOpacity(layout->m_nCOpacity); setBackGroundColorVector(layout->m_AlongVector); setLayoutType(layout->m_eLayoutType); setClippingEnabled(layout->m_bClippingEnabled); } }
bool DialogBox::init() { if (!ui::Layout::init()) return false; const Size &contentSize = Size(620, 250); auto center = Vec2(contentSize / 2.f); setContentSize(contentSize); setCascadeOpacityEnabled(true); setAnchorPoint(Vec2::ANCHOR_MIDDLE); setBackGroundImage("bg_panel.png", TextureResType::PLIST); setBackGroundImageScale9Enabled(true); setPosition(_world->_canvasCenter); setScaleY(0.f); auto touchListener = cocos2d::EventListenerTouchOneByOne::create(); touchListener->setSwallowTouches(true); touchListener->onTouchBegan = [&](Touch *touch, Event *event) { return true; }; Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(touchListener, this); _text = ui::Text::create(); _text->setFontName("fonts/kenvector_future.ttf"); _text->setFontSize(24); _text->setAnchorPoint(Vec2::ANCHOR_MIDDLE); _text->setColor(Palette::ICE); _text->setPosition(center + Vec2(0.f, 50.f)); _text->setVisible(false); addChild(_text); auto button = ui::Button::create("btn_no_n.png", "btn_no_t.png", "", TextureResType::PLIST); button->setPosition(center + Vec2(-150.f, -50.f)); button->addTouchEventListener(CC_CALLBACK_2(DialogBox::noButtonCallback, this)); button->setVisible(false); addChild(button); _yesButton = ui::Button::create("btn_yes_n.png", "btn_yes_t.png", "", TextureResType::PLIST); _yesButton->setPosition(center + Vec2(150.f, -50.f)); _yesButton->setVisible(false); addChild(_yesButton); return true; }
void Layout::copySpecialProperties(Widget *widget) { Layout* layout = dynamic_cast<Layout*>(widget); if (layout) { setBackGroundImageScale9Enabled(layout->_backGroundScale9Enabled); setBackGroundImage(layout->_backGroundImageFileName,layout->_bgImageTexType); setBackGroundImageCapInsets(layout->_backGroundImageCapInsets); setBackGroundColorType(layout->_colorType); setBackGroundColor(layout->_cColor); setBackGroundColor(layout->_gStartColor, layout->_gEndColor); setBackGroundColorOpacity(layout->_cOpacity); setBackGroundColorVector(layout->_alongVector); setLayoutType(layout->_layoutType); setClippingEnabled(layout->_clippingEnabled); setClippingType(layout->_clippingType); _loopFocus = layout->_loopFocus; _passFocusToChild = layout->_passFocusToChild; _isInterceptTouch = layout->_isInterceptTouch; } }
Layout * Mx::createDialog(Node* child, Node * parent, Size innerSize, DialogBtn buttonStyle, string background){ auto layout = Layout::create(); auto size = parent->getContentSize(); auto dialogSize = Size(innerSize.width + 30, innerSize.height + 30); parent->addChild(layout, 999); layout->setContentSize(size); layout->setBackGroundColorType(cocos2d::ui::Layout::BackGroundColorType::SOLID); layout->setBackGroundColor(Color3B::BLACK); layout->setBackGroundColorOpacity(150); layout->setTouchEnabled(true); auto diaLayout = Layout::create(); layout->addChild(diaLayout); diaLayout->setContentSize(innerSize); diaLayout->setClippingEnabled(false); diaLayout->setAnchorPoint(Vec2::ANCHOR_MIDDLE); diaLayout->setPosition(Vec2(dialogSize.width/2, dialogSize.height/2)); diaLayout->setScale(0); diaLayout->setBackGroundImageScale9Enabled(true); if (background == "") { diaLayout->setBackGroundImage("sys_toast_b.png"); }else{ diaLayout->setBackGroundImage(background); } diaLayout->setPosition(size/2); if (child != nullptr) { diaLayout->addChild(child); } // set button; { if (buttonStyle.buttonNum != 0) { if (buttonStyle.closeText == "") { buttonStyle.closeText = this->getStrValue("close"); } auto buttonConfirm = this->createDialogButton(buttonStyle, buttonStyle.confirmText); auto buttonClose = this->createDialogButton(buttonStyle, buttonStyle.closeText); if (buttonStyle.buttonNum == 1) { buttonConfirm->setPosition(Vec2((dialogSize/2).width, 0)); diaLayout->addChild(buttonConfirm); }else{ Size size = buttonConfirm->getContentSize()/2; Size center = dialogSize/2; buttonConfirm->setPosition(Vec2(center.width - size.width, 0)); buttonClose->setPosition(Vec2(center.width + size.width, 0)); diaLayout->addChild(buttonConfirm); diaLayout->addChild(buttonClose); } } if (buttonStyle.isVisibleClose) { auto buttonClose = this->createDialogCloseButton(buttonStyle, buttonStyle.closeText, layout, diaLayout); diaLayout->addChild(buttonClose); buttonClose->setPosition(diaLayout->getContentSize() - buttonClose->getContentSize()/2 + Size(25, 25)); } } auto action = EaseBackOut::create(ScaleTo::create(.3, 1)); diaLayout->runAction(action); return layout; }