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())
|
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
Size widgetSize = _widget->getContentSize();;
|
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);
|
2014-05-15 01:07:09 +08:00
|
|
|
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1));
|
|
|
|
_displayValueLabel->setPosition(Vec2(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));
|
2014-06-20 11:18:53 +08:00
|
|
|
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().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
|
2014-04-02 15:58:18 +08:00
|
|
|
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");
|
2014-05-15 01:07:09 +08:00
|
|
|
checkBox->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
|
2013-09-16 20:54:13 +08:00
|
|
|
|
2014-05-09 16:04:55 +08:00
|
|
|
checkBox->addEventListener(CC_CALLBACK_2(UICheckBoxTest::selectedEvent, this));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(checkBox);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-09 16:04:55 +08:00
|
|
|
void UICheckBoxTest::selectedEvent(Ref* pSender,CheckBox::EventType type)
|
2013-09-16 20:54:13 +08:00
|
|
|
{
|
2013-12-23 15:35:35 +08:00
|
|
|
switch (type)
|
|
|
|
{
|
2014-05-09 16:04:55 +08:00
|
|
|
case CheckBox::EventType::SELECTED:
|
2014-05-14 15:26:14 +08:00
|
|
|
_displayValueLabel->setString(String::createWithFormat("Selected")->getCString());
|
2013-09-16 20:54:13 +08:00
|
|
|
break;
|
2013-12-23 15:35:35 +08:00
|
|
|
|
2014-05-09 16:04:55 +08:00
|
|
|
case CheckBox::EventType::UNSELECTED:
|
2014-05-14 15:26:14 +08:00
|
|
|
_displayValueLabel->setString(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
|
|
|
}
|
2014-12-23 15:03:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
// UICheckBoxDefaultBehaviorTest
|
|
|
|
UICheckBoxDefaultBehaviorTest::UICheckBoxDefaultBehaviorTest()
|
|
|
|
: _displayValueLabel(nullptr)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UICheckBoxDefaultBehaviorTest::~UICheckBoxDefaultBehaviorTest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UICheckBoxDefaultBehaviorTest::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
|
|
|
Size widgetSize = _widget->getContentSize();;
|
|
|
|
|
|
|
|
// Add a label in which the checkbox events will be displayed
|
|
|
|
_displayValueLabel = Text::create("No Event", "fonts/Marker Felt.ttf", 32);
|
|
|
|
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1));
|
|
|
|
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
|
|
|
|
_uiLayer->addChild(_displayValueLabel);
|
|
|
|
|
|
|
|
// Add the alert
|
|
|
|
Text* alert = Text::create("Only left two and the last checkbox can be cliked!","fonts/Marker Felt.ttf",20 );
|
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
|
|
|
alert->setPosition(Vec2(widgetSize.width / 2.0f,
|
|
|
|
widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
|
|
|
|
_uiLayer->addChild(alert);
|
|
|
|
|
|
|
|
// Create the checkbox
|
|
|
|
CheckBox* checkBox = CheckBox::create("cocosui/check_box_normal.png",
|
|
|
|
"cocosui/check_box_active.png");
|
|
|
|
checkBox->setPosition(Vec2(widgetSize.width / 2.0f - 50, widgetSize.height / 2.0f));
|
|
|
|
|
|
|
|
_uiLayer->addChild(checkBox);
|
|
|
|
|
|
|
|
|
|
|
|
// Create the checkbox
|
|
|
|
CheckBox* checkBox2 = CheckBox::create("cocosui/check_box_normal.png",
|
|
|
|
"cocosui/check_box_active.png");
|
|
|
|
checkBox2->setPosition(Vec2(widgetSize.width / 2.0f - 150, widgetSize.height / 2.0f));
|
|
|
|
checkBox2->ignoreContentAdaptWithSize(false);
|
|
|
|
checkBox2->setZoomScale(0.5);
|
|
|
|
checkBox2->setContentSize(Size(80,80));
|
|
|
|
checkBox2->setName("bigCheckBox");
|
|
|
|
_uiLayer->addChild(checkBox2);
|
|
|
|
|
|
|
|
|
|
|
|
// Create the checkbox
|
|
|
|
CheckBox* checkBoxDisabled = CheckBox::create("cocosui/check_box_normal.png",
|
|
|
|
"cocosui/check_box_active.png");
|
|
|
|
checkBoxDisabled->setPosition(Vec2(widgetSize.width / 2.0f + 20, widgetSize.height / 2.0f));
|
|
|
|
checkBoxDisabled->setEnabled(false);
|
|
|
|
checkBoxDisabled->setBright(false);
|
|
|
|
_uiLayer->addChild(checkBoxDisabled);
|
|
|
|
|
|
|
|
CheckBox* checkBoxDisabled2 = CheckBox::create("cocosui/check_box_normal.png",
|
|
|
|
"cocosui/check_box_active.png");
|
|
|
|
checkBoxDisabled2->setPosition(Vec2(widgetSize.width / 2.0f + 70, widgetSize.height / 2.0f));
|
|
|
|
checkBoxDisabled2->setBright(false);
|
|
|
|
checkBoxDisabled2->setSelected(true);
|
|
|
|
_uiLayer->addChild(checkBoxDisabled2);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|