EditorGridSettingsWindow::EditorGridSettingsWindow(EditorGrid *grid) : UIWindow("Grid Settings", 100, 190) { visible = false; enabled = false; this->grid = grid; visibleCheck = new UICheckBox("Enabled", grid->visible); addChild(visibleCheck); visibleCheck->setPosition(10, 40); visibleCheck->addEventListener(this, UIEvent::CHANGE_EVENT); UILabel *label = new UILabel("Size:", 12); label->setColor(1.0, 1.0 ,1.0, 1.0); addChild(label); label->setPosition(10, 70); sizeInput = new UITextInput(false, 50, 10); addChild(sizeInput); sizeInput->setPosition(60, 68); sizeInput->setNumberOnly(true); sizeInput->setText(String::NumberToString(grid->getGridSize())); sizeInput->addEventListener(this, UIEvent::CHANGE_EVENT); label = new UILabel("Count:", 12); label->setColor(1.0, 1.0 ,1.0, 1.0); addChild(label); label->setPosition(10, 100); countInput = new UITextInput(false, 50, 10); addChild(countInput); countInput->setPosition(60, 98); countInput->setNumberOnly(true); countInput->setText(String::IntToString(grid->getGridLen())); countInput->addEventListener(this, UIEvent::CHANGE_EVENT); xAxisBox = new UICheckBox("X Axis", grid->isXAxisEnabled()); addChild(xAxisBox); xAxisBox->setPosition(10, 130); xAxisBox->addEventListener(this, UIEvent::CHANGE_EVENT); yAxisBox = new UICheckBox("Y Axis", grid->isYAxisEnabled()); addChild(yAxisBox); yAxisBox->setPosition(10, 155); yAxisBox->addEventListener(this, UIEvent::CHANGE_EVENT); zAxisBox = new UICheckBox("Z Axis", grid->isZAxisEnabled()); addChild(zAxisBox); zAxisBox->setPosition(10, 180); zAxisBox->addEventListener(this, UIEvent::CHANGE_EVENT); }
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 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::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 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; }
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); }
PolycodeProjectBrowser::PolycodeProjectBrowser(PolycodeProject *project) : UIElement() { this->project = project; headerBg = new UIRect(10,10); addChild(headerBg); headerBg->setAnchorPoint(-1.0, -1.0, 0.0); headerBg->color.setColorHexFromString(CoreServices::getInstance()->getConfig()->getStringValue("Polycode", "uiHeaderBgColor")); UILabel *label = new UILabel("PROJECT BROWSER", 18, "section", Label::ANTIALIAS_FULL); label->color.setColorHexFromString(CoreServices::getInstance()->getConfig()->getStringValue("Polycode", "uiHeaderFontColor")); addChild(label); label->setPosition(10, 3); treeContainer = new UITreeContainer("boxIcon.png", project->getProjectName(), 200, 555); treeContainer->getRootNode()->toggleCollapsed(); treeContainer->getRootNode()->addEventListener(this, UITreeEvent::SELECTED_EVENT); treeContainer->addEventListener(this, InputEvent::EVENT_MOUSEDOWN); treeContainer->setPosition(0, 30); BrowserUserData *data = new BrowserUserData(); data->type = 0; data->parentProject = project; treeContainer->getRootNode()->setUserData((void*) data) ; addChild(treeContainer); selectedData = NULL; parseFolderIntoNode(treeContainer->getRootNode(), project->getRootFolder()); }
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; }
/*===*/ 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; }
FindBar::FindBar() : UIElement() { barBg = new UIRect(30,30); barBg->setAnchorPoint(-1.0, -1.0, 0.0); barBg->color.setColorHexFromString(CoreServices::getInstance()->getConfig()->getStringValue("Polycode", "uiHeaderBgColor")); addChild(barBg); setHeight(30); UILabel *findLabel = new UILabel("FIND", 18, "section"); addChild(findLabel); findLabel->setColor(1.0, 1.0, 1.0, 0.6); findLabel->setPosition(10,3); UILabel *replaceLabel = new UILabel("REPLACE", 18, "section"); addChild(replaceLabel); replaceLabel->setColor(1.0, 1.0, 1.0, 0.6); replaceLabel->setPosition(200,3); processInputEvents = true; findInput = new UITextInput(false, 120, 12); addFocusChild(findInput); findInput->setPosition(60, 4); replaceInput = new UITextInput(false, 120, 12); addFocusChild(replaceInput); replaceInput->setPosition(280, 4); replaceAllButton = new UIButton("Replace All", 100); addFocusChild(replaceAllButton); replaceAllButton->setPosition(420, 3); UIImage *functionIcon = new UIImage("main/function_icon.png", 11, 17); addChild(functionIcon); functionIcon->setPosition(540, 6); functionList = new UIComboBox(globalMenu, 200); addChild(functionList); functionList->setPosition(560, 4); closeButton = new UIImageButton("main/barClose.png", 1.0, 17, 17); addChild(closeButton); }
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; }
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; }
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; }
void UIMenu::addMenuBreak() { UILabel* label = new UILabel(gfx); label->setColor(MENU_TEXT_COLOR); label->setText("...", 0, text_size); label->setPosition(vector2()); label->setActive(false); // label->fadeIn(); //size[0] = 18; size[1] = (labels_n+1)*text_size; gfx->addSceneNode(label, this); labels.push_back(label); labels_n++; }
void UIMenu::addMenuOption(const char* text, bool isSelected) { UILabel* label = new UILabel(gfx); if(isSelected) label->setColor(MENU_TEXT_COLOR_SELECTED); else label->setColor(MENU_TEXT_COLOR); label->setText(text, text_font, text_size); label->setPosition(vector2()); label->setActive(false); // label->fadeIn(); float minMenuSizeX = strlen(text)*(text_size-text_size/2); if(minMenuSizeX > size[0]) size[0] = minMenuSizeX; size[1] = (labels_n+1)*text_size; gfx->addSceneNode(label, this); labels.push_back(label); labels_n++; }
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; }
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; }
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; }
bool UIScene::init() { if (CCLayer::init()) { m_pUiLayer = UILayer::create(); addChild(m_pUiLayer); m_pWidget = dynamic_cast<Layout*>(CCUIHELPER->createWidgetFromJsonFile("cocosgui/UITest/UITest.json")); m_pUiLayer->addWidget(m_pWidget); m_pSceneTitle = dynamic_cast<UILabel*>(m_pUiLayer->getWidgetByName("UItest")); UILabel *back_label = dynamic_cast<UILabel*>(m_pUiLayer->getWidgetByName("back")); back_label->setVisible(false); // back_label->addReleaseEvent(this, coco_releaseselector(UIScene::toExtensionsMainLayer)); UIButton *left_button = dynamic_cast<UIButton*>(m_pUiLayer->getWidgetByName("left_Button")); left_button->addTouchEventListener(this, toucheventselector(UIScene::previousCallback)); UIButton *middle_button = dynamic_cast<UIButton*>(m_pUiLayer->getWidgetByName("middle_Button")); middle_button->addTouchEventListener(this, toucheventselector(UIScene::restartCallback)); UIButton *right_button = dynamic_cast<UIButton*>(m_pUiLayer->getWidgetByName("right_Button")); right_button->addTouchEventListener(this, toucheventselector(UIScene::nextCallback)); UILabel* mainMenuLabel = UILabel::create(); mainMenuLabel->setText("MainMenu"); mainMenuLabel->setFontSize(20); mainMenuLabel->setTouchScaleChangeEnabled(true); mainMenuLabel->setPosition(Point(430,30)); mainMenuLabel->setTouchEnabled(true); mainMenuLabel->addTouchEventListener(this, toucheventselector(UIScene::menuCloseCallback)); m_pUiLayer->addWidget(mainMenuLabel); return true; } return false; }
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; }
UIColorPicker::UIColorPicker() : UIWindow(L"", 300, 240) { closeOnEscape = true; continuous = true; // topPadding Config *conf = CoreServices::getInstance()->getConfig(); Number uiScale = conf->getNumericValue("Polycode", "uiScale"); String fontName = conf->getStringValue("Polycode", "uiDefaultFontName"); int fontSize = conf->getNumericValue("Polycode", "uiDefaultFontSize"); String mainBgImage = conf->getStringValue("Polycode", "uiColorPickerMainBg"); String mainFrameImage = conf->getStringValue("Polycode", "uiColorPickerMainFrame"); String hueFrameImage = conf->getStringValue("Polycode", "uiColorPickerHueFrame"); String hueSelectorImage = conf->getStringValue("Polycode", "uiColorPickerHueSelector"); String mainSelectorImage = conf->getStringValue("Polycode", "uiColorPickerMainSelector"); mainBg = new UIImage(mainBgImage, 187, 187); mainBg->setPosition(padding, topPadding+padding); addChild(mainBg); mainFrame = new UIImage(mainFrameImage, 187, 187); mainFrame->setPosition(padding, topPadding+padding); alphaSlider = new UIHSlider(0, 1.0, mainFrame->getWidth()); alphaSlider->setPosition(padding, mainFrame->getHeight() + mainFrame->getPosition().y + 13); addChild(alphaSlider); alphaSlider->addEventListener(this, UIEvent::CHANGE_EVENT); mainColorRect = new SceneMesh(Mesh::QUAD_MESH); mainColorRect->setBlendingMode(Renderer::BLEND_MODE_NORMAL); mainColorRect->setWidth(mainFrame->getWidth()); mainColorRect->setHeight(mainFrame->getWidth()); mainColorRect->setDepth(0.001); mainColorRect->getMesh()->addVertex(-mainFrame->getWidth()/2,mainFrame->getHeight()/2.0,0,0,0); mainColorRect->getMesh()->addVertex(mainFrame->getWidth()/2,mainFrame->getHeight()/2.0,0, 1, 0); mainColorRect->getMesh()->addVertex(mainFrame->getWidth()/2,-mainFrame->getHeight()/2.0,0, 1, 1); mainColorRect->getMesh()->addVertex(-mainFrame->getWidth()/2,-mainFrame->getHeight()/2.0,0,0,1); mainColorRect->getMesh()->dirtyArrays(); mainColorRect->backfaceCulled = false; mainColorRect->setAnchorPoint(-1.0, -1.0, 0.0); mainColorRect->setPosition(padding, topPadding+padding); addChild(mainColorRect); addChild(mainFrame); hueFrame = new UIImage(hueFrameImage, 20, 187); hueFrame->setPosition(mainFrame->getPosition().x + mainFrame->getWidth()+10, topPadding+padding); addChild(hueFrame); hueSelector = new UIImage(hueSelectorImage); hueSelector->Resize(hueSelector->getWidth() / uiScale, hueSelector->getHeight() / uiScale); hueSelector->setAnchorPoint(0.0, 0.0, 0.0); hueSelector->setPosition(hueFrame->getPosition().x + (hueFrame->getWidth()/2.0), hueFrame->getPosition().y); addChild(hueSelector); hueSelector->setDragLimits(Polycode::Rectangle(hueSelector->getPosition().x,hueSelector->getPosition().y,0,hueFrame->getHeight())); mainSelector = new UIImage(mainSelectorImage); mainSelector->Resize(mainSelector->getWidth() / uiScale, mainSelector->getHeight() / uiScale); mainSelector->setAnchorPoint(0.0, 0.0, 0.0); mainSelector->setPosition(mainFrame->getPosition()); addChild(mainSelector); mainColorRect->getMesh()->useVertexColors = true; mainColorRect->addEventListener(this, InputEvent::EVENT_MOUSEDOWN); mainColorRect->addEventListener(this, InputEvent::EVENT_MOUSEUP); mainColorRect->addEventListener(this, InputEvent::EVENT_MOUSEUP_OUTSIDE); mainColorRect->processInputEvents = true; hueFrame->addEventListener(this, InputEvent::EVENT_MOUSEDOWN); hueFrame->addEventListener(this, InputEvent::EVENT_MOUSEUP); hueFrame->addEventListener(this, InputEvent::EVENT_MOUSEUP_OUTSIDE); hueFrame->processInputEvents = true; UILabel *label = new UILabel(L"R:", fontSize, fontName); label->setPosition(hueFrame->getPosition().x+hueFrame->getWidth() + 15, topPadding+padding + 3); addChild(label); junkLabels.push_back(label); rTextInput = new UITextInput(false, 40, 12); rTextInput->setPosition(hueFrame->getPosition().x+hueFrame->getWidth() + 30, topPadding+padding); addChild(rTextInput); rTextInput->addEventListener(this, UIEvent::CHANGE_EVENT); label = new UILabel(L"G:", fontSize, fontName); label->setPosition(hueFrame->getPosition().x+hueFrame->getWidth() + 15, topPadding+padding + 33); addChild(label); junkLabels.push_back(label); gTextInput = new UITextInput(false, 40, 12); gTextInput->setPosition(hueFrame->getPosition().x+hueFrame->getWidth() + 30, topPadding+padding + 30); addChild(gTextInput); gTextInput->addEventListener(this, UIEvent::CHANGE_EVENT); label = new UILabel(L"B:", fontSize, fontName); label->setPosition(hueFrame->getPosition().x+hueFrame->getWidth() + 15, topPadding+padding + 63); addChild(label); junkLabels.push_back(label); bTextInput = new UITextInput(false, 40, 12); bTextInput->setPosition(hueFrame->getPosition().x+hueFrame->getWidth() + 30, topPadding+padding + 60); addChild(bTextInput); bTextInput->addEventListener(this, UIEvent::CHANGE_EVENT); label = new UILabel(L"A:", fontSize, fontName); label->setPosition(hueFrame->getPosition().x+hueFrame->getWidth() + 15, topPadding+padding + 93); addChild(label); junkLabels.push_back(label); aTextInput = new UITextInput(false, 40, 12); aTextInput->setPosition(hueFrame->getPosition().x+hueFrame->getWidth() + 30, topPadding+padding + 90); addChild(aTextInput); aTextInput->addEventListener(this, UIEvent::CHANGE_EVENT); setHue(0.0); setSaturationAndValue(0.0, 0.0); rTextInput->setNumberOnly(true); gTextInput->setNumberOnly(true); bTextInput->setNumberOnly(true); aTextInput->setNumberOnly(true); lastHueSelectorPosition = 0; mainSelector->setDragLimits(Polycode::Rectangle(mainColorRect->getPosition().x,mainColorRect->getPosition().y,mainColorRect->getWidth(), mainColorRect->getHeight())); colorAlpha = 1.0; visible = false; enabled = false; suppressTextChangeEvent = false; }
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 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; }
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; }
void Game::startIntroCutscene() { gfx->recomputeBackground(); gfx->getUI()->darkenScreen(1.f); if(introCutscene) gfx->deleteSceneNode(introCutscene); introCutscene = new UICutscene(gfx); vector2 wparams = gfx->getRenderer()->getWindowParams(); vector2 center = wparams*0.5f; /*** FRAME 0 ***/ introCutscene->startFrame(3.f); UILabel* text = new UILabel(gfx); text->setColor(color(0.7f, 0.7f, 0.7f, 0.f)); text->setText("powered by", 0, 32.f); text->setPosition(center+vector2(-150.f, 100.f)); // text->fadeOut(); UIImage* gllogo = new UIImage(gfx); gllogo->setImage("LOGOS"); gllogo->setPosition(vector2(center[0]-100.f, center[1]-gllogo->getSize()[1]+100.f)); // gllogo->fadeOut(); introCutscene->addWidgetToFrame(text); introCutscene->addWidgetToFrame(gllogo); introCutscene->endFrame(); /*** FRAME 1 ***/ introCutscene->startFrame(6.f); text = new UILabel(gfx); text->setColor(color(0.7f, 0.7f, 0.7f, 0.f)); // text->setText("Copyright 2010 Alexander Dzhoganov", 0, 32.f); text->setText(GNU_COPYRIGHT_NOTICE, 0, 20.f); text->setPosition(vector2(center[0]-400.f, center[1])); text->fadeOut(); introCutscene->addWidgetToFrame(text); UILabel* skiplabel = new UILabel(gfx); skiplabel->setColor(color(0.4f, 0.4f, 0.4f, 0.f)); skiplabel->setText("press [space ] to skip intro", 0, 16.f); skiplabel->setPosition(vector2(wparams[0]-320.f, 50.f)); introCutscene->addWidgetToFrame(skiplabel); introCutscene->endFrame(); /*** FRAME 2 ***/ introCutscene->startFrame(3.f); text = new UILabel(gfx); text->setColor(color(0.7f, 0.7f, 0.7f, 0.f)); text->setText("a game by Alexander Dzhoganov", 0, 32.f); text->setPosition(center); text->fadeOut(); introCutscene->addWidgetToFrame(text); introCutscene->endFrame(); /*** FRAME 3 ***/ introCutscene->startFrame(3.f); text = new UILabel(gfx); text->setColor(color(0.7f, 0.7f, 0.7f, 0.f)); text->setText("programming by:\nAlexander Dzhoganov\n\nart by:\nViktor Popov", 0, 32.f); text->setPosition(center); text->fadeOut(); introCutscene->addWidgetToFrame(text); introCutscene->endFrame(); gfx->getUI()->addWidget(introCutscene); }
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; }
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 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 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; }