From eadbca8ee788e3a02afa040ca953b3c3660d9b91 Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Tue, 1 Apr 2014 14:15:35 +0800 Subject: [PATCH] 1.fixed logical error in Label::enableShadow. 2.Add test case for shadow and outline take effect at the same time. --- cocos/2d/CCLabel.cpp | 19 +++++++------------ cocos/2d/CCLabel.h | 1 + .../Classes/LabelTest/LabelTestNew.cpp | 14 +++++++++++--- .../Classes/LabelTest/LabelTestNew.h | 1 + 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/cocos/2d/CCLabel.cpp b/cocos/2d/CCLabel.cpp index 5293c9f9bf..4a6d110979 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -871,15 +871,10 @@ void Label::enableShadow(const Color4B& shadowColor /* = Color4B::BLACK */,const _fontDefinition._shadow._shadowEnabled = false; _shadowDirty = true; - _effectColor = shadowColor; - _effectColorF.r = _effectColor.r / 255.0f; - _effectColorF.g = _effectColor.g / 255.0f; - _effectColorF.b = _effectColor.b / 255.0f; - _effectColorF.a = _effectColor.a / 255.0f; - - _shadowColor.r = _effectColor.r; - _shadowColor.g = _effectColor.g; - _shadowColor.b = _effectColor.b; + _shadowColor.r = shadowColor.r; + _shadowColor.g = shadowColor.g; + _shadowColor.b = shadowColor.b; + _shadowOpacity = shadowColor.a / 255.0f; auto contentScaleFactor = CC_CONTENT_SCALE_FACTOR(); _shadowOffset.width = offset.width * contentScaleFactor; @@ -890,7 +885,7 @@ void Label::enableShadow(const Color4B& shadowColor /* = Color4B::BLACK */,const if (_textSprite && _shadowNode) { _shadowNode->setColor(_shadowColor); - _shadowNode->setOpacity(_effectColorF.a * _displayedOpacity); + _shadowNode->setOpacity(_shadowOpacity * _displayedOpacity); _shadowNode->setPosition(_shadowOffset.width, _shadowOffset.height); } } @@ -970,7 +965,7 @@ void Label::drawShadowWithoutBlur() { Color3B oldColor = _realColor; GLubyte oldOPacity = _displayedOpacity; - _displayedOpacity = _effectColorF.a * _displayedOpacity; + _displayedOpacity = _shadowOpacity * _displayedOpacity; setColor(_shadowColor); _shaderProgram->setUniformsForBuiltins(_shadowTransform); @@ -1093,7 +1088,7 @@ void Label::drawTextSprite(Renderer *renderer, bool parentTransformUpdated) } _shadowNode->setAnchorPoint(Point::ANCHOR_BOTTOM_LEFT); _shadowNode->setColor(_shadowColor); - _shadowNode->setOpacity(_effectColorF.a * _displayedOpacity); + _shadowNode->setOpacity(_shadowOpacity * _displayedOpacity); _shadowNode->setPosition(_shadowOffset.width, _shadowOffset.height); Node::addChild(_shadowNode,0,Node::INVALID_TAG); } diff --git a/cocos/2d/CCLabel.h b/cocos/2d/CCLabel.h index 38cfa07073..6e042e7caf 100644 --- a/cocos/2d/CCLabel.h +++ b/cocos/2d/CCLabel.h @@ -376,6 +376,7 @@ protected: int _shadowBlurRadius; kmMat4 _shadowTransform; Color3B _shadowColor; + float _shadowOpacity; Sprite* _shadowNode; Color4B _textColor; diff --git a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp index 152e76577e..f7c3bf99db 100644 --- a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp +++ b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp @@ -1308,14 +1308,21 @@ LabelShadowTest::LabelShadowTest() TTFConfig ttfConfig("fonts/arial.ttf", 40, GlyphCollection::DYNAMIC,nullptr,true); - shadowLabelTTF = Label::createWithTTF(ttfConfig,"TTF:Shadow", TextHAlignment::CENTER, size.width); - shadowLabelTTF->setPosition( Point(size.width/2, size.height*0.6f) ); + shadowLabelTTF = Label::createWithTTF(ttfConfig,"TTF:Shadow"); + shadowLabelTTF->setPosition( Point(size.width/2, size.height*0.65f) ); shadowLabelTTF->setTextColor( Color4B::RED ); shadowLabelTTF->enableShadow(Color4B::BLACK); addChild(shadowLabelTTF); + shadowLabelOutline = Label::createWithTTF(ttfConfig,"TTF:Shadow"); + shadowLabelOutline->setPosition( Point(size.width/2, size.height*0.5f) ); + shadowLabelOutline->setTextColor( Color4B::RED ); + shadowLabelOutline->enableOutline(Color4B::YELLOW,1); + shadowLabelOutline->enableShadow(Color4B::BLACK); + addChild(shadowLabelOutline); + shadowLabelBMFont = Label::createWithBMFont("fonts/bitmapFontTest.fnt", "BMFont:Shadow"); - shadowLabelBMFont->setPosition( Point(size.width/2, size.height*0.4f) ); + shadowLabelBMFont->setPosition( Point(size.width/2, size.height*0.35f) ); shadowLabelBMFont->setColor( Color3B::RED ); shadowLabelBMFont->enableShadow(Color4B::GREEN); addChild(shadowLabelBMFont); @@ -1354,6 +1361,7 @@ void LabelShadowTest::sliderEvent(Ref *pSender, ui::SliderEventType type) auto offset = Size(slider->getPercent()-50,50 - slider2->getPercent()); shadowLabelTTF->enableShadow(Color4B::BLACK,offset); shadowLabelBMFont->enableShadow(Color4B::GREEN,offset); + shadowLabelOutline->enableShadow(Color4B::BLACK,offset); } } diff --git a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.h b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.h index 7ea2f570e3..d0ee7b8bea 100644 --- a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.h +++ b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.h @@ -374,6 +374,7 @@ public: void sliderEvent(Ref *pSender, ui::SliderEventType type); private: + Label* shadowLabelOutline; Label* shadowLabelTTF; Label* shadowLabelBMFont; };