bool UILabelTest::init()
{
    if (UIScene::init())
    {
        CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
        
        UILabel *alert = UILabel::create();
        alert->setText("Label");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
//        alert->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getRect().size.height * 1.75));
        m_pUiLayer->addWidget(alert);
        
        // Create the label
        UILabel* label = UILabel::create();
        label->setText("Label");
        label->setFontName("AmericanTypewriter");
        label->setFontSize(30);
//        label->setPosition(ccp(screenSize.width / 2, screenSize.height / 2 + label->getRect().size.height / 4));
        m_pUiLayer->addWidget(label);
        
        return true;
    }
    return false;
}
bool UIImageViewTest_Scale9::init()
{
    if (UIScene::init())
    {
        CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
        
        UILabel *alert = UILabel::create();
        alert->setText("ImageView scale9 render");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
//        alert->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getRect().size.height * 1.75));
        m_pUiLayer->addWidget(alert);
        
        // Create the ui layer
        UILayer *ul = UILayer::create();
        ul->scheduleUpdate();
        addChild(ul);
        
        // Create the imageview
        UIImageView *imageView = UIImageView::create();
        imageView->setScale9Enabled(true);
        imageView->loadTexture("cocosgui/buttonHighlighted.png");
//        imageView->setScale9Size(CCSizeMake(200, 85));
//        imageView->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f + imageView->getRect().size.height / 4.0f));
        ul->addWidget(imageView);
        
        return true;
    }
    return false;
}
bool UILoadingBarTest_Left::init()
{
    if (UIScene::init())
    {
        scheduleUpdate();
        
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("LoadingBar left");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75));
        m_pUiLayer->addWidget(alert);
        
        // Create the loading bar
        UILoadingBar* loadingBar = UILoadingBar::create();
        loadingBar->setName("LoadingBar");
        loadingBar->loadTexture("cocosui/sliderProgress.png");        
        loadingBar->setPercent(0);
        
        loadingBar->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f));
        m_pUiLayer->addWidget(loadingBar);
        
        return true;
    }
    return false;
}
bool UITextAreaTest::init()
{
    if (UIScene::init())
    {
        CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
        
        UILabel *alert = UILabel::create();
        alert->setText("TextArea");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getRect().size.height * 1.75));
        m_pUiLayer->addWidget(alert);        
        
        // Create the text area
        UITextArea* textArea = UITextArea::create();
        textArea->setTextAreaSize(CCSizeMake(280, 150));
        textArea->setTextHorizontalAlignment(kCCTextAlignmentCenter);
        textArea->setText("TextArea widget can line wrap");
        textArea->setFontName("AmericanTypewriter");
        textArea->setFontSize(32);
        textArea->setPosition(ccp(screenSize.width / 2, screenSize.height / 2 - textArea->getRect().size.height / 8));
        m_pUiLayer->addWidget(textArea);
        
        return true;
    }
    return false;
}
bool UILoadingBarTest_Left_Scale9::init()
{
    if (UIScene::init())
    {
        scheduleUpdate();
        
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("LoadingBar left scale9 render");
        alert->setFontName("Marker Felt");
        alert->setFontSize(20);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.7));
        m_pUiLayer->addWidget(alert);
        
        // Create the loading bar
        UILoadingBar* loadingBar = UILoadingBar::create();
        loadingBar->setName("LoadingBar");
        loadingBar->loadTexture("cocosui/slider_bar_active_9patch.png");
        loadingBar->setScale9Enabled(true);
        loadingBar->setCapInsets(CCRectMake(0, 0, 0, 0));
        /*===*/
        loadingBar->setSize(CCSizeMake(300, loadingBar->getContentSize().height));
        /*=*/
        loadingBar->setPercent(0);
        
        loadingBar->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f));
        m_pUiLayer->addWidget(loadingBar);
        
        return true;
    }
    return false;
}
bool UIWidgetAddNodeTest::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("Widget Add Node");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75));
        m_pUiLayer->addWidget(alert);
        
        // Create the ui node container
        UIWidget* widget = UIWidget::create();
        widget->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
        m_pUiLayer->addWidget(widget);
        
        CCSprite* sprite = CCSprite::create("cocosui/ccicon.png");
        sprite->setPosition(ccp(0, sprite->boundingBox().size.height / 4));
        widget->addNode(sprite);
        
        return true;
    }
    return false;
}
bool UILoadingBarTest::init()
{
    if (UIScene::init())
    {
        scheduleUpdate();
        
        CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("LoadingBar");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
//        alert->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getRect().size.height * 1.75));
        m_pUiLayer->addWidget(alert);
        
        // Create the loading bar
        UILoadingBar* loadingBar = UILoadingBar::create();
        loadingBar->setName("LoadingBar");
        loadingBar->loadTexture("cocosgui/sliderProgress.png");
//        loadingBar->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f + loadingBar->getRect().size.height / 4.0f));
        m_pUiLayer->addWidget(loadingBar);
        
        return true;
    }
    return false;
}
void CocosGUIExamplesPageScene::onEnter()
{
    CCScene::onEnter();
    
    m_pUILayer = UILayer::create();
    m_pUILayer->scheduleUpdate();
    addChild(m_pUILayer);
    
    PageInit();
    
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    
    UILabel* label = UILabel::create();
    label->setText("Move by horizontal direction");
    label->setFontName("Marker Felt");
    label->setFontSize(32);
    label->setAnchorPoint(ccp(0.5f, -1));
    label->setPosition(ccp(winSize.width / 2.0f, winSize.height / 2.0f + label->getContentSize().height * 1.5));
    m_pUILayer->addWidget(label);
    
    // left button
    UIButton* left_button = UIButton::create();
    left_button->setTouchEnable(true);
    left_button->loadTextures("cocosgui/UITest/b1.png", "cocosgui/UITest/b2.png", "");
    float left_button_width = left_button->getContentSize().width;
    left_button->setPosition(ccp(left_button_width - left_button_width / 2, m_pUILayer->getContentSize().height / 2));
    left_button->addReleaseEvent(this, coco_releaseselector(CocosGUIExamplesPageScene::toCocosGUIExamplesMapScene));
    m_pUILayer->addWidget(left_button);
}
Esempio n. 9
0
/*===*/
bool UISliderTest::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add a label in which the slider alert will be displayed
        m_pDisplayValueLabel = UILabel::create();
        m_pDisplayValueLabel->setText("Move the slider thumb");
        m_pDisplayValueLabel->setFontName("Marker Felt");
        m_pDisplayValueLabel->setFontSize(32);
        m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1));
        m_pDisplayValueLabel->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
        m_pUiLayer->addWidget(m_pDisplayValueLabel);
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("Slider");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75));
        m_pUiLayer->addWidget(alert);
        
        // Create the slider
        UISlider* slider = UISlider::create();
        slider->setTouchEnabled(true);
        slider->loadBarTexture("cocosgui/sliderTrack.png");
        slider->loadSlidBallTextures("cocosgui/sliderThumb.png", "cocosgui/sliderThumb.png", "");
        slider->loadProgressBarTexture("cocosgui/sliderProgress.png");
        slider->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
//        slider->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f + slider->getSize().height * 2));
        slider->addEventListenerSlider(this, sliderpercentchangedselector(UISliderTest::sliderEvent));
        m_pUiLayer->addWidget(slider);

        /*
        // Create the slider that set allow min progress and allow max progress
        UISlider* sliderAllow = UISlider::create();
        //===//
//        sliderAllow->setMinAllowPercent(20);
//        sliderAllow->setMaxAllowPercent(80);
        //
        sliderAllow->setTouchEnabled(true);
        sliderAllow->loadBarTexture("cocosgui/sliderTrack.png");
        sliderAllow->loadSlidBallTextures("cocosgui/sliderThumb.png", "cocosgui/sliderThumb.png", "");
        sliderAllow->loadProgressBarTexture("cocosgui/sliderProgress.png");
        sliderAllow->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - sliderAllow->getSize().height * 2));
        sliderAllow->addEventListenerSlider(this, sliderpercentchangedselector(UISliderTest::sliderEvent));
        m_pUiLayer->addWidget(sliderAllow);
         */
        
        return true;
    }
    return false;
}
Esempio n. 10
0
bool UIScrollViewTest_Both::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();;
        
        // Add a label in which the dragpanel events will be displayed
        m_pDisplayValueLabel = UILabel::create();
        m_pDisplayValueLabel->setText("Move by any direction");
        m_pDisplayValueLabel->setFontName("Marker Felt");
        m_pDisplayValueLabel->setFontSize(32);
        m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1));
        m_pDisplayValueLabel->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f + m_pDisplayValueLabel->getSize().height * 1.5));
        m_pUiLayer->addWidget(m_pDisplayValueLabel);
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("ScrollView both");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075));
        m_pUiLayer->addWidget(alert);
        
        Layout *background = dynamic_cast<Layout*>(m_pUiLayer->getWidgetByName("background_Panel"));
        
        // Create the dragpanel
        UIScrollView* scrollView = UIScrollView::create();
        scrollView->setDirection(SCROLLVIEW_DIR_BOTH);
        scrollView->setTouchEnabled(true);
        scrollView->setBounceEnabled(true);
        scrollView->setBackGroundImageScale9Enabled(true);
        scrollView->setBackGroundImage("cocosgui/green_edit.png");
        scrollView->setSize(CCSizeMake(210, 122.5));
        CCSize backgroundSize = background->getContentSize();
        scrollView->setPosition(ccp((widgetSize.width - backgroundSize.width) / 2 +
                                    (backgroundSize.width - scrollView->getSize().width) / 2,
                                    (widgetSize.height - backgroundSize.height) / 2 +
                                    (backgroundSize.height - scrollView->getSize().height) / 2));
        UIImageView* imageView = UIImageView::create();
        imageView->setTouchEnabled(true);
        imageView->loadTexture("cocosgui/b11.png");
        scrollView->addChild(imageView);
        
        scrollView->setInnerContainerSize(imageView->getContentSize());
        CCSize innerSize = scrollView->getInnerContainerSize();
        imageView->setPosition(ccp(innerSize.width / 2, innerSize.height / 2));
        
        m_pUiLayer->addWidget(scrollView);
        
        return true;
    }
    
    return false;
}
Esempio n. 11
0
bool UILayoutTest_Color::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add the alert
        UILabel* alert = UILabel::create();
        alert->setText("Layout color render");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075));
        m_pUiLayer->addWidget(alert);
        
        UILayout *background = dynamic_cast<UILayout*>(m_pUiLayer->getWidgetByName("background_Panel"));
        
        // Create the layout with color render
        UILayout* layout = UILayout::create();
        layout->setBackGroundColorType(LAYOUT_COLOR_SOLID);
        layout->setBackGroundColor(ccc3(128, 128, 128));
        layout->setSize(CCSizeMake(280, 150));
        CCSize backgroundSize = background->getContentSize();
        layout->setPosition(ccp((widgetSize.width - backgroundSize.width) / 2 +
                                (backgroundSize.width - layout->getSize().width) / 2,
                                (widgetSize.height - backgroundSize.height) / 2 +
                                (backgroundSize.height - layout->getSize().height) / 2));
        m_pUiLayer->addWidget(layout);
        
        UIButton* button = UIButton::create();
        button->setTouchEnabled(true);
        button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
        button->setPosition(ccp(button->getSize().width / 2, layout->getSize().height - button->getSize().height / 2));
        layout->addChild(button);
        
        UIButton* titleButton = UIButton::create();
        titleButton->setTouchEnabled(true);
        titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", "");
        titleButton->setTitleText("Title Button");
        titleButton->setPosition(ccp(layout->getSize().width / 2, layout->getSize().height / 2));
        layout->addChild(titleButton);
        
        UIButton* button_scale9 = UIButton::create();
        button_scale9->setTouchEnabled(true);
        button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "");
        button_scale9->setScale9Enabled(true);
        button_scale9->setSize(CCSizeMake(100, button_scale9->getContentSize().height));
        button_scale9->setPosition(ccp(layout->getSize().width - button_scale9->getSize().width / 2, button_scale9->getSize().height / 2));
        layout->addChild(button_scale9);        
        
        return true;
    }
    return false;
}
Esempio n. 12
0
bool UISwitchTest_VerticalAndTitleVertical::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add a label in which the switch events will be displayed
        m_pDisplayValueLabel = UILabel::create();
        m_pDisplayValueLabel->setText("No Event");
        m_pDisplayValueLabel->setFontName("Marker Felt");
        m_pDisplayValueLabel->setFontSize(32);
        m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1));
        m_pDisplayValueLabel->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
        m_pUiLayer->addWidget(m_pDisplayValueLabel);
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("Switch Vertical and Title Vertical");
        alert->setFontName("Marker Felt");
        alert->setFontSize(20);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.7));
        m_pUiLayer->addWidget(alert);
        
        // Create the switch
        UISwitch* pSwitch = UISwitch::create();
        pSwitch->setTouchEnabled(true);
        pSwitch->loadTextures("cocosgui/switch-mask_v.png", "cocosgui/switch-on_v.png", "cocosgui/switch-off_v.png", "cocosgui/switch-thumb_v.png");
        pSwitch->setOnTitleText("On");
        pSwitch->setOffTitleText("Off");
        pSwitch->setOnTitleFontName("Arial-BoldMT");
        pSwitch->setOnTitleFontSize(16);
        pSwitch->setOffTitleFontName("Arial-BoldMT");
        pSwitch->setOffTitleFontSize(16);
        CCSize switchSize = pSwitch->getSize();
        pSwitch->setPosition(ccp((widgetSize.width - switchSize.width) / 2.0f, (widgetSize.height - switchSize.height) / 2.0f));
        pSwitch->addEventListenerSwitch(this, switchselector(UISwitchTest_Horizontal::switchEvent));
        m_pUiLayer->addWidget(pSwitch);
        
        
        pSwitch->setDirection(SWITCH_DIRECTION_VERTICAL);
        
        // set unicode text with title vertical direction
        pSwitch->setTitleDirection(SWITCH_TITLE_DIRECTION_VERTICAL);
        
        return true;
    }
    return false;
}
Esempio n. 13
0
bool UIScrollViewTest_ScrollToPercentBothDirection_Bounce::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add a label in which the dragpanel events will be displayed
        m_pDisplayValueLabel = UILabel::create();
