PuzzleSDK
UIButtonTest类 参考

#include <UIButtonTest.h>

+ 类 UIButtonTest 继承关系图:
+ UIButtonTest 的协作图:

Public 成员函数

 CREATE_FUNC (UIButtonTest)
 
 UIButtonTest ()
 
 ~UIButtonTest ()
 
virtual bool init () override
 
void touchEvent (cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
 
void printWidgetResources (cocos2d::Ref *sender)
 
- Public 成员函数 继承自 UIScene
 UIScene ()
 
 ~UIScene ()
 
virtual void onEnter () override
 
- Public 成员函数 继承自 TestCase
 TestCase ()
 
 ~TestCase ()
 
virtual std::string title () const
 
virtual std::string subtitle () const
 
virtual Type getTestType () const
 
virtual float getDuration () const
 
virtual std::string getExpectedOutput () const
 
virtual std::string getActualOutput () const
 
virtual void restartTestCallback (cocos2d::Ref *sender)
 
virtual void nextTestCallback (cocos2d::Ref *sender)
 
virtual void priorTestCallback (cocos2d::Ref *sender)
 
virtual void onBackCallback (cocos2d::Ref *sender)
 
void setTestSuite (TestSuite *testSuite)
 
TestSuitegetTestSuite () const
 
float getRunTime () const
 
void setTestCaseName (const std::string &name)
 
std::string getTestCaseName () const
 
const cocos2d::Label * getSubtitleLable () const
 
const cocos2d::MenuItemImage * getRestartTestItem () const
 

Protected 属性

cocos2d::ui::Text * _displayValueLabel
 
cocos2d::ui::Button * _button
 
- Protected 属性 继承自 UIScene
cocos2d::Layer * _uiLayer
 
cocos2d::ui::Layout * _widget
 
cocos2d::ui::Text * _sceneTitle
 
- Protected 属性 继承自 TestCase
cocos2d::MenuItemImage * _priorTestItem
 
cocos2d::MenuItemImage * _restartTestItem
 
cocos2d::MenuItemImage * _nextTestItem
 
cocos2d::Label * _titleLabel
 
cocos2d::Label * _subtitleLabel
 

额外继承的成员函数

- Public 类型 继承自 TestCase
enum class  Type { ROBUSTNESS , UNIT , GRAPHICAL_STATIC , MANUAL }
 
- Public 属性 继承自 TestCase
CC_CONSTRUCTOR_ACCESS __pad0__: virtual bool init() override
 

详细描述

在文件 UIButtonTest.h33 行定义.

构造及析构函数说明

◆ UIButtonTest()

UIButtonTest::UIButtonTest ( )

在文件 UIButtonTest.cpp54 行定义.

55: _displayValueLabel(nullptr)
56{
57
58}
cocos2d::ui::Text * _displayValueLabel
Definition: UIButtonTest.h:46

◆ ~UIButtonTest()

UIButtonTest::~UIButtonTest ( )

在文件 UIButtonTest.cpp60 行定义.

61{
62}

成员函数说明

◆ CREATE_FUNC()

UIButtonTest::CREATE_FUNC ( UIButtonTest  )

◆ init()

bool UIButtonTest::init ( )
overridevirtual

重载 UIScene .

在文件 UIButtonTest.cpp64 行定义.

65{
66 if (UIScene::init())
67 {
68 Size widgetSize = _widget->getContentSize();
69
70 // Add a label in which the button events will be displayed
71 _displayValueLabel = Text::create("No Event", "fonts/Marker Felt.ttf",32);
72 _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
73 _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
75
76 // Add the alert
77 Text* alert = Text::create("Button","fonts/Marker Felt.ttf",30);
78 alert->setColor(Color3B(159, 168, 176));
79
80 alert->setPosition(Vec2(widgetSize.width / 2.0f,
81 widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
82
83 _uiLayer->addChild(alert);
84
85 // Create the button
86 Button* button = Button::create("cocosui/animationbuttonnormal.png",
87 "cocosui/animationbuttonpressed.png");
88 CCLOG("content size should be greater than 0: width = %f, height = %f", button->getContentSize().width,
89 button->getContentSize().height);
90 button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
91 button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest::touchEvent, this));
92 button->setZoomScale(0.4f);
93 button->setPressedActionEnabled(true);
94 _uiLayer->addChild(button);
95 button->setOpacity(100);
96 // Create the imageview
97 ImageView* imageView = ImageView::create();
98
99 imageView->setPosition(Vec2(widgetSize.width / 2.0f + 50+ button->getContentSize().width/2,
100 widgetSize.height / 2.0f));
101 imageView->setTag(12);
102
103 _uiLayer->addChild(imageView);
104
105 _button = button;
106
107 TTFConfig ttfConfig("fonts/arial.ttf", 15);
108 auto label1 = Label::createWithTTF(ttfConfig, "Print Resources");
109 auto item1 = MenuItemLabel::create(label1, CC_CALLBACK_1(UIButtonTest::printWidgetResources, this));
110 item1->setPosition(Vec2(VisibleRect::left().x + 60, VisibleRect::bottom().y + item1->getContentSize().height * 3));
111 auto pMenu1 = Menu::create(item1, nullptr);
112 pMenu1->setPosition(Vec2(0.0f, 0.0f));
113 this->addChild(pMenu1, 10);
114
115 return true;
116 }
117 return false;
118}
cocos2d::ui::Button * _button
Definition: UIButtonTest.h:47
void printWidgetResources(cocos2d::Ref *sender)
void touchEvent(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
cocos2d::Layer * _uiLayer
Definition: UIScene.h:44
virtual bool init() override
Definition: UIScene.cpp:46
cocos2d::ui::Layout * _widget
Definition: UIScene.h:45
static cocos2d::Vec2 bottom()
Definition: VisibleRect.cpp:63
static cocos2d::Vec2 left()
Definition: VisibleRect.cpp:45

引用了 _button, _displayValueLabel, UIScene::_uiLayer, UIScene::_widget, VisibleRect::bottom(), UIScene::init(), VisibleRect::left(), printWidgetResources() , 以及 touchEvent().

+ 函数调用图:

◆ printWidgetResources()

void UIButtonTest::printWidgetResources ( cocos2d::Ref *  sender)

在文件 UIButtonTest.cpp155 行定义.

156{
157 cocos2d::ResourceData normalFileName = _button->getNormalFile();
158 CCLOG("normalFileName Name : %s, Type: %d", normalFileName.file.c_str(), normalFileName.type);
159 cocos2d::ResourceData clickedFileName = _button->getPressedFile();
160 CCLOG("clickedFileName Name : %s, Type: %d", clickedFileName.file.c_str(), clickedFileName.type);
161 cocos2d::ResourceData disabledFileName = _button->getDisabledFile();
162 CCLOG("disabledFileName Name : %s, Type: %d", disabledFileName.file.c_str(), disabledFileName.type);
163}

引用了 _button.

被这些函数引用 init().

+ 这是这个函数的调用关系图:

◆ touchEvent()

void UIButtonTest::touchEvent ( cocos2d::Ref *  sender,
cocos2d::ui::Widget::TouchEventType  type 
)

在文件 UIButtonTest.cpp120 行定义.

121{
122 switch (type)
123 {
124 case Widget::TouchEventType::BEGAN:
125 _displayValueLabel->setString(StringUtils::format("Touch Down"));
126 break;
127
128 case Widget::TouchEventType::MOVED:
129 _displayValueLabel->setString(StringUtils::format("Touch Move"));
130 break;
131
132 case Widget::TouchEventType::ENDED:
133 {
134 _displayValueLabel->setString(StringUtils::format("Touch Up"));
135 ImageView* imageView = (ImageView*)_uiLayer->getChildByTag(12);
136 imageView->setVisible(false);
137 imageView->loadTexture("cocosui/ccicon.png");
138 imageView->setOpacity(0);
139 imageView->setVisible(true);
140 imageView->runAction(Sequence::create(FadeIn::create(0.5),DelayTime::create(1.0),FadeOut::create(0.5), nullptr));
141 Button *btn = (Button*)pSender;
142 btn->loadTextureNormal("cocosui/animationbuttonnormal.png");
143 }
144 break;
145
146 case Widget::TouchEventType::CANCELED:
147 _displayValueLabel->setString(StringUtils::format("Touch Cancelled"));
148 break;
149
150 default:
151 break;
152 }
153}

引用了 _displayValueLabel , 以及 UIScene::_uiLayer.

被这些函数引用 init().

+ 这是这个函数的调用关系图:

类成员变量说明

◆ _button

cocos2d::ui::Button* UIButtonTest::_button
protected

在文件 UIButtonTest.h47 行定义.

被这些函数引用 init() , 以及 printWidgetResources().

◆ _displayValueLabel

cocos2d::ui::Text* UIButtonTest::_displayValueLabel
protected

在文件 UIButtonTest.h46 行定义.

被这些函数引用 init() , 以及 touchEvent().


该类的文档由以下文件生成: