bool Label::setCurrentString(unsigned short *stringToSet) { // set the new string if (_currentUTF16String) { delete [] _currentUTF16String; } _currentUTF16String = stringToSet; computeStringNumLines(); // compute the advances return computeHorizontalKernings(stringToSet); }
int Label::getStringNumLines() { if (_contentDirty) { updateContent(); } if (_currentLabelType == LabelType::STRING_TEXTURE) { computeStringNumLines(); } return _numberOfLines; }
void Label::updateContent() { if (_systemFontDirty) { if (_fontAtlas) { _batchNodes.clear(); _batchNodes.push_back(this); FontAtlasCache::releaseFontAtlas(_fontAtlas); _fontAtlas = nullptr; } _systemFontDirty = false; } if (_textSprite) { Node::removeChild(_textSprite, true); _textSprite = nullptr; if (_shadowNode) { Node::removeChild(_shadowNode, true); _shadowNode = nullptr; } } if (_fontAtlas) { std::u16string utf16String; if (StringUtils::UTF8ToUTF16(_originalUTF8String, utf16String)) { _currentUTF16String = utf16String; } computeStringNumLines(); computeHorizontalKernings(_currentUTF16String); alignText(); } else { createSpriteForSystemFont(); if (_shadowEnabled) { createShadowSpriteForSystemFont(); } } _contentDirty = false; }
void Label::updateContent() { std::u16string utf16String; if (StringUtils::UTF8ToUTF16(_originalUTF8String, utf16String)) { _currentUTF16String = utf16String; } computeStringNumLines(); if (_fontAtlas) { computeHorizontalKernings(_currentUTF16String); } if (_textSprite) { Node::removeChild(_textSprite,true); _textSprite = nullptr; if (_shadowNode) { Node::removeChild(_shadowNode,true); _shadowNode = nullptr; } } if (_fontAtlas) { alignText(); } else { if (!_compatibleMode) { _fontDefinition._fontName = _systemFont; _fontDefinition._fontSize = _systemFontSize; _fontDefinition._alignment = _hAlignment; _fontDefinition._vertAlignment = _vAlignment; _fontDefinition._dimensions.width = _labelWidth; _fontDefinition._dimensions.height = _labelHeight; _fontDefinition._fontFillColor.r = _textColor.r; _fontDefinition._fontFillColor.g = _textColor.g; _fontDefinition._fontFillColor.b = _textColor.b; _fontDefinition._shadow._shadowEnabled = false; if (_currLabelEffect == LabelEffect::OUTLINE && _outlineSize > 0) { _fontDefinition._stroke._strokeEnabled = true; _fontDefinition._stroke._strokeSize = _outlineSize; _fontDefinition._stroke._strokeColor.r = _effectColor.r; _fontDefinition._stroke._strokeColor.g = _effectColor.g; _fontDefinition._stroke._strokeColor.b = _effectColor.b; } else { _fontDefinition._stroke._strokeEnabled = false; } #if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID) && (CC_TARGET_PLATFORM != CC_PLATFORM_IOS) if (_fontDefinition._stroke._strokeEnabled) { CCLOGERROR("Currently only supported on iOS and Android!"); } _fontDefinition._stroke._strokeEnabled = false; #endif } createSpriteWithFontDefinition(); } _contentDirty = false; }