//        m_pDisplayValueLabel->setText("No Event");
        m_pDisplayValueLabel->setFontName("Marker Felt");
        m_pDisplayValueLabel->setFontSize(32);
        m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1));
        m_pDisplayValueLabel->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f + m_pDisplayValueLabel->getSize().height * 1.5));
        m_pUiLayer->addWidget(m_pDisplayValueLabel);
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("ScrollView scroll to percent both directrion bounce");
        alert->setFontName("Marker Felt");
        alert->setFontSize(20);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5));
        m_pUiLayer->addWidget(alert);
        
        UILayout* background = dynamic_cast<UILayout*>(m_pUiLayer->getWidgetByName("background_Panel"));
        
        UIScrollView* sc = UIScrollView::create();
        sc->setBackGroundColor(ccGREEN);
        sc->setBackGroundColorType(LAYOUT_COLOR_SOLID);
        sc->setBounceEnabled(true);
        sc->setDirection(SCROLLVIEW_DIR_BOTH);
        sc->setInnerContainerSize(CCSizeMake(480, 320));
        sc->setSize(CCSizeMake(100,100));
        CCSize backgroundSize = background->getContentSize();
        sc->setPosition(ccp((widgetSize.width - backgroundSize.width) / 2 +
                            (backgroundSize.width - sc->getSize().width) / 2,
                            (widgetSize.height - backgroundSize.height) / 2 +
                            (backgroundSize.height - sc->getSize().height) / 2));
        sc->scrollToPercentBothDirection(ccp(50, 50), 1, true);
        UIImageView* iv = UIImageView::create();
        iv->loadTexture("cocosgui/Hello.png");
        iv->setPosition(ccp(240, 160));
        sc->addChild(iv);
        m_pUiLayer->addWidget(sc);
        return true;
    }
    
    return false;
}
Esempio n. 14
0
bool UISwitchTest_Horizontal::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add a label in which the switch events will be displayed
        m_pDisplayValueLabel = UILabel::create();
        m_pDisplayValueLabel->setText("No Event");
        m_pDisplayValueLabel->setFontName("Marker Felt");
        m_pDisplayValueLabel->setFontSize(32);
        m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1));
        m_pDisplayValueLabel->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
        m_pUiLayer->addWidget(m_pDisplayValueLabel);
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("Switch Horizontal");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75));
        m_pUiLayer->addWidget(alert);
        
        // Create the switch
        UISwitch* pSwitch = UISwitch::create();
        pSwitch->setTouchEnabled(true);
        pSwitch->loadTextures("cocosgui/switch-mask.png", "cocosgui/switch-on.png", "cocosgui/switch-off.png", "cocosgui/switch-thumb.png");
        pSwitch->setOnTitleText("Hello\nWorld");
        pSwitch->setOffTitleText("Come\nOn");
        pSwitch->setOnTitleFontName("Arial-BoldMT");
        pSwitch->setOnTitleFontSize(10);
        pSwitch->setOffTitleFontName("Arial-BoldMT");
        pSwitch->setOffTitleFontSize(10);
        CCSize switchSize = pSwitch->getSize();
        pSwitch->setPosition(ccp((widgetSize.width - switchSize.width) / 2.0f, (widgetSize.height - switchSize.height) / 2.0f));
        pSwitch->addEventListenerSwitch(this, switchselector(UISwitchTest_Horizontal::switchEvent));
        m_pUiLayer->addWidget(pSwitch);
        
        return true;
    }
    return false;
}
Esempio n. 15
0
bool UITextFieldTest_LineWrap::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add a label in which the textfield events will be displayed
        m_pDisplayValueLabel = UILabel::create();
        m_pDisplayValueLabel->setText("No Event");
        m_pDisplayValueLabel->setFontName("Marker Felt");
        m_pDisplayValueLabel->setFontSize(30);
        m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1));
        m_pDisplayValueLabel->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f + m_pDisplayValueLabel->getSize().height * 1.5));
        m_pUiLayer->addWidget(m_pDisplayValueLabel);
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("TextField line wrap");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075));
        m_pUiLayer->addWidget(alert);
        
        // Create the textfield
        UITextField* textField = UITextField::create();
        UICCTextField* render = static_cast<UICCTextField*>(textField->getVirtualRenderer());
        render->setDimensions(CCSizeMake(240, 160));
        render->setHorizontalAlignment(kCCTextAlignmentCenter);
        render->setVerticalAlignment(kCCVerticalTextAlignmentCenter);
        textField->setTouchEnabled(true);
        textField->setFontName("Marker Felt");
        textField->setFontSize(30);
        textField->setPlaceHolder("input words here");
        textField->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
        textField->addEventListenerTextField(this, textfieldeventselector(UITextFieldTest_LineWrap::textFieldEvent));
        m_pUiLayer->addWidget(textField);
        
        return true;
    }
    return false;
}
Esempio n. 16
0
bool UITextFieldTest_Password::init()
{
    if (UIScene::init())
    {
        CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
        
        // Add a label in which the textfield events will be displayed
        m_pDisplayValueLabel = UILabel::create();
        m_pDisplayValueLabel->setText("No Event");
        m_pDisplayValueLabel->setFontName("Marker Felt");
        m_pDisplayValueLabel->setFontSize(32);
        m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1));
        m_pDisplayValueLabel->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f + m_pDisplayValueLabel->getSize().height * 1.5));
        m_pUiLayer->addWidget(m_pDisplayValueLabel);
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("TextField password");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getSize().height * 3.0f));
        m_pUiLayer->addWidget(alert);
        
        // Create the textfield
        UITextField* textField = UITextField::create();
        textField->setPasswordEnabled(true);
        textField->setPasswordStyleText("*");
        textField->setTouchEnabled(true);
        textField->setFontName("Marker Felt");
        textField->setFontSize(30);
        textField->setPlaceHolder("input password here");
        textField->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f));
        textField->addEventListenerTextField(this, textfieldeventselector(UITextFieldTest_Password::textFieldEvent));
        m_pUiLayer->addWidget(textField);
        
        return true;
    }
    return false;
}
Esempio n. 17
0
bool UIButtonTest_Scale9::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add a label in which the button events will be displayed
        m_pDisplayValueLabel = UILabel::create();
        m_pDisplayValueLabel->setText("No Event");
        m_pDisplayValueLabel->setFontName("Marker Felt");
        m_pDisplayValueLabel->setFontSize(32);
        m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1));
        m_pDisplayValueLabel->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
        m_pUiLayer->addWidget(m_pDisplayValueLabel);
        
        // Add the alert
        UILabel* alert = UILabel::create();
        alert->setText("Button scale9 render");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75));
        m_pUiLayer->addWidget(alert);
        
        // Create the button
        UIButton* button = UIButton::create();
        button->setTouchEnabled(true);
        // open scale9 render
        button->setScale9Enabled(true);
        button->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "");
        button->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
        button->setSize(CCSizeMake(150, button->getContentSize().height * 1.5f));
        button->addTouchEventListener(this, toucheventselector(UIButtonTest_Scale9::touchEvent));
        m_pUiLayer->addWidget(button);
        
        return true;
    }
    return false;
}
bool UINodeContainerTest::init()
{
    if (UIScene::init())
    {
        CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
        
        // Add a label in which the UINodeContainer alert will be displayed
        m_pDisplayValueLabel = UILabel::create();
        m_pDisplayValueLabel->setText("NodeContainer Add CCNode");
        m_pDisplayValueLabel->setFontName("Marker Felt");
        m_pDisplayValueLabel->setFontSize(32);
        m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1));
