Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
void Layout::setBackGroundImageScale9Enabled(bool able)
{
    if (_backGroundScale9Enabled == able)
    {
        return;
    }
    _backGroundScale9Enabled = able;
    if (nullptr == _backGroundImage)
    {
        addBackGroundImage();
        setBackGroundImage(_backGroundImageFileName,_bgImageTexType);
    }
    _backGroundImage->setScale9Enabled(_backGroundScale9Enabled);
    setBackGroundImageCapInsets(_backGroundImageCapInsets);
}
Exemplo n.º 3
0
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);
    }
}
Exemplo n.º 4
0
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;
}
Exemplo n.º 5
0
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;
    }
}
Exemplo n.º 6
0
void OptionLayer::setViews()
{
	setBackGroundImage("loading.png");	

	CCSprite *title = CCSprite::create("menuTitle.png",CCRectMake(0,0,135,35));
	title->setAnchorPoint(ccp(0.5,1));
	title->setPosition(ccp(getWinSize().width/2,getWinSize().height-20));

	this->addChild(title);

	CCMenuItemToggle *music_trigger = CCMenuItemToggle::createWithTarget(this,menu_selector(OptionLayer::music_triggerCallback),
			CCMenuItemFont::create("Music : On"),CCMenuItemFont::create("Music : Off"),NULL);
	
	music_trigger->setPosition(ccp(getWinSize().width/2,getWinSize().height/2));


	if(SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying())
	{
		music_trigger->setSelectedIndex(1);
	}
	else
	{
		music_trigger->setSelectedIndex(0);
	}

	//menu->setPosition(ccp(getWinSize().width/2,getWinSize().height/2));

	CCLabelBMFont *back = CCLabelBMFont::create("back","arial-14.fnt");

	back->setScale(1.25f);
	CCMenuItemLabel *backLable =  CCMenuItemLabel::create(back,this,menu_selector(OptionLayer::backCallback));
	backLable->setAnchorPoint(ccp(0.5,1));
	backLable->setPosition(ccp(getWinSize().width/2,50));

	CCMenu *menu = CCMenu::create(music_trigger,backLable,NULL);
	menu->setPosition(CCPointZero);

	this->addChild(menu);
}
Exemplo n.º 7
0
void Layout::setBackGroundImageScale9Enabled(bool able)
{
    if (_backGroundScale9Enabled == able)
    {
        return;
    }
    CCNode::removeChild(_backGroundImage, true);
    _backGroundImage = NULL;
    _backGroundScale9Enabled = able;
    if (_backGroundScale9Enabled)
    {
        _backGroundImage = extension::CCScale9Sprite::create();
        CCNode::addChild(_backGroundImage, BACKGROUNDIMAGE_Z, -1);
    }
    else
    {
        _backGroundImage = CCSprite::create();
        CCNode::addChild(_backGroundImage, BACKGROUNDIMAGE_Z, -1);
    }
    setBackGroundImage(_backGroundImageFileName.c_str(),_bgImageTexType);    
    setBackGroundImageCapInsets(_backGroundImageCapInsets);
}
Exemplo n.º 8
0
void Layout::setBackGroundImageScale9Enabled(bool able)
{
    if (_backGroundScale9Enabled == able)
    {
        return;
    }
    _backGroundScale9Enabled = able;
    if (nullptr == _backGroundImage)
    {
        addBackGroundImage();
        setBackGroundImage(_backGroundImageFileName,_bgImageTexType);
    }
    if(_backGroundScale9Enabled){
        _backGroundImage->setRenderingType(Scale9Sprite::RenderingType::SLICE);
        _backGroundImage->setPreferredSize(_contentSize);
    }else{
        _backGroundImage->setRenderingType(Scale9Sprite::RenderingType::SIMPLE);
        _backGroundImage->setPreferredSize(_backGroundImageTextureSize);
    }

    setBackGroundImageCapInsets(_backGroundImageCapInsets);
}
Exemplo n.º 9
0
void UILayout::setBackGroundImageScale9Enabled(bool able)
{
    if (m_bBackGroundScale9Enabled == able)
    {
        return;
    }
    m_pRenderer->removeChild(m_pBackGroundImage, true);
    m_pBackGroundImage = NULL;
    m_bBackGroundScale9Enabled = able;
    if (m_bBackGroundScale9Enabled)
    {
        m_pBackGroundImage = CCScale9Sprite::create();
        m_pRenderer->addChild(m_pBackGroundImage);
    }
    else
    {
        m_pBackGroundImage = CCSprite::create();
        m_pRenderer->addChild(m_pBackGroundImage);
    }
    m_pBackGroundImage->setZOrder(-1);
    setBackGroundImage(m_strBackGroundImageFileName.c_str(),m_eBGImageTexType);    
    setBackGroundImageCapInsets(m_backGroundImageCapInsets);
}
Exemplo n.º 10
0
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;
}
Exemplo n.º 11
0
// on "init" you need to initialize your instance
bool PageTest::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    scheduleUpdate();
    
    percent = 0;
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    
    
    auto loadingBar = ui::LoadingBar::create("sliderProgress.png");
    loadingBar->setTag(0);
    loadingBar->setPosition(Vec2(visibleSize.width/2, visibleSize.height/2));
    loadingBar->setPercent(percent);
    this->addChild(loadingBar);
    
    
    
    
    auto checkBox = ui::CheckBox::create("check_box_normal.png", "check_box_normal_press.png", "check_box_active.png", "check_box_normal_disable.png", "check_box_active_disable.png");
    checkBox->setPosition(Vec2(visibleSize.width / 2.0f, visibleSize.height - 100));
    checkBox->addEventListener(CC_CALLBACK_2(PageTest::selectedEvent, this));
    this->addChild(checkBox);
    
    
    auto slider = ui::Slider::create();
    slider->loadBarTexture("sliderTrack.png");
    slider->loadSlidBallTextures("sliderThumb.png", "sliderThumb.png", "");
    slider->loadProgressBarTexture("sliderProgress.png");
    slider->setPosition(Vec2(visibleSize.width / 2.0f, visibleSize.height - 200));
    slider->addEventListener(CC_CALLBACK_2(PageTest::sliderEvent, this));
    this->addChild(slider);
    
    

    
    // auto recustom = ui::RichElementCustomNode::create(1, Color3B::WHITE, 255, pAr);
    // richText->pushBackElement(recustom);
    
    
    // androidだとバックグランドが緑がデフォ?
    // androidだと盤面全体が背景白になる
    // http://discuss.cocos2d-x.org/t/ui-pageview-bug-with-v3-rc1-green-background-on-android/12897
    //
    auto layout = ui::Layout::create();
    layout->setSize(Size(visibleSize.width, 200.0f));
    layout->setPosition(Vec2::ZERO);
    layout->setBackGroundColorType(ui::Layout::BackGroundColorType::SOLID);
    layout->setBackGroundColor(Color3B::BLUE);
    this->addChild(layout);
    
    auto pageView = ui::PageView::create();
    /*
    pageView->setBackGroundColorType(ui::Layout::BackGroundColorType::SOLID);
    pageView->setBackGroundColor(Color3B::RED);
    */
    pageView->setSize(Size(visibleSize.width, 130.0f));
    pageView->setPosition(Vec2::ZERO);
    pageView->setContentSize(Size(visibleSize.width, 130.0f));
    
    for (int i = 0; i < 3; ++i) {
        auto layout = ui::Layout::create();
        layout->setBackGroundImage("");
        layout->setBackGroundColor(Color3B::YELLOW);
        layout->setBackGroundColorType(ui::Layout::BackGroundColorType::SOLID);
        layout->setSize(Size(240.0f, 130.0f));
        // layout->addTouchEventListener(<#ccWidgetTouchCallback callback#>)

        
        auto imageView = ui::ImageView::create("HelloWorld.png");
        imageView->setScale9Enabled(true);
        imageView->setSize(Size(240, 130));
        imageView->setPosition(Vec2(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f));
        layout->addChild(imageView);
        
        auto label = ui::Text::create(StringUtils::format("page %d",(i+1)), "Arial", 30);
        label->setColor(Color3B(192, 192, 192));
        label->setPosition(Vec2(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f));
        layout->addChild(label);
        
        auto btn = ui::Button::create("");
        btn->setTitleText("");
        btn->setTitleFontSize(12);
        btn->setTitleFontName("");

        
        
        pageView->addPage(layout);
    }
    // pageView->scrollToPage(2);  // うまくいかない。handleReleaseLogicのboundaryのためだと思われる
    pageView->addEventListener(CC_CALLBACK_2(PageTest::pageViewEvent, this));
    
    
    layout->addChild(pageView);
    
    
    auto richText = ui::RichText::create();
    richText->ignoreContentAdaptWithSize(false);
    richText->setSize(Size(100, 100));
    richText->setPosition(Vec2(visibleSize.width / 2.0f, visibleSize.height - 300));
    this->addChild(richText);
    
    auto re1 = ui::RichElementText::create(1, Color3B::WHITE, 255, "This color is white. ", "Arial", 10);
    richText->pushBackElement(re1);
    
    auto re2 = ui::RichElementText::create(2, Color3B::YELLOW, 255, "This color is yellow. ", "Arial", 24);
    richText->insertElement(re2, 1);
    
    auto reimg = ui::RichElementImage::create(6, Color3B::WHITE, 255, "sliderballnormal.png");
    richText->pushBackElement(reimg);

    
    return true;
}