mirror of https://github.com/axmolengine/axmol.git
Merge pull request #6077 from Dhilan007/develop_label
Label:fixed possible blink if label contains shadow.
This commit is contained in:
commit
a93470c67d
|
@ -279,6 +279,7 @@ Label::Label(FontAtlas *atlas /* = nullptr */, TextHAlignment hAlignment /* = Te
|
|||
, _currNumLines(-1)
|
||||
, _textSprite(nullptr)
|
||||
, _contentDirty(false)
|
||||
, _shadowDirty(false)
|
||||
{
|
||||
setAnchorPoint(Point::ANCHOR_MIDDLE);
|
||||
reset();
|
||||
|
@ -852,6 +853,7 @@ void Label::enableShadow(const Color4B& shadowColor /* = Color4B::BLACK */,const
|
|||
{
|
||||
_shadowEnabled = true;
|
||||
_fontDefinition._shadow._shadowEnabled = false;
|
||||
_shadowDirty = true;
|
||||
|
||||
_effectColor = shadowColor;
|
||||
_effectColorF.r = _effectColor.r / 255.0f;
|
||||
|
@ -928,8 +930,6 @@ void Label::onDraw(const kmMat4& transform, bool transformUpdated)
|
|||
}
|
||||
else if(_shadowEnabled && _shadowBlurRadius <= 0)
|
||||
{
|
||||
trans = true;
|
||||
kmGLPushMatrix();
|
||||
drawShadowWithoutBlur();
|
||||
}
|
||||
|
||||
|
@ -946,29 +946,17 @@ void Label::onDraw(const kmMat4& transform, bool transformUpdated)
|
|||
batchNode->getTextureAtlas()->drawQuads();
|
||||
}
|
||||
|
||||
if (trans)
|
||||
{
|
||||
kmGLPopMatrix();
|
||||
}
|
||||
|
||||
CC_PROFILER_STOP("Label - draw");
|
||||
}
|
||||
|
||||
void Label::drawShadowWithoutBlur()
|
||||
{
|
||||
_position.x += _shadowOffset.width;
|
||||
_position.y += _shadowOffset.height;
|
||||
_transformDirty = _inverseDirty = true;
|
||||
|
||||
Color3B oldColor = _realColor;
|
||||
GLubyte oldOPacity = _displayedOpacity;
|
||||
_displayedOpacity = _effectColorF.a * _displayedOpacity;
|
||||
setColor(_shadowColor);
|
||||
|
||||
_modelViewTransform = transform(_parentTransform);
|
||||
kmGLLoadMatrix(&_modelViewTransform);
|
||||
|
||||
_shaderProgram->setUniformsForBuiltins(_modelViewTransform);
|
||||
_shaderProgram->setUniformsForBuiltins(_shadowTransform);
|
||||
for(const auto &child: _children)
|
||||
{
|
||||
child->updateTransform();
|
||||
|
@ -978,15 +966,8 @@ void Label::drawShadowWithoutBlur()
|
|||
batchNode->getTextureAtlas()->drawQuads();
|
||||
}
|
||||
|
||||
_position.x -= _shadowOffset.width;
|
||||
_position.y -= _shadowOffset.height;
|
||||
_transformDirty = _inverseDirty = true;
|
||||
|
||||
_displayedOpacity = oldOPacity;
|
||||
setColor(oldColor);
|
||||
|
||||
_modelViewTransform = transform(_parentTransform);
|
||||
kmGLLoadMatrix(&_modelViewTransform);
|
||||
}
|
||||
|
||||
void Label::draw(Renderer *renderer, const kmMat4 &transform, bool transformUpdated)
|
||||
|
@ -1121,17 +1102,27 @@ void Label::visit(Renderer *renderer, const kmMat4 &parentTransform, bool parent
|
|||
updateContent();
|
||||
}
|
||||
|
||||
if (! _textSprite && _shadowEnabled && _shadowBlurRadius <= 0)
|
||||
{
|
||||
_parentTransform = parentTransform;
|
||||
draw(renderer, _modelViewTransform, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
bool dirty = parentTransformUpdated || _transformUpdated;
|
||||
|
||||
if (_shadowEnabled && _shadowBlurRadius <= 0 && (_shadowDirty || dirty))
|
||||
{
|
||||
_position.x += _shadowOffset.width;
|
||||
_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:
|
||||
|
@ -1150,7 +1141,6 @@ void Label::visit(Renderer *renderer, const kmMat4 &parentTransform, bool parent
|
|||
}
|
||||
|
||||
kmGLPopMatrix();
|
||||
}
|
||||
|
||||
setOrderOfArrival(0);
|
||||
}
|
||||
|
|
|
@ -368,10 +368,11 @@ protected:
|
|||
GLuint _uniformTextColor;
|
||||
CustomCommand _customCommand;
|
||||
|
||||
bool _shadowDirty;
|
||||
bool _shadowEnabled;
|
||||
Size _shadowOffset;
|
||||
int _shadowBlurRadius;
|
||||
kmMat4 _parentTransform;
|
||||
kmMat4 _shadowTransform;
|
||||
Color3B _shadowColor;
|
||||
Sprite* _shadowNode;
|
||||
|
||||
|
|
Loading…
Reference in New Issue