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

68 lines
2.2 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-04-03 10:34:20 +08:00
_displayValueLabel = Text::create("No Event", "fonts/Marker Felt.ttf", 32);
_displayValueLabel->setAnchorPoint(Vector2(0.5f, -1));
_displayValueLabel->setPosition(Vector2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
2013-12-23 15:35:35 +08:00
_uiLayer->addChild(_displayValueLabel);
2013-09-16 20:54:13 +08:00
// Add the alert
2014-04-03 10:34:20 +08:00
Text* alert = Text::create("CheckBox","fonts/Marker Felt.ttf",30 );
2013-09-16 20:54:13 +08:00
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Vector2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f));
2013-12-23 15:35:35 +08:00
_uiLayer->addChild(alert);
2013-09-16 20:54:13 +08:00
// Create the checkbox
CheckBox* checkBox = CheckBox::create("cocosui/check_box_normal.png",
"cocosui/check_box_normal_press.png",
"cocosui/check_box_active.png",
"cocosui/check_box_normal_disable.png",
"cocosui/check_box_active_disable.png");
checkBox->setPosition(Vector2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
2013-09-16 20:54:13 +08:00
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-11 17:13:54 +08:00
}