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; }
bool UIPageViewTest::init() { if (UIScene::init()) { CCSize screenSize = CCDirector::sharedDirector()->getWinSize(); // 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(screenSize.width / 2.0f, screenSize.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(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 page view UIPageView* pageView = UIPageView::create(); pageView->setTouchEnable(true); pageView->setSize(CCSizeMake(240, 130)); CCSize backgroundSize = background->getContentSize(); pageView->setPosition(ccp((screenSize.width - backgroundSize.width) / 2 + (backgroundSize.width - pageView->getRect().size.width) / 2, (screenSize.height - backgroundSize.height) / 2 + (backgroundSize.height - pageView->getRect().size.height) / 2)); for (int i = 0; i < 3; ++i) { UIPanel* panel = UIPanel::create(); panel->setSize(CCSizeMake(240, 130)); UIImageView* imageView = UIImageView::create(); imageView->setTouchEnable(true); imageView->setScale9Enable(true); imageView->setTexture("cocosgui/scrollviewbg.png"); imageView->setScale9Size(CCSizeMake(240, 130)); imageView->setPosition(ccp(panel->getRect().size.width / 2, panel->getRect().size.height / 2)); panel->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(panel->getRect().size.width / 2, panel->getRect().size.height / 2)); panel->addChild(label); pageView->addPage(panel); } m_pUiLayer->addWidget(pageView); return true; } return false; }