axmol/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp

92 lines
2.6 KiB
C++
Raw Normal View History

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
UIButtonEditorTests::UIButtonEditorTests()
2014-03-04 16:51:35 +08:00
{
ADD_TEST_CASE(UIButtonTest_Editor);
2014-03-04 16:51:35 +08:00
}
UIButtonTest_Editor::UIButtonTest_Editor()
: _displayValueLabel(nullptr)
2014-03-04 16:51:35 +08:00
{
}
UIButtonTest_Editor::~UIButtonTest_Editor()
2014-03-04 16:51:35 +08:00
{
}
2014-03-04 16:51:35 +08:00
void UIButtonTest_Editor::configureGUIScene()
{
UIScene_Editor::configureGUIScene();
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())
{
Node* node = CSLoader::createNode("cocosui/UIEditorTest/UIButton/res.csb");
Node* child = node->getChildByTag(4);
child->removeFromParent();
_layout = static_cast<Layout*>(child);
_touchGroup->addChild(_layout);
2014-03-04 16:51:35 +08:00
this->configureGUIScene();
2014-03-04 16:51:35 +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,
_layout->getContentSize().height - _displayValueLabel->getContentSize().height * 1.75f));
_touchGroup->addChild(_displayValueLabel,20);
2014-03-04 16:51:35 +08:00
return true;
}
return false;
}
void UIButtonTest_Editor::touchEvent(Ref *pSender, Widget::TouchEventType type)
2014-03-04 16:51:35 +08:00
{
switch (type)
{
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;
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;
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;
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;
}
}