//        m_pDisplayValueLabel->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f + m_pDisplayValueLabel->getContentSize().height * 1.5));
        m_pUiLayer->addWidget(m_pDisplayValueLabel);
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("NodeContainer");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
//        alert->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getRect().size.height * 1.75));
        m_pUiLayer->addWidget(alert);
        
        // Create the ui node container
        UINodeContainer* nodeContainer = UINodeContainer::create();
        nodeContainer->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f));
        m_pUiLayer->addWidget(nodeContainer);
        
        CCSprite* sprite = CCSprite::create("cocosgui/ccicon.png");
        sprite->setPosition(ccp(0, sprite->boundingBox().size.height / 4));
        nodeContainer->addCCNode(sprite);
        
        return true;
    }
    return false;
}
bool UIImageViewTest::init()
{
    if (UIScene::init())
    {
        CCSize screenSize = CCDirector::sharedDirector()->getWinSize();                
        
        UILabel *alert = UILabel::create();
        alert->setText("ImageView");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
//        alert->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getRect().size.height * 1.75));
        m_pUiLayer->addWidget(alert);
        
        // Create the imageview
        UIImageView *imageView = UIImageView::create();
        imageView->loadTexture("cocosgui/ccicon.png");
//        imageView->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f + imageView->getRect().size.height / 4.0f));
        m_pUiLayer->addWidget(imageView);
        
        return true;
    }
    return false;
}
Esempio n. 20
0
bool UIPageViewTest::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add a label in which the dragpanel events will be displayed
        m_pDisplayValueLabel = UILabel::create();
        m_pDisplayValueLabel->setText("Move by horizontal direction");
        m_pDisplayValueLabel->setFontName("Marker Felt");
        m_pDisplayValueLabel->setFontSize(32);
        m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1));
        m_pDisplayValueLabel->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f + m_pDisplayValueLabel->getContentSize().height * 1.5));
        m_pUiLayer->addWidget(m_pDisplayValueLabel);
        
        // Add the black background
        UILabel *alert = UILabel::create();
        alert->setText("PageView");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075));
        m_pUiLayer->addWidget(alert);
        
        UILayout *background = dynamic_cast<UILayout*>(m_pUiLayer->getWidgetByName("background_Panel"));
        
        // Create the page view
        UIPageView* pageView = UIPageView::create();
        pageView->setTouchEnabled(true);
        pageView->setSize(CCSizeMake(240, 130));
        CCSize backgroundSize = background->getContentSize();
        pageView->setPosition(ccp((widgetSize.width - backgroundSize.width) / 2 +
                                  (backgroundSize.width - pageView->getSize().width) / 2,
                                  (widgetSize.height - backgroundSize.height) / 2 +
                                  (backgroundSize.height - pageView->getSize().height) / 2));
        
        for (int i = 0; i < 3; ++i)
        {
            UILayout* layout = UILayout::create();
            layout->setSize(CCSizeMake(240, 130));
            
            UIImageView* imageView = UIImageView::create();
            imageView->setTouchEnabled(true);
            imageView->setScale9Enabled(true);
            imageView->loadTexture("cocosgui/scrollviewbg.png");
            imageView->setSize(CCSizeMake(240, 130));
            imageView->setPosition(ccp(layout->getSize().width / 2, layout->getSize().height / 2));
            layout->addChild(imageView);
            
            UILabel* label = UILabel::create();
            label->setText(CCString::createWithFormat("page %d", (i + 1))->getCString());
            label->setFontName("Marker Felt");
            label->setFontSize(30);
            label->setColor(ccc3(192, 192, 192));
            label->setPosition(ccp(layout->getSize().width / 2, layout->getSize().height / 2));
            layout->addChild(label);
            
            pageView->addPage(layout);
        }        
        pageView->addEventListenerPageView(this, pagevieweventselector(UIPageViewTest::pageViewEvent));
        
        m_pUiLayer->addWidget(pageView);
        
        return true;
    }
    return false;
}
Esempio n. 21
0
bool UIScrollViewTest_Vertical::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add a label in which the scrollview alert will be displayed
        m_pDisplayValueLabel = UILabel::create();
        m_pDisplayValueLabel->setText("Move by vertical direction");
        m_pDisplayValueLabel->setFontName("Marker Felt");
        m_pDisplayValueLabel->setFontSize(32);
        m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1));
        m_pDisplayValueLabel->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f + m_pDisplayValueLabel->getContentSize().height * 1.5));
        m_pUiLayer->addWidget(m_pDisplayValueLabel);
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("ScrollView vertical");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075));
        m_pUiLayer->addWidget(alert);
        
        UILayout *background = dynamic_cast<UILayout*>(m_pUiLayer->getWidgetByName("background_Panel"));
        
        // Create the scrollview by vertical
        UIScrollView* scrollView = UIScrollView::create();
        scrollView->setTouchEnabled(true);
        scrollView->setBounceEnabled(true);
        scrollView->setSize(CCSizeMake(280, 150));        
        CCSize backgroundSize = background->getContentSize();
        scrollView->setPosition(ccp((widgetSize.width - backgroundSize.width) / 2 +
                               (backgroundSize.width - scrollView->getSize().width) / 2,
                               (widgetSize.height - backgroundSize.height) / 2 +
                               (backgroundSize.height - scrollView->getSize().height) / 2));
        scrollView->addEventListenerScrollView(this, scrollvieweventselector(UIScrollViewTest_Vertical::scrollEvent));
        m_pUiLayer->addWidget(scrollView);
        
        UIImageView* imageView = UIImageView::create();
        imageView->loadTexture("cocosgui/ccicon.png");
        
        float innerWidth = scrollView->getSize().width;
        float innerHeight = scrollView->getSize().height + imageView->getSize().height * 2;
        
        scrollView->setInnerContainerSize(CCSizeMake(innerWidth, innerHeight));
        
        
        UIButton* button = UIButton::create();
        button->setTouchEnabled(true);
        button->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", "");
        button->setPosition(ccp(innerWidth / 2, scrollView->getInnerContainerSize().height - button->getSize().height / 2));
        scrollView->addChild(button);
        
        UIButton* titleButton = UIButton::create();
        titleButton->setTouchEnabled(true);
        titleButton->loadTextures("cocosgui/backtotopnormal.png", "cocosgui/backtotoppressed.png", "");
        titleButton->setTitleText("Title Button");
        titleButton->setPosition(ccp(innerWidth / 2, button->getBottomInParent() - button->getSize().height));
        scrollView->addChild(titleButton);
        
        UIButton* button_scale9 = UIButton::create();
        button_scale9->setTouchEnabled(true);
        button_scale9->setScale9Enabled(true);
        button_scale9->loadTextures("cocosgui/button.png", "cocosgui/buttonHighlighted.png", "");
        button_scale9->setSize(CCSizeMake(100, button_scale9->getContentSize().height));
        button_scale9->setPosition(ccp(innerWidth / 2, titleButton->getBottomInParent() - titleButton->getSize().height));
        scrollView->addChild(button_scale9);
        
        imageView->setPosition(ccp(innerWidth / 2, imageView->getSize().height / 2));
        scrollView->addChild(imageView);
        
        
        
        
