2014-03-04 16:51:35 +08:00
|
|
|
#include "UIButtonTest_Editor.h"
|
|
|
|
|
2015-04-09 12:23:47 +08:00
|
|
|
USING_NS_CC;
|
|
|
|
using namespace cocos2d::ui;
|
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
// UIButtonTest_Editor
|
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
UIButtonEditorTests::UIButtonEditorTests()
|
2014-03-04 16:51:35 +08:00
|
|
|
{
|
2015-04-03 14:31:03 +08:00
|
|
|
ADD_TEST_CASE(UIButtonTest_Editor);
|
2014-03-04 16:51:35 +08:00
|
|
|
}
|
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
UIButtonTest_Editor::UIButtonTest_Editor()
|
|
|
|
: _displayValueLabel(nullptr)
|
2014-03-04 16:51:35 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
UIButtonTest_Editor::~UIButtonTest_Editor()
|
2014-03-04 16:51:35 +08:00
|
|
|
{
|
2014-07-01 14:35:43 +08:00
|
|
|
|
|
|
|
}
|
2014-03-04 16:51:35 +08:00
|
|
|
|
2014-07-01 14:35:43 +08:00
|
|
|
void UIButtonTest_Editor::configureGUIScene()
|
|
|
|
{
|
2015-04-03 14:31:03 +08:00
|
|
|
UIScene_Editor::configureGUIScene();
|
2014-07-01 14:35:43 +08:00
|
|
|
|
|
|
|
Layout* root = static_cast<Layout*>(_layout->getChildByName("root_Panel"));
|
|
|
|
|
|
|
|
Button* button = static_cast<Button*>(Helper::seekWidgetByName(root, "Button_123"));
|
|
|
|
button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest_Editor::touchEvent, this));
|
|
|
|
|
|
|
|
Button* title_button = static_cast<Button*>(Helper::seekWidgetByName(root, "Button_126"));
|
|
|
|
title_button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest_Editor::touchEvent, this));
|
|
|
|
|
|
|
|
Button* scale9_button = static_cast<Button*>(Helper::seekWidgetByName(root, "Button_129"));
|
|
|
|
scale9_button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest_Editor::touchEvent,this));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UIButtonTest_Editor::init()
|
|
|
|
{
|
|
|
|
if (UIScene_Editor::init())
|
|
|
|
{
|
2015-05-14 18:08:37 +08:00
|
|
|
Node* node = CSLoader::createNode("cocosui/UIEditorTest/UIButton/res.csb");
|
2014-10-10 10:44:16 +08:00
|
|
|
Node* child = node->getChildByTag(4);
|
|
|
|
child->removeFromParent();
|
|
|
|
_layout = static_cast<Layout*>(child);
|
2014-07-01 14:35:43 +08:00
|
|
|
_touchGroup->addChild(_layout);
|
2014-03-04 16:51:35 +08:00
|
|
|
|
2014-07-01 14:35:43 +08:00
|
|
|
this->configureGUIScene();
|
2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
|
2014-07-01 14:35:43 +08:00
|
|
|
_displayValueLabel = ui::Text::create();
|
|
|
|
_displayValueLabel->setFontName("Marker Felt");
|
2014-03-04 16:51:35 +08:00
|
|
|
_displayValueLabel->setFontSize(30);
|
2014-05-14 15:26:14 +08:00
|
|
|
_displayValueLabel->setString("No event");
|
2014-06-20 11:18:53 +08:00
|
|
|
_displayValueLabel->setPosition(Vec2(_layout->getContentSize().width / 2,
|
2014-07-01 14:35:43 +08:00
|
|
|
_layout->getContentSize().height - _displayValueLabel->getContentSize().height * 1.75f));
|
|
|
|
|
|
|
|
_touchGroup->addChild(_displayValueLabel,20);
|
2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-09 14:30:39 +08:00
|
|
|
void UIButtonTest_Editor::touchEvent(Ref *pSender, Widget::TouchEventType type)
|
2014-03-04 16:51:35 +08:00
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
2014-05-09 14:30:39 +08:00
|
|
|
case Widget::TouchEventType::BEGAN:
|
2014-05-14 15:26:14 +08:00
|
|
|
_displayValueLabel->setString("Touch Down");
|
2014-03-04 16:51:35 +08:00
|
|
|
break;
|
|
|
|
|
2014-05-09 14:30:39 +08:00
|
|
|
case Widget::TouchEventType::MOVED:
|
2014-05-14 15:26:14 +08:00
|
|
|
_displayValueLabel->setString("Touch Moved");
|
2014-03-04 16:51:35 +08:00
|
|
|
break;
|
|
|
|
|
2014-05-09 14:30:39 +08:00
|
|
|
case Widget::TouchEventType::ENDED:
|
2014-05-14 15:26:14 +08:00
|
|
|
_displayValueLabel->setString("Touch Ended");
|
2014-03-04 16:51:35 +08:00
|
|
|
break;
|
|
|
|
|
2014-05-09 14:30:39 +08:00
|
|
|
case Widget::TouchEventType::CANCELED:
|
2014-05-14 15:26:14 +08:00
|
|
|
_displayValueLabel->setString("Touch Canceled");
|
2014-03-04 16:51:35 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|