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; }
void SelectMenuView::noticeShowLock(int beautyIndex, int needHeart) { _panelUnlock->setVisible(true); _panelUnlock->setTouchEnabled(true); // setting head UIImageView* head = (UIImageView*)_panelUnlock->getChildByName("panelLock_head"); char tmp[32]; sprintf(tmp,"head_%d.png",beautyIndex); head->loadTexture(tmp,UI_TEX_TYPE_PLIST); // setting heart number for(int i=0; i<MAX_HEART; i++) { sprintf(tmp,"panelLock_heart_%d",i+1); if(i<needHeart) { _panelUnlock->getChildByName(tmp)->setVisible(true); } else { _panelUnlock->getChildByName(tmp)->setVisible(false); } } // setting beauty name UILabelBMFont* labelName = (UILabelBMFont*) _panelUnlock->getChildByName("panelLock_txt_name"); labelName->setText(BeautyStaticData::getInstance()->getName(beautyIndex)); // setting unlock price UILabelBMFont* labelPrice = (UILabelBMFont*) _panelUnlock->getChildByName("panelLock_txt_price"); sprintf(tmp,"$%d",BeautyStaticData::getInstance()->getRequiement(beautyIndex+1)); labelPrice->setText(tmp); // animation UIWidget* bg = _panelUnlock->getChildByName("panelLock_bg"); bg->setScale(0.1f); bg->runAction(CCScaleTo::create(0.3f,1)); UIButton* button = (UIButton*)_panelUnlock->getChildByName("panelLock_btn_back"); button->setTouchEnabled(true); button->setPressedActionEnabled(true); button->addTouchEventListener(this,toucheventselector(SelectMenuView::onTouchUnlock)); button = (UIButton*)_panelUnlock->getChildByName("panelLock_btn_unlock"); button->setTouchEnabled(true); button->setPressedActionEnabled(true); button->addTouchEventListener(this,toucheventselector(SelectMenuView::onTouchUnlock)); this->addWidget(_panelUnlock); }
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 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; }
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 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; }
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; }