//        UIButton* button_1 = UIButton::create();
//        button_1->setTouchEnabled(true);
//        button_1->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", "");
//        button_1->addTouchEventListener(this, toucheventselector(UIScrollViewTest_Vertical::touchEvent));
//        
//        Layout* layout = Layout::create();
//        layout->setSize(button_1->getSize());
//        layout->setBackGroundImage("cocosgui/green_edit.png");
//        layout->setBackGroundImageScale9Enabled(true);
////        layout->setBackGroundColorType(LAYOUT_COLOR_SOLID);
////        layout->setBackGroundColor(ccc3(0, 255, 0));
//        layout->setPosition(ccp(imageView->getPosition().x, layout->getSize().height * 2));
//        
//        button_1->setPosition(ccp(button_1->getSize().width / 2, button_1->getSize().height / 2));
//        
//        layout->addChild(button_1);
//        scrollView->addChild(layout);
        
        return true;
    }
    
    return false;
}
Esempio n. 22
0
bool UIScrollViewTest_Horizontal::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add a label in which the scrollview alert will be displayed
        m_pDisplayValueLabel = UILabel::create();
        m_pDisplayValueLabel->setText("Move by horizontal direction");
        m_pDisplayValueLabel->setFontName("Marker Felt");
        m_pDisplayValueLabel->setFontSize(32);
        m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1));
        m_pDisplayValueLabel->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f + m_pDisplayValueLabel->getContentSize().height * 1.5));
        m_pUiLayer->addWidget(m_pDisplayValueLabel);            
        
        UILabel *alert = UILabel::create();
        alert->setText("ScrollView horizontal");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075));
        m_pUiLayer->addWidget(alert);
        
        UILayout *background = dynamic_cast<UILayout*>(m_pUiLayer->getWidgetByName("background_Panel"));
        
        // Create the scrollview by horizontal
        UIScrollView* scrollView = UIScrollView::create();        
        scrollView->setDirection(SCROLLVIEW_DIR_HORIZONTAL);
        scrollView->setBounceEnabled(true);
        scrollView->setTouchEnabled(true);
        scrollView->setSize(CCSizeMake(280, 150));
        scrollView->setInnerContainerSize(scrollView->getSize());
        CCSize backgroundSize = background->getContentSize();
        scrollView->setPosition(ccp((widgetSize.width - backgroundSize.width) / 2 +
                                    (backgroundSize.width - scrollView->getSize().width) / 2,
                                    (widgetSize.height - backgroundSize.height) / 2 +
                                    (backgroundSize.height - scrollView->getSize().height) / 2));
        m_pUiLayer->addWidget(scrollView);
        
        UIImageView* imageView = UIImageView::create();
        imageView->loadTexture("cocosgui/ccicon.png");
        
        float innerWidth = scrollView->getSize().width + imageView->getSize().width * 2;
        float innerHeight = scrollView->getSize().height;
        
        scrollView->setInnerContainerSize(CCSizeMake(innerWidth, innerHeight));
        
        UIButton* button = UIButton::create();
        button->setTouchEnabled(true);
        button->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", "");
        button->setPosition(ccp(button->getSize().width / 2,
                                scrollView->getInnerContainerSize().height - button->getSize().height / 2));
        scrollView->addChild(button);
        
        UIButton* titleButton = UIButton::create();
        titleButton->setTouchEnabled(true);
        titleButton->loadTextures("cocosgui/backtotopnormal.png", "cocosgui/backtotoppressed.png", "");
        titleButton->setTitleText("Title Button");
        titleButton->setPosition(ccp(button->getRightInParent() + button->getSize().width / 2,
                                    button->getBottomInParent() - button->getSize().height / 2));
        scrollView->addChild(titleButton);
        
        UIButton* button_scale9 = UIButton::create();
        button_scale9->setTouchEnabled(true);
        button_scale9->setScale9Enabled(true);
        button_scale9->loadTextures("cocosgui/button.png", "cocosgui/buttonHighlighted.png", "");
        button_scale9->setSize(CCSizeMake(100, button_scale9->getContentSize().height));
        button_scale9->setPosition(ccp(titleButton->getRightInParent() + titleButton->getSize().width / 2,
                                       titleButton->getBottomInParent() - titleButton->getSize().height / 2));
        scrollView->addChild(button_scale9);                
                
        imageView->setPosition(ccp(innerWidth - imageView->getSize().width / 2,
                                   button_scale9->getBottomInParent() - button_scale9->getSize().height / 2));
        scrollView->addChild(imageView);                
        
        return true;
    }
    
    return false;
}
bool UIListViewExTest_Horizontal::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        m_pDisplayValueLabel = UILabel::create();
        m_pDisplayValueLabel->setText("Move by horizontal direction");
        m_pDisplayValueLabel->setFontName("Marker Felt");
        m_pDisplayValueLabel->setFontSize(32);
        m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1));
        m_pDisplayValueLabel->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f + m_pDisplayValueLabel->getContentSize().height * 1.5));
        m_pUiLayer->addWidget(m_pDisplayValueLabel);
        
        
        UILabel* alert = UILabel::create();
        alert->setText("ListView horizontal");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075));
        m_pUiLayer->addWidget(alert);
        
        Layout* background = dynamic_cast<Layout*>(m_pUiLayer->getWidgetByName("background_Panel"));
        CCSize backgroundSize = background->getContentSize();
        
        
        // create list view data
        m_array = CCArray::create();
        CC_SAFE_RETAIN(m_array);
        for (int i = 0; i < 20; ++i)
        {
            CCString* ccstr = CCString::createWithFormat("listview_item_%d", i);
            m_array->addObject(ccstr);
        }
        
        
        // Create the list view
        UIListView* listView = UIListView::create();
        // set list view direction
        listView->setDirection(SCROLLVIEW_DIR_HORIZONTAL);
        listView->setTouchEnabled(true);
        listView->setBounceEnabled(true);
        listView->setBackGroundImage("cocosgui/green_edit.png");
        listView->setBackGroundImageScale9Enabled(true);
        listView->setSize(CCSizeMake(240, 130));
        listView->setPosition(ccp((widgetSize.width - backgroundSize.width) / 2 +
                                    (backgroundSize.width - listView->getSize().width) / 2,
                                    (widgetSize.height - backgroundSize.height) / 2 +
                                    (backgroundSize.height - listView->getSize().height) / 2));
        listView->addEventListenerListView(this, listvieweventselector(UIListViewExTest_Horizontal::selectedItemEvent));
        m_pUiLayer->addWidget(listView);
        
        
        // create model
        UIButton* default_button = UIButton::create();
        default_button->setName("TextButton");
        default_button->setTouchEnabled(true);
        default_button->loadTextures("cocosgui/backtotoppressed.png", "cocosgui/backtotopnormal.png", "");
        
        Layout* default_item = Layout::create();
        default_item->setTouchEnabled(true);
        default_item->setSize(default_button->getSize());
        default_button->setPosition(ccp(default_item->getSize().width / 2, default_item->getSize().height / 2));
        default_item->addChild(default_button);
        
        // set model
        listView->setItemModel(default_item);
        
        // add default item
        int count = m_array->count();
        for (int i = 0; i < count / 4; ++i)
        {
            listView->pushBackDefaultItem();
        }
        // insert default item
        for (int i = 0; i < count / 4; ++i)
        {
            listView->insertDefaultItem(0);
        }
        
        // add custom item
        for (int i = 0; i < count / 4; ++i)
        {
            UIButton* custom_button = UIButton::create();
            custom_button->setName("TextButton");
            custom_button->setTouchEnabled(true);
            custom_button->loadTextures("cocosgui/button.png", "cocosgui/buttonHighlighted.png", "");
            custom_button->setScale9Enabled(true);
            custom_button->setSize(default_button->getSize());
            
            Layout *custom_item = Layout::create();
            custom_item->setSize(custom_button->getSize());
            custom_button->setPosition(ccp(custom_item->getSize().width / 2, custom_item->getSize().height / 2));
            custom_item->addChild(custom_button);
            
            listView->pushBackCustomItem(custom_item);
        }
        // insert custom item
        CCArray *items = listView->getItems();
        int items_count = items->count();
        for (int i = 0; i < count / 4; ++i)
        {
            UIButton* custom_button = UIButton::create();
            custom_button->setName("TextButton");
            custom_button->setTouchEnabled(true);
            custom_button->loadTextures("cocosgui/button.png", "cocosgui/buttonHighlighted.png", "");
            custom_button->setScale9Enabled(true);
            custom_button->setSize(default_button->getSize());
            
            Layout *custom_item = Layout::create();
            custom_item->setSize(custom_button->getSize());
            custom_button->setPosition(ccp(custom_item->getSize().width / 2, custom_item->getSize().height / 2));
            custom_item->addChild(custom_button);
            
            listView->insertCustomItem(custom_item, items_count);
        }
        
        // set item data
        items_count = items->count();
        for (int i = 0; i < items_count; ++i)
        {
            UIWidget *item = listView->getItem(i);
            UIButton *button = static_cast<UIButton*>(item->getChildByName("TextButton"));
            int index = listView->getIndex(item);
            button->setTitleText(static_cast<CCString*>(m_array->objectAtIndex(index))->getCString());
        }
        
        // remove last item
        listView->removeLastItem();
        
        // remove item by index
        items_count = items->count();
        listView->removeItem(items_count - 1);        
        
        // set all items layout gravity
        listView->setGravity(LISTVIEW_GRAVITY_CENTER_VERTICAL);
        
        // set items margin
        listView->setItemsMargin(2);
        
        return true;
    }
    
    return false;
}
Esempio n. 24
0
bool UILayoutTest_Layout_Relative_Align_Parent::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add the alert
        UILabel* alert = UILabel::create();
        alert->setText("Layout Relative Align Parent");
        alert->setFontName("Marker Felt");
        alert->setFontSize(20);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5));
        m_pUiLayer->addWidget(alert);
        
        Layout* background = dynamic_cast<Layout*>(m_pUiLayer->getWidgetByName("background_Panel"));
        
        // Create the layout
        Layout* layout = Layout::create();
        layout->setLayoutType(LAYOUT_RELATIVE);
        layout->setSize(CCSizeMake(280, 150));
        layout->setBackGroundColorType(LAYOUT_COLOR_SOLID);
        layout->setBackGroundColor(ccGREEN);
        CCSize backgroundSize = background->getSize();
        layout->setPosition(ccp((widgetSize.width - backgroundSize.width) / 2 +
                                (backgroundSize.width - layout->getSize().width) / 2,
                                (widgetSize.height - backgroundSize.height) / 2 +
                                (backgroundSize.height - layout->getSize().height) / 2));
        m_pUiLayer->addWidget(layout);
        
        // top left
        UIButton* button_TopLeft = UIButton::create();
        button_TopLeft->setTouchEnabled(true);
        button_TopLeft->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
        layout->addChild(button_TopLeft);
        
        UIRelativeLayoutParameter* rp_TopLeft = UIRelativeLayoutParameter::create();
        rp_TopLeft->setAlign(RELATIVE_ALIGN_PARENT_TOP_LEFT);
        button_TopLeft->setLayoutParameter(rp_TopLeft);
        
        
        // top center horizontal
        UIButton* button_TopCenter = UIButton::create();
        button_TopCenter->setTouchEnabled(true);
        button_TopCenter->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
        layout->addChild(button_TopCenter);
        
        UIRelativeLayoutParameter* rp_TopCenter = UIRelativeLayoutParameter::create();
        rp_TopCenter->setAlign(RELATIVE_ALIGN_PARENT_TOP_CENTER_HORIZONTAL);
        button_TopCenter->setLayoutParameter(rp_TopCenter);
        
        
        // top right
        UIButton* button_TopRight = UIButton::create();
        button_TopRight->setTouchEnabled(true);
        button_TopRight->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
        layout->addChild(button_TopRight);
        
        UIRelativeLayoutParameter* rp_TopRight = UIRelativeLayoutParameter::create();
        rp_TopRight->setAlign(RELATIVE_ALIGN_PARENT_TOP_RIGHT);
        button_TopRight->setLayoutParameter(rp_TopRight);
        
        
        // left center
        UIButton* button_LeftCenter = UIButton::create();
        button_LeftCenter->setTouchEnabled(true);
        button_LeftCenter->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
        layout->addChild(button_LeftCenter);
        
        UIRelativeLayoutParameter* rp_LeftCenter = UIRelativeLayoutParameter::create();
        rp_LeftCenter->setAlign(RELATIVE_ALIGN_PARENT_LEFT_CENTER_VERTICAL);
        button_LeftCenter->setLayoutParameter(rp_LeftCenter);
        
        
        // center
        UIButton* buttonCenter = UIButton::create();
        buttonCenter->setTouchEnabled(true);
        buttonCenter->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
        layout->addChild(buttonCenter);
        
        UIRelativeLayoutParameter* rpCenter = UIRelativeLayoutParameter::create();
        rpCenter->setAlign(RELATIVE_CENTER_IN_PARENT);
        buttonCenter->setLayoutParameter(rpCenter);
        
        
        // right center
        UIButton* button_RightCenter = UIButton::create();
        button_RightCenter->setTouchEnabled(true);
        button_RightCenter->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
        layout->addChild(button_RightCenter);
        
        UIRelativeLayoutParameter* rp_RightCenter = UIRelativeLayoutParameter::create();
        rp_RightCenter->setAlign(RELATIVE_ALIGN_PARENT_RIGHT_CENTER_VERTICAL);
        button_RightCenter->setLayoutParameter(rp_RightCenter);
        
        
        // left bottom
        UIButton* button_LeftBottom = UIButton::create();
        button_LeftBottom->setTouchEnabled(true);
        button_LeftBottom->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
        layout->addChild(button_LeftBottom);
        
        UIRelativeLayoutParameter* rp_LeftBottom = UIRelativeLayoutParameter::create();
        rp_LeftBottom->setAlign(RELATIVE_ALIGN_PARENT_LEFT_BOTTOM);
        button_LeftBottom->setLayoutParameter(rp_LeftBottom);
        
        
        // bottom center
        UIButton* button_BottomCenter = UIButton::create();
        button_BottomCenter->setTouchEnabled(true);
        button_BottomCenter->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
        layout->addChild(button_BottomCenter);
        
        UIRelativeLayoutParameter* rp_BottomCenter = UIRelativeLayoutParameter::create();
        rp_BottomCenter->setAlign(RELATIVE_ALIGN_PARENT_BOTTOM_CENTER_HORIZONTAL);
        button_BottomCenter->setLayoutParameter(rp_BottomCenter);
        
        
        // right bottom
        UIButton* button_RightBottom = UIButton::create();
        button_RightBottom->setTouchEnabled(true);
        button_RightBottom->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
        layout->addChild(button_RightBottom);
        
        UIRelativeLayoutParameter* rp_RightBottom = UIRelativeLayoutParameter::create();
        rp_RightBottom->setAlign(RELATIVE_ALIGN_PARENT_RIGHT_BOTTOM);
        button_RightBottom->setLayoutParameter(rp_RightBottom);
        
        return true;
    }
    
    return false;
}
Esempio n. 25
0
bool UILayoutTest_Layout_Relative_Location::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add the alert
        UILabel* alert = UILabel::create();
        alert->setText("Layout Relative Location");
        alert->setFontName("Marker Felt");
        alert->setFontSize(20);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5));
        m_pUiLayer->addWidget(alert);
        
        Layout* background = dynamic_cast<Layout*>(m_pUiLayer->getWidgetByName("background_Panel"));
        
        // Create the layout
        Layout* layout = Layout::create();
        layout->setLayoutType(LAYOUT_RELATIVE);
        layout->setSize(CCSizeMake(280, 150));
        CCSize backgroundSize = background->getSize();
        layout->setPosition(ccp((widgetSize.width - backgroundSize.width) / 2 +
                                (backgroundSize.width - layout->getSize().width) / 2,
                                (widgetSize.height - backgroundSize.height) / 2 +
                                (backgroundSize.height - layout->getSize().height) / 2));
        m_pUiLayer->addWidget(layout);
        
        // center
        UIImageView* imageView_Center = UIImageView::create();
        imageView_Center->loadTexture("cocosui/scrollviewbg.png");
        layout->addChild(imageView_Center);
        
        UIRelativeLayoutParameter* rp_Center = UIRelativeLayoutParameter::create();
        rp_Center->setRelativeName("rp_Center");
        rp_Center->setAlign(RELATIVE_CENTER_IN_PARENT);
        imageView_Center->setLayoutParameter(rp_Center);
        
        
        // above center
        UIImageView* imageView_AboveCenter = UIImageView::create();
        imageView_AboveCenter->loadTexture("cocosui/switch-mask.png");
        layout->addChild(imageView_AboveCenter);
        
        UIRelativeLayoutParameter* rp_AboveCenter = UIRelativeLayoutParameter::create();
        rp_AboveCenter->setRelativeToWidgetName("rp_Center");
        rp_AboveCenter->setAlign(RELATIVE_LOCATION_ABOVE_CENTER);
        imageView_AboveCenter->setLayoutParameter(rp_AboveCenter);
        
        
        // below center
        UIImageView* imageView_BelowCenter = UIImageView::create();
        imageView_BelowCenter->loadTexture("cocosui/switch-mask.png");
        layout->addChild(imageView_BelowCenter);
        
        UIRelativeLayoutParameter* rp_BelowCenter = UIRelativeLayoutParameter::create();
        rp_BelowCenter->setRelativeToWidgetName("rp_Center");
        rp_BelowCenter->setAlign(RELATIVE_LOCATION_BELOW_CENTER);
        imageView_BelowCenter->setLayoutParameter(rp_BelowCenter);
        
        
        // left center
        UIImageView* imageView_LeftCenter = UIImageView::create();
        imageView_LeftCenter->loadTexture("cocosui/switch-mask.png");
        layout->addChild(imageView_LeftCenter);
        
        UIRelativeLayoutParameter* rp_LeftCenter = UIRelativeLayoutParameter::create();
        rp_LeftCenter->setRelativeToWidgetName("rp_Center");
        rp_LeftCenter->setAlign(RELATIVE_LOCATION_LEFT_OF_CENTER);
        imageView_LeftCenter->setLayoutParameter(rp_LeftCenter);
        
        
        
        // right center
        UIImageView* imageView_RightCenter = UIImageView::create();
        imageView_RightCenter->loadTexture("cocosui/switch-mask.png");
        layout->addChild(imageView_RightCenter);
        
        UIRelativeLayoutParameter* rp_RightCenter = UIRelativeLayoutParameter::create();
        rp_RightCenter->setRelativeToWidgetName("rp_Center");
        rp_RightCenter->setAlign(RELATIVE_LOCATION_RIGHT_OF_CENTER);
        imageView_RightCenter->setLayoutParameter(rp_RightCenter);
        
        return true;
    }
    
    return false;
}
bool UIPanelTest_Color::init()
{
    if (UIScene::init())
    {
        CCSize screenSize = CCDirector::sharedDirector()->getWinSize();        
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("Panel color render");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getRect().size.height * 2.925));
        m_pUiLayer->addWidget(alert);
        
        UIPanel *background = dynamic_cast<UIPanel*>(m_pUiLayer->getWidgetByName("background_Panel"));
        
        // Create the panel with color render
        UIPanel* panel = UIPanel::create();
        panel->setBackGroundColorType(PANEL_COLOR_SOLID);
        panel->setBackGroundColor(ccc3(128, 128, 128));
        panel->setClippingEnable(true);
        panel->setSize(CCSizeMake(280, 150));
        CCSize backgroundSize = background->getContentSize();
        panel->setPosition(ccp((screenSize.width - backgroundSize.width) / 2 +
                               (backgroundSize.width - panel->getRect().size.width) / 2,
                               (screenSize.height - backgroundSize.height) / 2 +
                               (backgroundSize.height - panel->getRect().size.height) / 2));
        m_pUiLayer->addWidget(panel);
        
        UIButton* button = UIButton::create();
        button->setTouchEnable(true);
        button->setTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", "");
        button->setPosition(ccp(button->getRect().size.width / 2, panel->getRect().size.height - button->getRect().size.height / 2));
        panel->addChild(button);
        
        UITextButton* textButton = UITextButton::create();
        textButton->setTouchEnable(true);
        textButton->setTextures("cocosgui/backtotopnormal.png", "cocosgui/backtotoppressed.png", "");
        textButton->setText("Text Button");
        textButton->setPosition(ccp(panel->getRect().size.width / 2, panel->getRect().size.height / 2));
        panel->addChild(textButton);
        
        UIZoomButton* zoomButton = UIZoomButton::create();
        zoomButton->setTouchEnable(true);
        zoomButton->setTextures("cocosgui/button.png", "cocosgui/buttonHighlighted.png", "cocosgui/button.png");
        zoomButton->setTitle("ControlButton", "ControlButton", "ControlButton");
        zoomButton->setNormalFontSize(16);
        zoomButton->setNormalFontName("Marker Felt");
        zoomButton->setPressedFontSize(16);
        zoomButton->setPressedFontName("Marker Felt");
        zoomButton->setDisabledFontSize(16);
        zoomButton->setDisabledFontName("Marker Felt");
        zoomButton->setPreferredSize(CCSizeMake(100, zoomButton->getContentSize().height * 2.0f));
        zoomButton->setPosition(ccp(panel->getRect().size.width - zoomButton->getRect().size.width / 2,
                                       zoomButton->getRect().size.height / 2));
        panel->addChild(zoomButton);
        
        return true;
    }
    return false;
}
Esempio n. 27
0
bool UILayoutTest_Layout_Linear_Horizontal::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add the alert
        UILabel* alert = UILabel::create();
        alert->setText("Layout Layout Linear Horizontal");
        alert->setFontName("Marker Felt");
        alert->setFontSize(20);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5));
        m_pUiLayer->addWidget(alert);
        
        Layout* background = dynamic_cast<Layout*>(m_pUiLayer->getWidgetByName("background_Panel"));
        
        // Create the layout
        Layout* layout = Layout::create();
        layout->setLayoutType(LAYOUT_LINEAR_HORIZONTAL);
        layout->setClippingEnabled(true);
        layout->setSize(CCSizeMake(280, 150));
        CCSize backgroundSize = background->getSize();
        layout->setPosition(ccp((widgetSize.width - backgroundSize.width) / 2 +
                                (backgroundSize.width - layout->getSize().width) / 2,
                                (widgetSize.height - backgroundSize.height) / 2 +
                                (backgroundSize.height - layout->getSize().height) / 2));
        m_pUiLayer->addWidget(layout);
        
        UIButton* button = UIButton::create();
        button->setTouchEnabled(true);
        button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
        layout->addChild(button);
        
        UILinearLayoutParameter* lp1 = UILinearLayoutParameter::create();
        button->setLayoutParameter(lp1);
        lp1->setGravity(LINEAR_GRAVITY_CENTER_VERTICAL);
        lp1->setMargin(UIMargin(0, 10, 0, 10));
        
        
        UIButton* titleButton = UIButton::create();
        titleButton->setTouchEnabled(true);
        titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", "");
        titleButton->setTitleText("Title Button");
        layout->addChild(titleButton);
        
        UILinearLayoutParameter* lp2 = UILinearLayoutParameter::create();
        titleButton->setLayoutParameter(lp2);
        lp2->setGravity(LINEAR_GRAVITY_CENTER_VERTICAL);
        lp2->setMargin(UIMargin(0, 10, 0, 10));
        
        
        UIButton* button_scale9 = UIButton::create();
        button_scale9->setTouchEnabled(true);
        button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "");
        button_scale9->setScale9Enabled(true);
        button_scale9->setSize(CCSizeMake(100, button_scale9->getContentSize().height));
        layout->addChild(button_scale9);
        
        UILinearLayoutParameter* lp3 = UILinearLayoutParameter::create();
        button_scale9->setLayoutParameter(lp3);
        lp3->setGravity(LINEAR_GRAVITY_CENTER_VERTICAL);
        lp3->setMargin(UIMargin(0, 10, 0, 10));
        
        return true;
    }
    
    return false;
}