axmol/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.cpp

75 lines
2.4 KiB
C++
Raw Normal View History

2013-09-16 20:54:13 +08:00
#include "UICheckBoxTest.h"
// UICheckBoxTest
UICheckBoxTest::UICheckBoxTest()
2013-12-23 15:35:35 +08:00
: _displayValueLabel(nullptr)
2013-09-16 20:54:13 +08:00
{
}
UICheckBoxTest::~UICheckBoxTest()
{
}
bool UICheckBoxTest::init()
{
if (UIScene::init())
{
2013-12-23 15:35:35 +08:00
Size widgetSize = _widget->getSize();;
2013-09-16 20:54:13 +08:00
// Add a label in which the checkbox events will be displayed
2014-03-04 16:51:35 +08:00
_displayValueLabel = Text::create();
2013-12-23 15:35:35 +08:00
_displayValueLabel->setText("No Event");
_displayValueLabel->setFontName("Marker Felt");
_displayValueLabel->setFontSize(32);
_displayValueLabel->setAnchorPoint(Point(0.5f, -1));
_displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
_uiLayer->addChild(_displayValueLabel);
2013-09-16 20:54:13 +08:00
// Add the alert
2014-03-04 16:51:35 +08:00
Text* alert = Text::create();
2013-09-16 20:54:13 +08:00
alert->setText("CheckBox");
2013-12-23 15:35:35 +08:00
alert->setFontName("Marker Felt");
2013-09-16 20:54:13 +08:00
alert->setFontSize(30);
alert->setColor(Color3B(159, 168, 176));
2013-12-23 15:35:35 +08:00
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f));
_uiLayer->addChild(alert);
2013-09-16 20:54:13 +08:00
// Create the checkbox
2013-12-23 15:35:35 +08:00
CheckBox* checkBox = CheckBox::create();
2013-09-16 20:54:13 +08:00
checkBox->setTouchEnabled(true);
checkBox->loadTextures("cocosgui/check_box_normal.png",
"cocosgui/check_box_normal_press.png",
"cocosgui/check_box_active.png",
"cocosgui/check_box_normal_disable.png",
"cocosgui/check_box_active_disable.png");
checkBox->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
2013-11-08 18:43:06 +08:00
checkBox->addEventListenerCheckBox(this, checkboxselectedeventselector(UICheckBoxTest::selectedEvent));
2013-12-23 15:35:35 +08:00
_uiLayer->addChild(checkBox);
2013-09-16 20:54:13 +08:00
return true;
}
return false;
}
void UICheckBoxTest::selectedEvent(Ref* pSender,CheckBoxEventType type)
2013-09-16 20:54:13 +08:00
{
2013-12-23 15:35:35 +08:00
switch (type)
{
case CHECKBOX_STATE_EVENT_SELECTED:
_displayValueLabel->setText(String::createWithFormat("Selected")->getCString());
2013-09-16 20:54:13 +08:00
break;
2013-12-23 15:35:35 +08:00
case CHECKBOX_STATE_EVENT_UNSELECTED:
_displayValueLabel->setText(String::createWithFormat("Unselected")->getCString());
2013-09-16 20:54:13 +08:00
break;
2013-12-23 15:35:35 +08:00
2013-09-16 20:54:13 +08:00
default:
break;
}
2014-03-04 16:51:35 +08:00
}