mirror of https://github.com/axmolengine/axmol.git
Label:fixed possible blink if label contains shadow.
This commit is contained in:
parent
687b2e9f87
commit
f485d3b6d5
|
@ -279,6 +279,7 @@ Label::Label(FontAtlas *atlas /* = nullptr */, TextHAlignment hAlignment /* = Te
|
||||||
, _currNumLines(-1)
|
, _currNumLines(-1)
|
||||||
, _textSprite(nullptr)
|
, _textSprite(nullptr)
|
||||||
, _contentDirty(false)
|
, _contentDirty(false)
|
||||||
|
, _shadowDirty(false)
|
||||||
{
|
{
|
||||||
setAnchorPoint(Point::ANCHOR_MIDDLE);
|
setAnchorPoint(Point::ANCHOR_MIDDLE);
|
||||||
reset();
|
reset();
|
||||||
|
@ -852,6 +853,7 @@ void Label::enableShadow(const Color4B& shadowColor /* = Color4B::BLACK */,const
|
||||||
{
|
{
|
||||||
_shadowEnabled = true;
|
_shadowEnabled = true;
|
||||||
_fontDefinition._shadow._shadowEnabled = false;
|
_fontDefinition._shadow._shadowEnabled = false;
|
||||||
|
_shadowDirty = true;
|
||||||
|
|
||||||
_effectColor = shadowColor;
|
_effectColor = shadowColor;
|
||||||
_effectColorF.r = _effectColor.r / 255.0f;
|
_effectColorF.r = _effectColor.r / 255.0f;
|
||||||
|
@ -928,13 +930,11 @@ void Label::onDraw(const kmMat4& transform, bool transformUpdated)
|
||||||
}
|
}
|
||||||
else if(_shadowEnabled && _shadowBlurRadius <= 0)
|
else if(_shadowEnabled && _shadowBlurRadius <= 0)
|
||||||
{
|
{
|
||||||
trans = true;
|
|
||||||
kmGLPushMatrix();
|
|
||||||
drawShadowWithoutBlur();
|
drawShadowWithoutBlur();
|
||||||
}
|
}
|
||||||
|
|
||||||
_shaderProgram->setUniformsForBuiltins(transform);
|
_shaderProgram->setUniformsForBuiltins(transform);
|
||||||
|
|
||||||
for(const auto &child: _children)
|
for(const auto &child: _children)
|
||||||
{
|
{
|
||||||
if(child->getTag() >= 0)
|
if(child->getTag() >= 0)
|
||||||
|
@ -946,29 +946,17 @@ void Label::onDraw(const kmMat4& transform, bool transformUpdated)
|
||||||
batchNode->getTextureAtlas()->drawQuads();
|
batchNode->getTextureAtlas()->drawQuads();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (trans)
|
|
||||||
{
|
|
||||||
kmGLPopMatrix();
|
|
||||||
}
|
|
||||||
|
|
||||||
CC_PROFILER_STOP("Label - draw");
|
CC_PROFILER_STOP("Label - draw");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Label::drawShadowWithoutBlur()
|
void Label::drawShadowWithoutBlur()
|
||||||
{
|
{
|
||||||
_position.x += _shadowOffset.width;
|
|
||||||
_position.y += _shadowOffset.height;
|
|
||||||
_transformDirty = _inverseDirty = true;
|
|
||||||
|
|
||||||
Color3B oldColor = _realColor;
|
Color3B oldColor = _realColor;
|
||||||
GLubyte oldOPacity = _displayedOpacity;
|
GLubyte oldOPacity = _displayedOpacity;
|
||||||
_displayedOpacity = _effectColorF.a * _displayedOpacity;
|
_displayedOpacity = _effectColorF.a * _displayedOpacity;
|
||||||
setColor(_shadowColor);
|
setColor(_shadowColor);
|
||||||
|
|
||||||
_modelViewTransform = transform(_parentTransform);
|
_shaderProgram->setUniformsForBuiltins(_shadowTransform);
|
||||||
kmGLLoadMatrix(&_modelViewTransform);
|
|
||||||
|
|
||||||
_shaderProgram->setUniformsForBuiltins(_modelViewTransform);
|
|
||||||
for(const auto &child: _children)
|
for(const auto &child: _children)
|
||||||
{
|
{
|
||||||
child->updateTransform();
|
child->updateTransform();
|
||||||
|
@ -978,15 +966,8 @@ void Label::drawShadowWithoutBlur()
|
||||||
batchNode->getTextureAtlas()->drawQuads();
|
batchNode->getTextureAtlas()->drawQuads();
|
||||||
}
|
}
|
||||||
|
|
||||||
_position.x -= _shadowOffset.width;
|
|
||||||
_position.y -= _shadowOffset.height;
|
|
||||||
_transformDirty = _inverseDirty = true;
|
|
||||||
|
|
||||||
_displayedOpacity = oldOPacity;
|
_displayedOpacity = oldOPacity;
|
||||||
setColor(oldColor);
|
setColor(oldColor);
|
||||||
|
|
||||||
_modelViewTransform = transform(_parentTransform);
|
|
||||||
kmGLLoadMatrix(&_modelViewTransform);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Label::draw(Renderer *renderer, const kmMat4 &transform, bool transformUpdated)
|
void Label::draw(Renderer *renderer, const kmMat4 &transform, bool transformUpdated)
|
||||||
|
@ -1121,36 +1102,45 @@ void Label::visit(Renderer *renderer, const kmMat4 &parentTransform, bool parent
|
||||||
updateContent();
|
updateContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! _textSprite && _shadowEnabled && _shadowBlurRadius <= 0)
|
bool dirty = parentTransformUpdated || _transformUpdated;
|
||||||
|
|
||||||
|
if (_shadowEnabled && _shadowBlurRadius <= 0 && (_shadowDirty || dirty))
|
||||||
{
|
{
|
||||||
_parentTransform = parentTransform;
|
_position.x += _shadowOffset.width;
|
||||||
draw(renderer, _modelViewTransform, true);
|
_position.y += _shadowOffset.height;
|
||||||
|
_transformDirty = _inverseDirty = true;
|
||||||
|
|
||||||
|
_shadowTransform = transform(parentTransform);
|
||||||
|
|
||||||
|
_position.x -= _shadowOffset.width;
|
||||||
|
_position.y -= _shadowOffset.height;
|
||||||
|
_transformDirty = _inverseDirty = true;
|
||||||
|
|
||||||
|
_shadowDirty = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(dirty)
|
||||||
|
{
|
||||||
|
_modelViewTransform = transform(parentTransform);
|
||||||
|
}
|
||||||
|
_transformUpdated = false;
|
||||||
|
|
||||||
|
// IMPORTANT:
|
||||||
|
// To ease the migration to v3.0, we still support the kmGL stack,
|
||||||
|
// but it is deprecated and your code should not rely on it
|
||||||
|
kmGLPushMatrix();
|
||||||
|
kmGLLoadMatrix(&_modelViewTransform);
|
||||||
|
|
||||||
|
if (_textSprite)
|
||||||
|
{
|
||||||
|
drawTextSprite(renderer,dirty);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bool dirty = parentTransformUpdated || _transformUpdated;
|
draw(renderer, _modelViewTransform, dirty);
|
||||||
|
|
||||||
if(dirty)
|
|
||||||
_modelViewTransform = transform(parentTransform);
|
|
||||||
_transformUpdated = false;
|
|
||||||
|
|
||||||
// IMPORTANT:
|
|
||||||
// To ease the migration to v3.0, we still support the kmGL stack,
|
|
||||||
// but it is deprecated and your code should not rely on it
|
|
||||||
kmGLPushMatrix();
|
|
||||||
kmGLLoadMatrix(&_modelViewTransform);
|
|
||||||
|
|
||||||
if (_textSprite)
|
|
||||||
{
|
|
||||||
drawTextSprite(renderer,dirty);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
draw(renderer, _modelViewTransform, dirty);
|
|
||||||
}
|
|
||||||
|
|
||||||
kmGLPopMatrix();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kmGLPopMatrix();
|
||||||
|
|
||||||
setOrderOfArrival(0);
|
setOrderOfArrival(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -368,10 +368,11 @@ protected:
|
||||||
GLuint _uniformTextColor;
|
GLuint _uniformTextColor;
|
||||||
CustomCommand _customCommand;
|
CustomCommand _customCommand;
|
||||||
|
|
||||||
|
bool _shadowDirty;
|
||||||
bool _shadowEnabled;
|
bool _shadowEnabled;
|
||||||
Size _shadowOffset;
|
Size _shadowOffset;
|
||||||
int _shadowBlurRadius;
|
int _shadowBlurRadius;
|
||||||
kmMat4 _parentTransform;
|
kmMat4 _shadowTransform;
|
||||||
Color3B _shadowColor;
|
Color3B _shadowColor;
|
||||||
Sprite* _shadowNode;
|
Sprite* _shadowNode;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue