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

Method updateContent

core/2d/Label.cpp:1795–1910  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1793}
1794
1795void Label::updateContent()
1796{
1797 clearTextures();
1798
1799 if (_fontAtlas)
1800 {
1801 alignText();
1802 }
1803 else
1804 {
1805 auto fontDef = _getFontDefinition();
1806 createSpriteForSystemFont(fontDef);
1807 if (_shadowEnabled)
1808 {
1809 createShadowSpriteForSystemFont(fontDef);
1810 }
1811 }
1812
1813 if (_lineDrawNode)
1814 {
1815 Color4B lineColor = Color4B(_displayedColor);
1816 if (_textColor != Color4B::WHITE && _textColor != lineColor)
1817 lineColor = _textColor;
1818
1819 _lineDrawNode->clear();
1820
1821 if (_numberOfLines > 0 && _currentLabelType != LabelType::STRING_TEXTURE)
1822 {
1823 // This is the logic for TTF fonts
1824 float thickness = std::max(std::ceil(_lineHeight * _fontScale * 0.12f * 2) / 2.f, 2.f);
1825 float nextY = _letterOffsetY;
1826 auto contentScaleFactor = AX_CONTENT_SCALE_FACTOR();
1827 float lineSpacing = _lineSpacing;
1828 float lineHeight = _lineHeight * _fontScale / contentScaleFactor;
1829
1830 // atlas font
1831 for (int i = 0; i < _numberOfLines; ++i)
1832 {
1833 float startOffset = 0;
1834 float endOffset = 0;
1835
1836 if (_overflow == Overflow::CLAMP)
1837 {
1838 startOffset = std::max(0.f, _linesOffsetX[i]);
1839 if (_hAlignment == TextHAlignment::LEFT || _hAlignment == TextHAlignment::CENTER)
1840 {
1841 endOffset = std::min(_linesWidth[i] + startOffset, _labelDimensions.width - startOffset);
1842 }
1843 else // _hAlignment == TextHAlignment::RIGHT
1844 {
1845 endOffset = std::min(_linesWidth[i] + startOffset, _labelDimensions.width);
1846 }
1847 }
1848 else
1849 {
1850 startOffset = _linesOffsetX[i];
1851 endOffset = _linesWidth[i] + _linesOffsetX[i];
1852 }

Callers 1

drawMethod · 0.80

Calls 9

Color4BFunction · 0.85
drawPolyMethod · 0.80
Vec2Class · 0.70
maxFunction · 0.50
minFunction · 0.50
Color4FFunction · 0.50
clearMethod · 0.45
drawLineMethod · 0.45
getContentSizeMethod · 0.45

Tested by

no test coverage detected