| 613 | static float menuItemPaddingCenter = 50; |
| 614 | |
| 615 | bool LabelFNTMultiLineAlignment::init() |
| 616 | { |
| 617 | if (!AtlasDemoNew::init()) |
| 618 | { |
| 619 | return false; |
| 620 | } |
| 621 | |
| 622 | auto listener = EventListenerTouchAllAtOnce::create(); |
| 623 | listener->onTouchesBegan = AX_CALLBACK_2(LabelFNTMultiLineAlignment::onTouchesBegan, this); |
| 624 | listener->onTouchesMoved = AX_CALLBACK_2(LabelFNTMultiLineAlignment::onTouchesMoved, this); |
| 625 | listener->onTouchesEnded = AX_CALLBACK_2(LabelFNTMultiLineAlignment::onTouchesEnded, this); |
| 626 | |
| 627 | _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); |
| 628 | // ask director the the window size |
| 629 | auto size = Director::getInstance()->getWinSize(); |
| 630 | |
| 631 | // create and initialize a Label |
| 632 | this->_label = Label::createWithBMFont("fonts/markerFelt.fnt", "", TextHAlignment::CENTER, size.width / 1.5); |
| 633 | |
| 634 | this->_arrowsBar = Sprite::create("Images/arrowsBar.png"); |
| 635 | this->_arrows = Sprite::create("Images/arrows.png"); |
| 636 | |
| 637 | MenuItemFont::setFontSize(20); |
| 638 | auto longSentences = |
| 639 | MenuItemFont::create("Long Flowing Sentences", AX_CALLBACK_1(LabelFNTMultiLineAlignment::stringChanged, this)); |
| 640 | auto lineBreaks = MenuItemFont::create("Short Sentences With Intentional Line Breaks", |
| 641 | AX_CALLBACK_1(LabelFNTMultiLineAlignment::stringChanged, this)); |
| 642 | auto mixed = MenuItemFont::create("Long Sentences Mixed With Intentional Line Breaks", |
| 643 | AX_CALLBACK_1(LabelFNTMultiLineAlignment::stringChanged, this)); |
| 644 | auto stringMenu = Menu::create(longSentences, lineBreaks, mixed, nullptr); |
| 645 | stringMenu->alignItemsVertically(); |
| 646 | |
| 647 | longSentences->setTag(LongSentences); |
| 648 | lineBreaks->setTag(LineBreaks); |
| 649 | mixed->setTag(Mixed); |
| 650 | |
| 651 | _menuItems.emplace_back(longSentences); |
| 652 | _menuItems.emplace_back(lineBreaks); |
| 653 | _menuItems.emplace_back(mixed); |
| 654 | |
| 655 | MenuItemFont::setFontSize(30); |
| 656 | |
| 657 | auto left = MenuItemFont::create("Left", AX_CALLBACK_1(LabelFNTMultiLineAlignment::alignmentChanged, this)); |
| 658 | auto center = MenuItemFont::create("Center", AX_CALLBACK_1(LabelFNTMultiLineAlignment::alignmentChanged, this)); |
| 659 | auto right = MenuItemFont::create("Right", AX_CALLBACK_1(LabelFNTMultiLineAlignment::alignmentChanged, this)); |
| 660 | |
| 661 | auto alignmentMenu = Menu::create(left, center, right, nullptr); |
| 662 | alignmentMenu->alignItemsHorizontallyWithPadding(alignmentItemPadding); |
| 663 | |
| 664 | left->setTag(LeftAlign); |
| 665 | center->setTag(CenterAlign); |
| 666 | right->setTag(RightAlign); |
| 667 | |
| 668 | // position the label on the center of the screen |
| 669 | this->_label->setPosition(Vec2(size.width / 2, size.height / 2)); |
| 670 | |
| 671 | this->_arrowsBar->setVisible(false); |
| 672 |
nothing calls this directly
no test coverage detected