PuzzleSDK
UIButtonTest_Title类 参考

#include <UIButtonTest.h>

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

Public 成员函数

 CREATE_FUNC (UIButtonTest_Title)
 
 UIButtonTest_Title ()
 
 ~UIButtonTest_Title ()
 
virtual bool init () override
 
void touchEvent (cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
 
- 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
 
- 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.h95 行定义.

构造及析构函数说明

◆ UIButtonTest_Title()

UIButtonTest_Title::UIButtonTest_Title ( )

在文件 UIButtonTest.cpp432 行定义.

433: _displayValueLabel(nullptr)
434{
435
436}
cocos2d::ui::Text * _displayValueLabel
Definition: UIButtonTest.h:107

◆ ~UIButtonTest_Title()

UIButtonTest_Title::~UIButtonTest_Title ( )

在文件 UIButtonTest.cpp438 行定义.

439{
440}

成员函数说明

◆ CREATE_FUNC()

UIButtonTest_Title::CREATE_FUNC ( UIButtonTest_Title  )

◆ init()

bool UIButtonTest_Title::init ( )
overridevirtual

重载 UIScene .

在文件 UIButtonTest.cpp442 行定义.

443{
444 if (UIScene::init())
445 {
446 Size widgetSize = _widget->getContentSize();
447
448 // Add a label in which the text button events will be displayed
449 _displayValueLabel = Text::create("No Event", "fonts/Marker Felt.ttf", 32);
450 _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
451 _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
452 _uiLayer->addChild(_displayValueLabel);
453
454 // Add the alert
455 Text* alert = Text::create("Button with title, title should be flipped!", "fonts/Marker Felt.ttf", 30);
456 alert->setColor(Color3B(159, 168, 176));
457 alert->setPosition(Vec2(widgetSize.width / 2.0f,
458 widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
459
460 _uiLayer->addChild(alert);
461
462 // Create the button with title
463 Button* button = Button::create("cocosui/backtotoppressed.png", "cocosui/backtotopnormal.png");
464 button->setTitleText("Title Button!");
465 button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
466 button->setTitleColor(Color3B::YELLOW);
467 CCASSERT(button->getTitleColor() == Color3B::YELLOW, "Button setTitleColor & getTitleColor not match!");
468 button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest_Title::touchEvent, this));
469 _uiLayer->addChild(button);
470 button->setFlippedX(true);
471 auto label = button->getTitleRenderer();
472 label->setScale(4.0);
473 button->runAction(RepeatForever::create(Sequence::create(ScaleTo::create(1.0f, 1.2f),
474 ScaleTo::create(1.0f, 1.0f),nullptr)));
475
476
477 TextBMFont *text = TextBMFont::create("BMFont", "cocosui/bitmapFontTest2.fnt");
478 text->setPosition(button->getPosition() + Vec2(button->getContentSize().width/2 + 50,0.0f));
479 text->setColor(Color3B::YELLOW);
480 text->setOpacity(50);
481 text->setName("text");
482
483 auto button2 = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
484 button2->setTitleFontName("fonts/helvetica-32.fnt");
485 button2->setTitleText("BMFont");
486 //the change of font size will take no effect.
487 button2->setTitleFontSize(30);
488 button2->setPosition(Vec2(button->getPosition() + Vec2(50.0f,-80.0f)));
489 this->addChild(button2);
490
491 _uiLayer->addChild(text);
492
493 return true;
494 }
495 return false;
496}
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

引用了 _displayValueLabel, UIScene::_uiLayer, UIScene::_widget, UIScene::init() , 以及 touchEvent().

+ 函数调用图:

◆ touchEvent()

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

在文件 UIButtonTest.cpp499 行定义.

500{
501 switch (type)
502 {
503 case Widget::TouchEventType::BEGAN:
504 _displayValueLabel->setString(StringUtils::format("Touch Down"));
505 break;
506
507 case Widget::TouchEventType::MOVED:
508 _displayValueLabel->setString(StringUtils::format("Touch Move"));
509 break;
510
511 case Widget::TouchEventType::ENDED:
512 {
513 _displayValueLabel->setString(StringUtils::format("Touch Up"));
514 TextBMFont *text = (TextBMFont*)_uiLayer->getChildByName("text");
515 text->setFntFile("cocosui/bitmapFontTest2.fnt");
516 if (text->getString() == "BMFont") {
517 text->setString("Hello");
518 }
519 else{
520 text->setString("BMFont");
521 }
522 }
523 break;
524
525 case Widget::TouchEventType::CANCELED:
526 _displayValueLabel->setString(StringUtils::format("Touch Cancelled"));
527 break;
528
529 default:
530 break;
531 }
532}

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

被这些函数引用 init().

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

类成员变量说明

◆ _displayValueLabel

cocos2d::ui::Text* UIButtonTest_Title::_displayValueLabel
protected

在文件 UIButtonTest.h107 行定义.

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


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