Example #1
0
void Label::enableShadow(const Color4B& shadowColor /* = Color4B::BLACK */,const Size &offset /* = Size(2 ,-2)*/, int blurRadius /* = 0 */)
{
    _shadowEnabled = true;
    _shadowDirty = true;

    auto contentScaleFactor = CC_CONTENT_SCALE_FACTOR();
    _shadowOffset.width = offset.width * contentScaleFactor;
    _shadowOffset.height = offset.height * contentScaleFactor;
    //TODO: support blur for shadow
    _shadowBlurRadius = 0;

    if (_textSprite && _shadowNode)
    {
        if (shadowColor != _shadowColor)
        {
            Node::removeChild(_shadowNode, true);
            _shadowNode = nullptr;
            createShadowSpriteForSystemFont();
        }
        else
        {
            _shadowNode->setPosition(_shadowOffset.width, _shadowOffset.height);
        }
    }

    _shadowColor.r = shadowColor.r / 255.0f;
    _shadowColor.g = shadowColor.g / 255.0f;
    _shadowColor.b = shadowColor.b / 255.0f;
    _shadowColor.a = shadowColor.a / 255.0f;
}
Example #2
0
void Label::updateContent()
{
    if (_systemFontDirty)
    {
        if (_fontAtlas)
        {
            _batchNodes.clear();

            FontAtlasCache::releaseFontAtlas(_fontAtlas);
            _fontAtlas = nullptr;
        }

        _systemFontDirty = false;
    }

    CC_SAFE_RELEASE_NULL(_textSprite);
    CC_SAFE_RELEASE_NULL(_shadowNode);

    if (_fontAtlas)
    {
        std::u16string utf16String;
        if (StringUtils::UTF8ToUTF16(_utf8Text, utf16String))
        {
            _utf16Text = utf16String;
        }

        computeHorizontalKernings(_utf16Text);
        alignText();
    }
    else
    {
        auto fontDef = _getFontDefinition();
        createSpriteForSystemFont(fontDef);
        if (_shadowEnabled)
        {
            createShadowSpriteForSystemFont(fontDef);
        }
    }
    _contentDirty = false;

#if CC_LABEL_DEBUG_DRAW
    _debugDrawNode->clear();
    Vec2 vertices[4] =
    {
        Vec2::ZERO,
        Vec2(_contentSize.width, 0),
        Vec2(_contentSize.width, _contentSize.height),
        Vec2(0, _contentSize.height)
    };
    _debugDrawNode->drawPoly(vertices, 4, true, Color4F::WHITE);
#endif
}
Example #3
0
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;
}