PuzzleSDK
LabelFNTMultiLineAlignment类 参考

#include <LabelTestNew.h>

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

Public 成员函数

 CREATE_FUNC (LabelFNTMultiLineAlignment)
 
virtual bool init () override
 
void snapArrowsToEdge ()
 
virtual std::string title () const override
 
virtual std::string subtitle () const override
 
void stringChanged (cocos2d::Ref *sender)
 
void alignmentChanged (cocos2d::Ref *sender)
 
void onTouchesBegan (const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
 
void onTouchesEnded (const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
 
void onTouchesMoved (const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
 
void selectAlignmentItem (cocos2d::MenuItemFont *item)
 
void selectSentenceItem (cocos2d::MenuItemFont *item)
 
virtual std::string getItemString (cocos2d::MenuItemFont *item)
 
- Public 成员函数 继承自 TestCase
 TestCase ()
 
 ~TestCase ()
 
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
 
virtual void onEnter () override
 

Protected 属性

cocos2d::Label * _label = nullptr
 
cocos2d::Sprite * _arrowsBar = nullptr
 
cocos2d::Sprite * _arrows = nullptr
 
std::vector< cocos2d::MenuItemFont * > _menuItems
 
cocos2d::MenuItemFont * _lastSentenceItem = nullptr
 
cocos2d::MenuItemFont * _lastAlignmentItem = nullptr
 
bool _drag = false
 
- 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
 

详细描述

在文件 LabelTestNew.h164 行定义.

成员函数说明

◆ alignmentChanged()

void LabelFNTMultiLineAlignment::alignmentChanged ( cocos2d::Ref *  sender)

在文件 LabelTestNew.cpp744 行定义.

745{
746 auto item = static_cast<MenuItemFont*>(sender);
747
749
750 this->snapArrowsToEdge();
751}
void selectAlignmentItem(cocos2d::MenuItemFont *item)

引用了 selectAlignmentItem() , 以及 snapArrowsToEdge().

被这些函数引用 init().

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

◆ CREATE_FUNC()

LabelFNTMultiLineAlignment::CREATE_FUNC ( LabelFNTMultiLineAlignment  )

◆ getItemString()

std::string LabelFNTMultiLineAlignment::getItemString ( cocos2d::MenuItemFont *  item)
virtual

LabelFNTMultiLineAlignmentUNICODE 重载.

在文件 LabelTestNew.cpp712 行定义.

713{
714 std::string str;
715
716 switch (item->getTag())
717 {
718 case LongSentences:
720 break;
721 case LineBreaks:
722 str = LineBreaksExample;
723 break;
724 case Mixed:
725 str = MixedExample;
726 break;
727
728 default:
729 break;
730 }
731
732 return str;
733}
#define LineBreaksExample
#define LineBreaks
#define MixedExample
#define LongSentencesExample
BitmapFontMultiLineAlignmentNew
#define LongSentences
#define Mixed

引用了 LineBreaks, LineBreaksExample, LongSentences, LongSentencesExample, Mixed , 以及 MixedExample.

被这些函数引用 selectSentenceItem().

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

◆ init()

bool LabelFNTMultiLineAlignment::init ( )
overridevirtual

LabelFNTMultiLineAlignmentUNICODE 重载.

在文件 LabelTestNew.cpp586 行定义.

587{
588 if (!AtlasDemoNew::init())
589 {
590 return false;
591 }
592
593 auto listener = EventListenerTouchAllAtOnce::create();
594 listener->onTouchesBegan = CC_CALLBACK_2(LabelFNTMultiLineAlignment::onTouchesBegan, this);
595 listener->onTouchesMoved = CC_CALLBACK_2(LabelFNTMultiLineAlignment::onTouchesMoved, this);
596 listener->onTouchesEnded = CC_CALLBACK_2(LabelFNTMultiLineAlignment::onTouchesEnded, this);
597
598 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
599 // ask director the the window size
600 auto size = Director::getInstance()->getWinSize();
601
602 // create and initialize a Label
603 this->_label = Label::createWithBMFont("fonts/markerFelt.fnt", "", TextHAlignment::CENTER, size.width/1.5);
604
605 this->_arrowsBar = Sprite::create("Images/arrowsBar.png");
606 this->_arrows = Sprite::create("Images/arrows.png");
607
608 MenuItemFont::setFontSize(20);
609 auto longSentences = MenuItemFont::create("Long Flowing Sentences", CC_CALLBACK_1(LabelFNTMultiLineAlignment::stringChanged, this));
610 auto lineBreaks = MenuItemFont::create("Short Sentences With Intentional Line Breaks", CC_CALLBACK_1(LabelFNTMultiLineAlignment::stringChanged, this));
611 auto mixed = MenuItemFont::create("Long Sentences Mixed With Intentional Line Breaks", CC_CALLBACK_1(LabelFNTMultiLineAlignment::stringChanged, this));
612 auto stringMenu = Menu::create(longSentences, lineBreaks, mixed, nullptr);
613 stringMenu->alignItemsVertically();
614
615 longSentences->setTag(LongSentences);
616 lineBreaks->setTag(LineBreaks);
617 mixed->setTag(Mixed);
618
619 _menuItems.push_back(longSentences);
620 _menuItems.push_back(lineBreaks);
621 _menuItems.push_back(mixed);
622
623 MenuItemFont::setFontSize(30);
624
625 auto left = MenuItemFont::create("Left", CC_CALLBACK_1(LabelFNTMultiLineAlignment::alignmentChanged, this));
626 auto center = MenuItemFont::create("Center", CC_CALLBACK_1(LabelFNTMultiLineAlignment::alignmentChanged, this));
627 auto right = MenuItemFont::create("Right", CC_CALLBACK_1(LabelFNTMultiLineAlignment::alignmentChanged, this));
628
629 auto alignmentMenu = Menu::create(left, center, right, nullptr);
630 alignmentMenu->alignItemsHorizontallyWithPadding(alignmentItemPadding);
631
632 left->setTag(LeftAlign);
633 center->setTag(CenterAlign);
634 right->setTag(RightAlign);
635
636 // position the label on the center of the screen
637 this->_label->setPosition(Vec2(size.width/2, size.height/2));
638
639 this->_arrowsBar->setVisible(false);
640
641 float arrowsWidth = (ArrowsMax - ArrowsMin) * size.width;
642 this->_arrowsBar->setScaleX(arrowsWidth / this->_arrowsBar->getContentSize().width);
643 this->_arrowsBar->setPosition(Vec2(((ArrowsMax + ArrowsMin) / 2) * size.width, this->_label->getPosition().y));
644
645 stringMenu->setPosition(Vec2(size.width/2, size.height - menuItemPaddingCenter));
646 alignmentMenu->setPosition(Vec2(size.width/2, menuItemPaddingCenter+15));
647
648 this->selectSentenceItem(longSentences);
649 this->selectAlignmentItem(center);
650 this->snapArrowsToEdge();
651
652 this->addChild(this->_label);
653 this->addChild(this->_arrowsBar);
654 this->addChild(this->_arrows);
655 this->addChild(stringMenu);
656 this->addChild(alignmentMenu);
657
658 return true;
659}
#define ArrowsMin
#define CenterAlign
static float menuItemPaddingCenter
#define ArrowsMax
static float alignmentItemPadding
#define LeftAlign
#define RightAlign
void alignmentChanged(cocos2d::Ref *sender)
void onTouchesMoved(const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
void selectSentenceItem(cocos2d::MenuItemFont *item)
cocos2d::Sprite * _arrowsBar
Definition: LabelTestNew.h:184
void stringChanged(cocos2d::Ref *sender)
cocos2d::Sprite * _arrows
Definition: LabelTestNew.h:185
cocos2d::Label * _label
Definition: LabelTestNew.h:183
void onTouchesEnded(const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
std::vector< cocos2d::MenuItemFont * > _menuItems
Definition: LabelTestNew.h:186
void onTouchesBegan(const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)

引用了 _arrows, _arrowsBar, _label, _menuItems, alignmentChanged(), alignmentItemPadding, ArrowsMax, ArrowsMin, CenterAlign, LeftAlign, LineBreaks, LongSentences, menuItemPaddingCenter, Mixed, onTouchesBegan(), onTouchesEnded(), onTouchesMoved(), RightAlign, selectAlignmentItem(), selectSentenceItem(), snapArrowsToEdge() , 以及 stringChanged().

被这些函数引用 LabelFNTMultiLineAlignmentUNICODE::init().

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

◆ onTouchesBegan()

void LabelFNTMultiLineAlignment::onTouchesBegan ( const std::vector< cocos2d::Touch * > &  touches,
cocos2d::Event *  event 
)

在文件 LabelTestNew.cpp753 行定义.

754{
755 auto touch = touches[0];
756 auto location = touch->getLocationInView();
757
758 if (this->_arrows->getBoundingBox().containsPoint(location))
759 {
760 _drag = true;
761 this->_arrowsBar->setVisible(true);
762 }
763}

引用了 _arrows, _arrowsBar , 以及 _drag.

被这些函数引用 init().

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

◆ onTouchesEnded()

void LabelFNTMultiLineAlignment::onTouchesEnded ( const std::vector< cocos2d::Touch * > &  touches,
cocos2d::Event *  event 
)

在文件 LabelTestNew.cpp765 行定义.

766{
767 _drag = false;
768 this->snapArrowsToEdge();
769
770 this->_arrowsBar->setVisible(false);
771}

引用了 _arrowsBar, _drag , 以及 snapArrowsToEdge().

被这些函数引用 init().

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

◆ onTouchesMoved()

void LabelFNTMultiLineAlignment::onTouchesMoved ( const std::vector< cocos2d::Touch * > &  touches,
cocos2d::Event *  event 
)

在文件 LabelTestNew.cpp773 行定义.

774{
775 if (! _drag)
776 {
777 return;
778 }
779
780 auto touch = touches[0];
781 auto location = touch->getLocationInView();
782
783 auto winSize = Director::getInstance()->getWinSize();
784
785 this->_arrows->setPosition(Vec2(MAX(MIN(location.x, ArrowsMax*winSize.width), ArrowsMin*winSize.width),
786 this->_arrows->getPosition().y));
787
788 float labelWidth = fabs(this->_arrows->getPosition().x - this->_label->getPosition().x) * 2;
789
790 this->_label->setMaxLineWidth(labelWidth);
791}

引用了 _arrows, _drag, _label, ArrowsMax , 以及 ArrowsMin.

被这些函数引用 init().

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

◆ selectAlignmentItem()

void LabelFNTMultiLineAlignment::selectAlignmentItem ( cocos2d::MenuItemFont *  item)

在文件 LabelTestNew.cpp671 行定义.

672{
673 if (this->_lastAlignmentItem && this->_lastAlignmentItem != item)
674 {
675 this->_lastAlignmentItem->setColor(Color3B::WHITE);
676 }
677
678 this->_lastAlignmentItem = item;
679 item->setColor(Color3B::RED);
680
681 switch (item->getTag())
682 {
683 case LeftAlign:
684 this->_label->setAlignment(TextHAlignment::LEFT);
685 break;
686 case CenterAlign:
687 this->_label->setAlignment(TextHAlignment::CENTER);
688 break;
689 case RightAlign:
690 this->_label->setAlignment(TextHAlignment::RIGHT);
691 break;
692
693 default:
694 break;
695 }
696}
cocos2d::MenuItemFont * _lastAlignmentItem
Definition: LabelTestNew.h:188

引用了 _label, _lastAlignmentItem, CenterAlign, LeftAlign , 以及 RightAlign.

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

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

◆ selectSentenceItem()

void LabelFNTMultiLineAlignment::selectSentenceItem ( cocos2d::MenuItemFont *  item)

在文件 LabelTestNew.cpp698 行定义.

699{
700 if (this->_lastSentenceItem && this->_lastSentenceItem != item)
701 {
702 this->_lastSentenceItem->setColor(Color3B::WHITE);
703 }
704
705 this->_lastSentenceItem = item;
706 item->setColor(Color3B::RED);
707
708 auto str = this->getItemString(item);
709 this->_label->setString(str);
710}
cocos2d::MenuItemFont * _lastSentenceItem
Definition: LabelTestNew.h:187
virtual std::string getItemString(cocos2d::MenuItemFont *item)

引用了 _label, _lastSentenceItem , 以及 getItemString().

被这些函数引用 init(), LabelFNTMultiLineAlignmentUNICODE::init() , 以及 stringChanged().

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

◆ snapArrowsToEdge()

void LabelFNTMultiLineAlignment::snapArrowsToEdge ( )

在文件 LabelTestNew.cpp793 行定义.

794{
795 this->_arrows->setPosition(Vec2(this->_label->getPosition().x + this->_label->getContentSize().width/2,
796 this->_label->getPosition().y));
797}

引用了 _arrows , 以及 _label.

被这些函数引用 alignmentChanged(), init(), LabelFNTMultiLineAlignmentUNICODE::init(), onTouchesEnded() , 以及 stringChanged().

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

◆ stringChanged()

void LabelFNTMultiLineAlignment::stringChanged ( cocos2d::Ref *  sender)

在文件 LabelTestNew.cpp735 行定义.

736{
737 auto item = (MenuItemFont*)sender;
738
739 selectSentenceItem(item);
740
741 this->snapArrowsToEdge();
742}

引用了 selectSentenceItem() , 以及 snapArrowsToEdge().

被这些函数引用 init().

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

◆ subtitle()

std::string LabelFNTMultiLineAlignment::subtitle ( ) const
overridevirtual

重载 TestCase .

LabelFNTMultiLineAlignmentUNICODE 重载.

在文件 LabelTestNew.cpp666 行定义.

667{
668 return "";
669}

◆ title()

std::string LabelFNTMultiLineAlignment::title ( ) const
overridevirtual

重载 TestCase .

LabelFNTMultiLineAlignmentUNICODE 重载.

在文件 LabelTestNew.cpp661 行定义.

662{
663 return "";
664}

类成员变量说明

◆ _arrows

cocos2d::Sprite* LabelFNTMultiLineAlignment::_arrows = nullptr
protected

在文件 LabelTestNew.h185 行定义.

被这些函数引用 init(), onTouchesBegan(), onTouchesMoved() , 以及 snapArrowsToEdge().

◆ _arrowsBar

cocos2d::Sprite* LabelFNTMultiLineAlignment::_arrowsBar = nullptr
protected

在文件 LabelTestNew.h184 行定义.

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

◆ _drag

bool LabelFNTMultiLineAlignment::_drag = false
protected

在文件 LabelTestNew.h189 行定义.

被这些函数引用 onTouchesBegan(), onTouchesEnded() , 以及 onTouchesMoved().

◆ _label

cocos2d::Label* LabelFNTMultiLineAlignment::_label = nullptr
protected

◆ _lastAlignmentItem

cocos2d::MenuItemFont* LabelFNTMultiLineAlignment::_lastAlignmentItem = nullptr
protected

在文件 LabelTestNew.h188 行定义.

被这些函数引用 selectAlignmentItem().

◆ _lastSentenceItem

cocos2d::MenuItemFont* LabelFNTMultiLineAlignment::_lastSentenceItem = nullptr
protected

在文件 LabelTestNew.h187 行定义.

被这些函数引用 selectSentenceItem().

◆ _menuItems

std::vector<cocos2d::MenuItemFont*> LabelFNTMultiLineAlignment::_menuItems
protected

在文件 LabelTestNew.h186 行定义.

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


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