예제 #1
0
void Label::updateContent()
{
    auto utf16String = cc_utf8_to_utf16(_originalUTF8String.c_str());
    setCurrentString(utf16String);
    setOriginalString(utf16String);
    if (_textSprite)
    {
        Node::removeChild(_textSprite,true);
        _textSprite = nullptr;
        if (_shadowNode)
        {
            Node::removeChild(_shadowNode,true);
            _shadowNode = nullptr;
        }
    }
    if (_fontAtlas)
    {
        alignText();
    }
    else
    {
        _fontDefinition._fontFillColor.r = _textColor.r;
        _fontDefinition._fontFillColor.g = _textColor.g;
        _fontDefinition._fontFillColor.b = _textColor.b;

        createSpriteWithFontDefinition();
    }
    _contentDirty = false;
}
예제 #2
0
 //---------------------------------------------------------------------
 //! @brief Move the top-left corner of the Label to the point
 //! designated by (_x, _y).
 //! @param[in] _x X coordinate.
 //! @param[in] _y Y coordinate.
 //---------------------------------------------------------------------
 void Label::move( float const& _x
                 , float const& _y )
 {
     x__ = _x;
     y__ = _y;
     alignText();
 }
예제 #3
0
void Label::listenToFontAtlasPurge(EventCustom *event)
{
    if (_fontAtlas && _currentLabelType == LabelType::TTF && event->getUserData() == _fontAtlas)
    {
        alignText();
    }
}
예제 #4
0
파일: CCLabel.cpp 프로젝트: KIngpon/HXGame
void Label::setLineBreakWithoutSpace(bool breakWithoutSpace)
{
    if (breakWithoutSpace != _lineBreakWithoutSpaces)
    {
        // store
        _lineBreakWithoutSpaces = breakWithoutSpace;
        
        // need to align text again
        alignText();
    }
}
예제 #5
0
파일: CCLabel.cpp 프로젝트: wade0317/Calc
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
}
예제 #6
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;
}
예제 #7
0
void Label::setString(const std::string& text)
{
    if (!_fontAtlas || _commonLineHeight <= 0)
        return ;
    
    unsigned short* utf16String = cc_utf8_to_utf16(text.c_str());
    if(!utf16String)
        return ;
    _originalUTF8String = text;
    setCurrentString(utf16String);
    setOriginalString(utf16String);
    
    // align text
    alignText();
}
예제 #8
0
파일: CCLabel.cpp 프로젝트: KIngpon/HXGame
void Label::setAlignment(TextHAlignment alignment)
{
    // store the new alignment
    if (alignment != _alignment)
    {
        // store
        _alignment = alignment;
        
        // reset the string
        resetCurrentString();
        
        // need to align text again
        alignText();
    }
}
예제 #9
0
파일: CCLabel.cpp 프로젝트: KIngpon/HXGame
void Label::setWidth(float width)
{
    if (width != _width)
    {
        // store
        _width = width;
        
        
        // reset the string
        resetCurrentString();
        
        // need to align text again
        alignText();
    }
}
예제 #10
0
void Label::setLineBreakWithoutSpace(bool breakWithoutSpace)
{
    if (breakWithoutSpace != _lineBreakWithoutSpaces)
    {
        // store
        _lineBreakWithoutSpaces = breakWithoutSpace;
        
        // need to align text again
        if(_currentUTF16String)
        {
            resetCurrentString();
            alignText();
        }
    }
}
예제 #11
0
Label::Label(FontAtlas *atlas /* = nullptr */, TextHAlignment hAlignment /* = TextHAlignment::LEFT */, 
             TextVAlignment vAlignment /* = TextVAlignment::TOP */,bool useDistanceField /* = false */,bool useA8Shader /* = false */)
: _reusedLetter(nullptr)
, _commonLineHeight(0.0f)
, _lineBreakWithoutSpaces(false)
, _maxLineWidth(0)
, _labelWidth(0)
, _labelHeight(0)
, _labelDimensions(Size::ZERO)
, _hAlignment(hAlignment)
, _vAlignment(vAlignment)
, _horizontalKernings(nullptr)
, _fontAtlas(atlas)
, _isOpacityModifyRGB(false)
, _useDistanceField(useDistanceField)
, _useA8Shader(useA8Shader)
, _fontScale(1.0f)
, _uniformEffectColor(0)
, _currNumLines(-1)
, _textSprite(nullptr)
, _contentDirty(false)
, _shadowDirty(false)
, _compatibleMode(false)
, _insideBounds(true)
, _effectColorF(Color4F::BLACK)
{
    setAnchorPoint(Vec2::ANCHOR_MIDDLE);
    reset();

#if CC_ENABLE_CACHE_TEXTURE_DATA
    auto toBackgroundListener = EventListenerCustom::create(EVENT_COME_TO_BACKGROUND, [this](EventCustom* event){
        if (_fontAtlas && _currentLabelType == LabelType::TTF)
        {
            _batchNodes.clear();
            _batchNodes.push_back(this);
            Node::removeAllChildrenWithCleanup(true);
        }
    });
    _eventDispatcher->addEventListenerWithSceneGraphPriority(toBackgroundListener, this);
#endif
    auto purgeTextureListener = EventListenerCustom::create(FontAtlas::EVENT_PURGE_TEXTURES, [this](EventCustom* event){
        if (_fontAtlas && _currentLabelType == LabelType::TTF && event->getUserData() == _fontAtlas)
        {
            alignText();
        }
    });
    _eventDispatcher->addEventListenerWithSceneGraphPriority(purgeTextureListener, this);
}
예제 #12
0
void SkPDFDevice::drawPosText(const SkDraw&, const void* text, size_t len,
                              const SkScalar pos[], SkScalar constY,
                              int scalarsPerPos, const SkPaint& paint) {
    SkASSERT(1 == scalarsPerPos || 2 == scalarsPerPos);
    SkPaint textPaint = calculateTextPaint(paint);
    updateGSFromPaint(textPaint, true);

    // Make sure we have a glyph id encoding.
    SkAutoFree glyphStorage;
    uint16_t* glyphIDs;
    size_t numGlyphs;
    if (paint.getTextEncoding() != SkPaint::kGlyphID_TextEncoding) {
        numGlyphs = paint.textToGlyphs(text, len, NULL);
        glyphIDs = (uint16_t*)sk_malloc_flags(numGlyphs * 2,
                                              SK_MALLOC_TEMP | SK_MALLOC_THROW);
        glyphStorage.set(glyphIDs);
        paint.textToGlyphs(text, len, glyphIDs);
        textPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
    } else {
        SkASSERT((len & 1) == 0);
        numGlyphs = len / 2;
        glyphIDs = (uint16_t*)text;
    }

    SkDrawCacheProc glyphCacheProc = textPaint.getDrawCacheProc();
    fContent.writeText("BT\n");
    updateFont(textPaint, glyphIDs[0]);
    for (size_t i = 0; i < numGlyphs; i++) {
        SkPDFFont* font = fGraphicStack[fGraphicStackIndex].fFont;
        uint16_t encodedValue = glyphIDs[i];
        if (font->glyphsToPDFFontEncoding(&encodedValue, 1) != 1) {
            updateFont(textPaint, glyphIDs[i]);
            i--;
            continue;
        }
        SkScalar x = pos[i * scalarsPerPos];
        SkScalar y = scalarsPerPos == 1 ? constY : pos[i * scalarsPerPos + 1];
        alignText(glyphCacheProc, textPaint, glyphIDs + i, 1, &x, &y, NULL);
        setTextTransform(x, y, textPaint.getTextSkewX());
        SkString encodedString =
            SkPDFString::formatString(&encodedValue, 1,
                                      font->multiByteGlyphs());
        fContent.writeText(encodedString.c_str());
        fContent.writeText(" Tj\n");
    }
    fContent.writeText("ET\n");
}
예제 #13
0
파일: Button.cpp 프로젝트: ZwodahS/LD28
 void Button::updatePosition()
 {
     if(_buttonType == TSB || _buttonType == TSTB || _buttonType == MSTB)
     {
         // update all sprite position
         for(std::vector<sf::Sprite>::iterator it = _sprites.begin() ; it != _sprites.end() ; ++it)
         {
             (*it).setPosition(_clickBound.left, _clickBound.top);
         }
     }
     if(_buttonType == TSTB || _buttonType == MSTB)
     {
         sf::FloatRect p = _texts[0].getGlobalBounds();
         alignText(_texts[0], _clickBound, _textPositionData);
         p = _texts[0].getGlobalBounds();
     }
 }
예제 #14
0
void Label::setMaxLineWidth(float width)
{
    if (width != _maxLineWidth)
    {
        // store
        _maxLineWidth = width;
        
        if (_currentUTF16String)
        {
            // reset the string
            resetCurrentString();

            // need to align text again
            alignText();
        }
    }
}
예제 #15
0
        //---------------------------------------------------------------------
        //! @brief Set the text to display in the Label.
        //! @param[in] _text The text to display.
        //---------------------------------------------------------------------
        void Label::setText( std::string const& _text )
        {
            text__ = _text;
            evas_object_text_text_set( label__
                                     , text__.c_str() );

            int end_char_pos = evas_object_text_last_up_to_pos( label__
                                                              , width__
                                                              , height__ / 2 );
            if( end_char_pos > 0 )
            {
                String short_text = _text.substr( 0
                                                , end_char_pos - 2 ) + "...";
                evas_object_text_text_set( label__
                                         , short_text.c_str() );
            }

            alignText();
        }
예제 #16
0
파일: CCLabel.cpp 프로젝트: KIngpon/HXGame
bool Label::setText(const char *stringToRender, float lineWidth, TextHAlignment alignment, bool lineBreakWithoutSpaces)
{
    if (!_fontAtlas)
        return false;
    
    // carloX
    // reset the string
    resetCurrentString();
    
    
    _width                  = lineWidth;
    _alignment              = alignment;
    _lineBreakWithoutSpaces = lineBreakWithoutSpaces;
    
    // release all the sprites
    moveAllSpritesToCache();
    
    // store locally common line height
    _commonLineHeight = _fontAtlas->getCommonLineHeight();
    if (_commonLineHeight <= 0)
        return false;
    
    int numLetter = 0;
    unsigned short* utf16String = cc_utf8_to_utf16(stringToRender);
    if(!utf16String)
        return false;
    
    numLetter = cc_wcslen(utf16String);
    SpriteBatchNode::initWithTexture(&_fontAtlas->getTexture(0), numLetter);
    _cascadeColorEnabled = true;
    
    //
    setCurrentString(utf16String);
    setOriginalString(utf16String);
    
    // align text
    alignText();
    
    // done here
    return true;
}
예제 #17
0
bool Label::initWithFontAtlas(FontAtlas* atlas,bool distanceFieldEnabled /* = false */, bool useA8Shader /* = false */)
{
    FontAtlas *oldAtlas = _fontAtlas;
    bool oldDistanceFieldEnable = _useDistanceField;
    bool oldA8ShaderEnabel = _useA8Shader;

    _fontAtlas = atlas;
    _useDistanceField = distanceFieldEnabled;
    _useA8Shader = useA8Shader;

    bool ret = Label::init();
    if (oldAtlas)
    {
        if (ret)
        {
            FontAtlasCache::releaseFontAtlas(oldAtlas);        
        }
        else
        {
            _fontAtlas = oldAtlas;
            _useDistanceField = oldDistanceFieldEnable;
            _useA8Shader = oldA8ShaderEnabel;
            Label::init();

            FontAtlasCache::releaseFontAtlas(atlas);
        }
    }

    if (_fontAtlas)
    {
        _commonLineHeight = _fontAtlas->getCommonLineHeight();
        if(_currentUTF16String)
        {
            resetCurrentString();
            alignText();
        }
    }

    return ret;
}
예제 #18
0
void SkPDFDevice::drawText(const SkDraw& d, const void* text, size_t len,
                           SkScalar x, SkScalar y, const SkPaint& paint) {
    SkPaint textPaint = calculateTextPaint(paint);
    updateGSFromPaint(textPaint, true);

    // We want the text in glyph id encoding and a writable buffer, so we end
    // up making a copy either way.
    size_t numGlyphs = paint.textToGlyphs(text, len, NULL);
    uint16_t* glyphIDs =
        (uint16_t*)sk_malloc_flags(numGlyphs * 2,
                                   SK_MALLOC_TEMP | SK_MALLOC_THROW);
    SkAutoFree autoFreeGlyphIDs(glyphIDs);
    if (paint.getTextEncoding() != SkPaint::kGlyphID_TextEncoding) {
        paint.textToGlyphs(text, len, glyphIDs);
        textPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
    } else {
        SkASSERT((len & 1) == 0);
        SkASSERT(len / 2 == numGlyphs);
        memcpy(glyphIDs, text, len);
    }

    SkScalar width;
    SkScalar* widthPtr = NULL;
    if (textPaint.isUnderlineText() || textPaint.isStrikeThruText())
        widthPtr = &width;

    SkDrawCacheProc glyphCacheProc = textPaint.getDrawCacheProc();
    alignText(glyphCacheProc, textPaint, glyphIDs, numGlyphs, &x, &y, widthPtr);
    fContent.writeText("BT\n");
    setTextTransform(x, y, textPaint.getTextSkewX());
    size_t consumedGlyphCount = 0;
    while (numGlyphs > consumedGlyphCount) {
        updateFont(textPaint, glyphIDs[consumedGlyphCount]);
        SkPDFFont* font = fGraphicStack[fGraphicStackIndex].fFont;
        size_t availableGlyphs =
            font->glyphsToPDFFontEncoding(glyphIDs + consumedGlyphCount,
                                          numGlyphs - consumedGlyphCount);
        SkString encodedString =
            SkPDFString::formatString(glyphIDs + consumedGlyphCount,
                                      availableGlyphs, font->multiByteGlyphs());
        fContent.writeText(encodedString.c_str());
        consumedGlyphCount += availableGlyphs;
        fContent.writeText(" Tj\n");
    }
    fContent.writeText("ET\n");

    // Draw underline and/or strikethrough if the paint has them.
    // drawPosText() and drawTextOnPath() don't draw underline or strikethrough
    // because the raster versions don't.  Use paint instead of textPaint
    // because we may have changed strokeWidth to do fakeBold text.
    if (paint.isUnderlineText() || paint.isStrikeThruText()) {
        SkScalar textSize = paint.getTextSize();
        SkScalar height = SkScalarMul(textSize, kStdUnderline_Thickness);

        if (paint.isUnderlineText()) {
            SkScalar top = SkScalarMulAdd(textSize, kStdUnderline_Offset, y);
            SkRect r = SkRect::MakeXYWH(x, top - height, width, height);
            drawRect(d, r, paint);
        }
        if (paint.isStrikeThruText()) {
            SkScalar top = SkScalarMulAdd(textSize, kStdStrikeThru_Offset, y);
            SkRect r = SkRect::MakeXYWH(x, top - height, width, height);
            drawRect(d, r, paint);
        }
    }
}
예제 #19
0
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;
}
예제 #20
0
파일: CCLabel.cpp 프로젝트: KIngpon/HXGame
void Label::setScaleY(float scaleY)
{
    Node::setScaleY(scaleY);
    alignText();
}
예제 #21
0
파일: CCLabel.cpp 프로젝트: KIngpon/HXGame
void Label::setScaleX(float scaleX)
{
    Node::setScaleX(scaleX);
    alignText();
}
예제 #22
0
파일: CCLabel.cpp 프로젝트: KIngpon/HXGame
void Label::setScale(float scale)
{
    Node::setScale(scale);
    alignText();
}
예제 #23
0
void Label::updateContent()
{
    auto utf16String = cc_utf8_to_utf16(_originalUTF8String.c_str());
    setCurrentString(utf16String);
    setOriginalString(utf16String);

    if (_textSprite)
    {
        Node::removeChild(_textSprite,true);
        _textSprite = nullptr;
        if (_shadowNode)
        {
            Node::removeChild(_shadowNode,true);
            _shadowNode = nullptr;
        }
    }

    if (_fontAtlas)
    {
        alignText();
    }
    else
    {
        _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;
}