mirror of https://github.com/axmolengine/axmol.git
1.fixed logical error in Label::enableShadow.
2.Add test case for shadow and outline take effect at the same time.
This commit is contained in:
parent
3a556c24aa
commit
eadbca8ee7
|
@ -871,15 +871,10 @@ void Label::enableShadow(const Color4B& shadowColor /* = Color4B::BLACK */,const
|
||||||
_fontDefinition._shadow._shadowEnabled = false;
|
_fontDefinition._shadow._shadowEnabled = false;
|
||||||
_shadowDirty = true;
|
_shadowDirty = true;
|
||||||
|
|
||||||
_effectColor = shadowColor;
|
_shadowColor.r = shadowColor.r;
|
||||||
_effectColorF.r = _effectColor.r / 255.0f;
|
_shadowColor.g = shadowColor.g;
|
||||||
_effectColorF.g = _effectColor.g / 255.0f;
|
_shadowColor.b = shadowColor.b;
|
||||||
_effectColorF.b = _effectColor.b / 255.0f;
|
_shadowOpacity = shadowColor.a / 255.0f;
|
||||||
_effectColorF.a = _effectColor.a / 255.0f;
|
|
||||||
|
|
||||||
_shadowColor.r = _effectColor.r;
|
|
||||||
_shadowColor.g = _effectColor.g;
|
|
||||||
_shadowColor.b = _effectColor.b;
|
|
||||||
|
|
||||||
auto contentScaleFactor = CC_CONTENT_SCALE_FACTOR();
|
auto contentScaleFactor = CC_CONTENT_SCALE_FACTOR();
|
||||||
_shadowOffset.width = offset.width * contentScaleFactor;
|
_shadowOffset.width = offset.width * contentScaleFactor;
|
||||||
|
@ -890,7 +885,7 @@ void Label::enableShadow(const Color4B& shadowColor /* = Color4B::BLACK */,const
|
||||||
if (_textSprite && _shadowNode)
|
if (_textSprite && _shadowNode)
|
||||||
{
|
{
|
||||||
_shadowNode->setColor(_shadowColor);
|
_shadowNode->setColor(_shadowColor);
|
||||||
_shadowNode->setOpacity(_effectColorF.a * _displayedOpacity);
|
_shadowNode->setOpacity(_shadowOpacity * _displayedOpacity);
|
||||||
_shadowNode->setPosition(_shadowOffset.width, _shadowOffset.height);
|
_shadowNode->setPosition(_shadowOffset.width, _shadowOffset.height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -970,7 +965,7 @@ void Label::drawShadowWithoutBlur()
|
||||||
{
|
{
|
||||||
Color3B oldColor = _realColor;
|
Color3B oldColor = _realColor;
|
||||||
GLubyte oldOPacity = _displayedOpacity;
|
GLubyte oldOPacity = _displayedOpacity;
|
||||||
_displayedOpacity = _effectColorF.a * _displayedOpacity;
|
_displayedOpacity = _shadowOpacity * _displayedOpacity;
|
||||||
setColor(_shadowColor);
|
setColor(_shadowColor);
|
||||||
|
|
||||||
_shaderProgram->setUniformsForBuiltins(_shadowTransform);
|
_shaderProgram->setUniformsForBuiltins(_shadowTransform);
|
||||||
|
@ -1093,7 +1088,7 @@ void Label::drawTextSprite(Renderer *renderer, bool parentTransformUpdated)
|
||||||
}
|
}
|
||||||
_shadowNode->setAnchorPoint(Point::ANCHOR_BOTTOM_LEFT);
|
_shadowNode->setAnchorPoint(Point::ANCHOR_BOTTOM_LEFT);
|
||||||
_shadowNode->setColor(_shadowColor);
|
_shadowNode->setColor(_shadowColor);
|
||||||
_shadowNode->setOpacity(_effectColorF.a * _displayedOpacity);
|
_shadowNode->setOpacity(_shadowOpacity * _displayedOpacity);
|
||||||
_shadowNode->setPosition(_shadowOffset.width, _shadowOffset.height);
|
_shadowNode->setPosition(_shadowOffset.width, _shadowOffset.height);
|
||||||
Node::addChild(_shadowNode,0,Node::INVALID_TAG);
|
Node::addChild(_shadowNode,0,Node::INVALID_TAG);
|
||||||
}
|
}
|
||||||
|
|
|
@ -376,6 +376,7 @@ protected:
|
||||||
int _shadowBlurRadius;
|
int _shadowBlurRadius;
|
||||||
kmMat4 _shadowTransform;
|
kmMat4 _shadowTransform;
|
||||||
Color3B _shadowColor;
|
Color3B _shadowColor;
|
||||||
|
float _shadowOpacity;
|
||||||
Sprite* _shadowNode;
|
Sprite* _shadowNode;
|
||||||
|
|
||||||
Color4B _textColor;
|
Color4B _textColor;
|
||||||
|
|
|
@ -1308,14 +1308,21 @@ LabelShadowTest::LabelShadowTest()
|
||||||
|
|
||||||
TTFConfig ttfConfig("fonts/arial.ttf", 40, GlyphCollection::DYNAMIC,nullptr,true);
|
TTFConfig ttfConfig("fonts/arial.ttf", 40, GlyphCollection::DYNAMIC,nullptr,true);
|
||||||
|
|
||||||
shadowLabelTTF = Label::createWithTTF(ttfConfig,"TTF:Shadow", TextHAlignment::CENTER, size.width);
|
shadowLabelTTF = Label::createWithTTF(ttfConfig,"TTF:Shadow");
|
||||||
shadowLabelTTF->setPosition( Point(size.width/2, size.height*0.6f) );
|
shadowLabelTTF->setPosition( Point(size.width/2, size.height*0.65f) );
|
||||||
shadowLabelTTF->setTextColor( Color4B::RED );
|
shadowLabelTTF->setTextColor( Color4B::RED );
|
||||||
shadowLabelTTF->enableShadow(Color4B::BLACK);
|
shadowLabelTTF->enableShadow(Color4B::BLACK);
|
||||||
addChild(shadowLabelTTF);
|
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 = 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->setColor( Color3B::RED );
|
||||||
shadowLabelBMFont->enableShadow(Color4B::GREEN);
|
shadowLabelBMFont->enableShadow(Color4B::GREEN);
|
||||||
addChild(shadowLabelBMFont);
|
addChild(shadowLabelBMFont);
|
||||||
|
@ -1354,6 +1361,7 @@ void LabelShadowTest::sliderEvent(Ref *pSender, ui::SliderEventType type)
|
||||||
auto offset = Size(slider->getPercent()-50,50 - slider2->getPercent());
|
auto offset = Size(slider->getPercent()-50,50 - slider2->getPercent());
|
||||||
shadowLabelTTF->enableShadow(Color4B::BLACK,offset);
|
shadowLabelTTF->enableShadow(Color4B::BLACK,offset);
|
||||||
shadowLabelBMFont->enableShadow(Color4B::GREEN,offset);
|
shadowLabelBMFont->enableShadow(Color4B::GREEN,offset);
|
||||||
|
shadowLabelOutline->enableShadow(Color4B::BLACK,offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -374,6 +374,7 @@ public:
|
||||||
|
|
||||||
void sliderEvent(Ref *pSender, ui::SliderEventType type);
|
void sliderEvent(Ref *pSender, ui::SliderEventType type);
|
||||||
private:
|
private:
|
||||||
|
Label* shadowLabelOutline;
|
||||||
Label* shadowLabelTTF;
|
Label* shadowLabelTTF;
|
||||||
Label* shadowLabelBMFont;
|
Label* shadowLabelBMFont;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue