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

88 lines
3.3 KiB
C++
Raw Normal View History

2014-03-04 16:51:35 +08:00
#include "UIButtonTest_Editor.h"
// UIButtonTest_Editor
UIButtonTest_Editor::UIButtonTest_Editor()
: _displayValueLabel(nullptr)
2014-03-04 16:51:35 +08:00
{
}
UIButtonTest_Editor::~UIButtonTest_Editor()
{
}
bool UIButtonTest_Editor::init()
{
if (UIScene_Editor::init())
{
2014-03-11 17:13:54 +08:00
_layout = static_cast<Layout*>(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIButton_Editor/UIButton_Editor_1.json"));
2014-03-04 16:51:35 +08:00
_touchGroup->addChild(_layout);
Size screenSize = CCDirector::getInstance()->getWinSize();
Size rootSize = _layout->getSize();
_touchGroup->setPosition(Vector2((screenSize.width - rootSize.width) / 2,
2014-03-04 16:51:35 +08:00
(screenSize.height - rootSize.height) / 2));
Layout* root = static_cast<Layout*>(_layout->getChildByName("root_Panel"));
Text* back_label = static_cast<Text*>(Helper::seekWidgetByName(root, "back"));
// back_label->addTouchEventListener(this, toucheventselector(UIScene_Editor::toGUIEditorTestScene));
back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this));
2014-03-04 16:51:35 +08:00
_sceneTitle = static_cast<Text*>(Helper::seekWidgetByName(root, "UItest"));
Button* button = static_cast<Button*>(Helper::seekWidgetByName(root, "Button_123"));
// button->addTouchEventListener(this, toucheventselector(UIButtonTest_Editor::touchEvent));
button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest_Editor::touchEvent, this));
2014-03-04 16:51:35 +08:00
Button* title_button = static_cast<Button*>(Helper::seekWidgetByName(root, "Button_126"));
// title_button->addTouchEventListener(this, toucheventselector(UIButtonTest_Editor::touchEvent));
title_button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest_Editor::touchEvent, this));
2014-03-04 16:51:35 +08:00
Button* scale9_button = static_cast<Button*>(Helper::seekWidgetByName(root, "Button_129"));
// scale9_button->addTouchEventListener(this, toucheventselector(UIButtonTest_Editor::touchEvent));
scale9_button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest_Editor::touchEvent, this));
2014-03-04 16:51:35 +08:00
_displayValueLabel = Text::create();
_displayValueLabel->setFontName("fonts/Marker Felt.ttf");
2014-03-04 16:51:35 +08:00
_displayValueLabel->setFontSize(30);
_displayValueLabel->setText("No event");
_displayValueLabel->setPosition(Vector2(_layout->getSize().width / 2,
2014-03-04 16:51:35 +08:00
_layout->getSize().height - _displayValueLabel->getSize().height * 1.75f));
_touchGroup->addChild(_displayValueLabel);
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-03-04 16:51:35 +08:00
_displayValueLabel->setText("Touch Down");
break;
case Widget::TouchEventType::MOVED:
2014-03-04 16:51:35 +08:00
_displayValueLabel->setText("Touch Moved");
break;
case Widget::TouchEventType::ENDED:
2014-03-04 16:51:35 +08:00
_displayValueLabel->setText("Touch Ended");
break;
case Widget::TouchEventType::CANCELED:
2014-03-04 16:51:35 +08:00
_displayValueLabel->setText("Touch Canceled");
break;
default:
break;
}
}