2012-04-19 14:35:52 +08:00
|
|
|
#include "KeypadTest.h"
|
|
|
|
|
|
|
|
KeypadTest::KeypadTest()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
auto label = LabelTTF::create("Keypad Test", "Arial", 28);
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(label, 0);
|
2013-07-12 14:11:55 +08:00
|
|
|
label->setPosition( Point(s.width/2, s.height-50) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-10-23 16:14:03 +08:00
|
|
|
auto listener = EventListenerKeyboard::create();
|
|
|
|
listener->onKeyReleased = CC_CALLBACK_2(KeypadTest::onKeyReleased, this);
|
|
|
|
|
2013-10-26 15:04:01 +08:00
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
2013-10-23 16:14:03 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// create a label to display the tip string
|
2013-06-20 14:17:10 +08:00
|
|
|
_label = LabelTTF::create("Please press any key...", "Arial", 22);
|
2013-07-12 14:11:55 +08:00
|
|
|
_label->setPosition(Point(s.width / 2, s.height / 2));
|
2013-06-15 14:03:30 +08:00
|
|
|
addChild(_label, 0);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_label->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
KeypadTest::~KeypadTest()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_label->release();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-09-20 19:19:31 +08:00
|
|
|
void KeypadTest::onKeyReleased(EventKeyboard::KeyCode keycode, Event* event)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-09-20 19:19:31 +08:00
|
|
|
if (keycode == EventKeyboard::KeyCode::KEY_BACKSPACE)
|
2013-09-03 18:22:03 +08:00
|
|
|
{
|
|
|
|
_label->setString("BACK clicked!");
|
|
|
|
}
|
2013-09-20 19:19:31 +08:00
|
|
|
else if (keycode == EventKeyboard::KeyCode::KEY_MENU)
|
2013-09-03 18:22:03 +08:00
|
|
|
{
|
|
|
|
_label->setString("MENU clicked!");
|
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void KeypadTestScene::runThisTest()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = new KeypadTest();
|
2013-07-23 08:25:44 +08:00
|
|
|
addChild(layer);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(this);
|
2013-07-23 08:25:44 +08:00
|
|
|
layer->release();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|