void FormsSample::initialize() { setMultiTouch(true); setVsync(false); _formSelect = Form::create("res/common/forms/formSelect.form"); _formSelect->setFocus(); RadioButton* form0Button = static_cast<RadioButton*>(_formSelect->getControl("form0")); form0Button->addListener(this, Control::Listener::CLICK); RadioButton* form1Button = static_cast<RadioButton*>(_formSelect->getControl("form1")); form1Button->addListener(this, Control::Listener::CLICK); RadioButton* form2Button = static_cast<RadioButton*>(_formSelect->getControl("form2")); form2Button->addListener(this, Control::Listener::CLICK); RadioButton* form3Button = static_cast<RadioButton*>(_formSelect->getControl("form3")); form3Button->addListener(this, Control::Listener::CLICK); RadioButton* form4Button = static_cast<RadioButton*>(_formSelect->getControl("form4")); form4Button->addListener(this, Control::Listener::CLICK); RadioButton* form5Button = static_cast<RadioButton*>(_formSelect->getControl("form5")); form5Button->addListener(this, Control::Listener::CLICK); for (unsigned int i = 0; i < _formFiles.size(); i++) { Form* form = Form::create(_formFiles[i]); form->setEnabled(false); _forms.push_back(form); } _formIndex = 0; // Create a form programmatically. createSampleForm(); Button* button = static_cast<Button*>(_forms[0]->getControl("testButton")); button->setFocus(); // Create a scene with a camera node. Camera* camera = Camera::createPerspective(45.0f, (float)getWidth() / (float)getHeight(), 0.25f, 100.0f); _scene = Scene::create(); Node* cameraNode = _scene->addNode("Camera"); cameraNode->setCamera(camera); _scene->setActiveCamera(camera); SAFE_RELEASE(camera); _formNodeParent = _scene->addNode("FormParent"); _formNode = Node::create("Form"); _formNodeParent->addChild(_formNode); formChanged(); _gamepad = getGamepad(0); // This is needed because the virtual gamepad is shared between all samples. // SamplesGame always ensures the virtual gamepad is disabled when a sample is exited. if (_gamepad && _gamepad->isVirtual()) _gamepad->getForm()->setEnabled(true); }
void FormsSample::createSampleForm() { Form* form = Form::create("testForm", NULL); form->setSize(600, 600); Label* label = Label::create("testLabel"); label->setPosition(50, 50); label->setSize(200, 50); label->setText(L"Label:"); form->addControl(label); label->release(); Button* button = Button::create("opacityButton"); button->setPosition(45, 100); button->setSize(200, 100); button->setText(L"This is a button. Click to change its opacity."); button->addListener(this, Control::Listener::CLICK); form->addControl(button); button->release(); form->setEnabled(false); _forms.push_back(form); }