MCPcopy Create free account
hub / github.com/axmolengine/axmol / showFont

Method showFont

tests/cpp-tests/Source/FontTest/FontTest.cpp:85–139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83}
84
85void FontTest::showFont(std::string_view fontFile)
86{
87 auto s = Director::getInstance()->getWinSize();
88
89 auto blockSize = Size(s.width / 3, 200);
90 float fontSize = 26;
91
92 removeChildByTag(kTagLabel1, true);
93 removeChildByTag(kTagLabel2, true);
94 removeChildByTag(kTagLabel3, true);
95 removeChildByTag(kTagLabel4, true);
96 removeChildByTag(kTagColor1, true);
97 removeChildByTag(kTagColor2, true);
98 removeChildByTag(kTagColor3, true);
99
100 auto top = Label::createWithSystemFont(fontFile, fontFile, 24);
101 auto left = Label::createWithSystemFont("alignment left", fontFile, fontSize, blockSize, TextHAlignment::LEFT,
102 verticalAlignment[vAlignIdx]);
103 auto center = Label::createWithSystemFont("alignment center", fontFile, fontSize, blockSize, TextHAlignment::CENTER,
104 verticalAlignment[vAlignIdx]);
105 auto right = Label::createWithSystemFont("alignment right", fontFile, fontSize, blockSize, TextHAlignment::RIGHT,
106 verticalAlignment[vAlignIdx]);
107
108 auto leftColor = LayerColor::create(Color4B(100, 100, 100, 255), blockSize.width, blockSize.height);
109 auto centerColor = LayerColor::create(Color4B(200, 100, 100, 255), blockSize.width, blockSize.height);
110 auto rightColor = LayerColor::create(Color4B(100, 100, 200, 255), blockSize.width, blockSize.height);
111
112 leftColor->setIgnoreAnchorPointForPosition(false);
113 centerColor->setIgnoreAnchorPointForPosition(false);
114 rightColor->setIgnoreAnchorPointForPosition(false);
115
116 top->setAnchorPoint(Vec2(0.5, 1));
117 left->setAnchorPoint(Vec2(0, 0.5));
118 leftColor->setAnchorPoint(Vec2(0, 0.5));
119 center->setAnchorPoint(Vec2(0, 0.5));
120 centerColor->setAnchorPoint(Vec2(0, 0.5));
121 right->setAnchorPoint(Vec2(0, 0.5));
122 rightColor->setAnchorPoint(Vec2(0, 0.5));
123
124 top->setPosition(s.width / 2, s.height - 20);
125 left->setPosition(0, s.height / 2);
126 leftColor->setPosition(left->getPosition());
127 center->setPosition(blockSize.width, s.height / 2);
128 centerColor->setPosition(center->getPosition());
129 right->setPosition(blockSize.width * 2, s.height / 2);
130 rightColor->setPosition(right->getPosition());
131
132 this->addChild(leftColor, -1, kTagColor1);
133 this->addChild(left, 0, kTagLabel1);
134 this->addChild(rightColor, -1, kTagColor2);
135 this->addChild(right, 0, kTagLabel2);
136 this->addChild(centerColor, -1, kTagColor3);
137 this->addChild(center, 0, kTagLabel3);
138 this->addChild(top, 0, kTagLabel4);
139}
140
141std::string FontTest::title() const
142{

Callers 1

createMethod · 0.80

Calls 10

getInstanceFunction · 0.85
createFunction · 0.85
Color4BFunction · 0.85
SizeFunction · 0.50
Vec2Function · 0.50
setAnchorPointMethod · 0.45
setPositionMethod · 0.45
getPositionMethod · 0.45
addChildMethod · 0.45

Tested by

no test coverage detected