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)
|
, _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,8 +930,6 @@ void Label::onDraw(const kmMat4& transform, bool transformUpdated)
|
||||||
}
|
}
|
||||||
else if(_shadowEnabled && _shadowBlurRadius <= 0)
|
else if(_shadowEnabled && _shadowBlurRadius <= 0)
|
||||||
{
|
{
|
||||||
trans = true;
|
|
||||||
kmGLPushMatrix();
|
|
||||||
drawShadowWithoutBlur();
|
drawShadowWithoutBlur();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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,17 +1102,27 @@ void Label::visit(Renderer *renderer, const kmMat4 &parentTransform, bool parent
|
||||||
updateContent();
|
updateContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! _textSprite && _shadowEnabled && _shadowBlurRadius <= 0)
|
|
||||||
{
|
|
||||||
_parentTransform = parentTransform;
|
|
||||||
draw(renderer, _modelViewTransform, true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bool dirty = parentTransformUpdated || _transformUpdated;
|
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)
|
if(dirty)
|
||||||
|
{
|
||||||
_modelViewTransform = transform(parentTransform);
|
_modelViewTransform = transform(parentTransform);
|
||||||
|
}
|
||||||
_transformUpdated = false;
|
_transformUpdated = false;
|
||||||
|
|
||||||
// IMPORTANT:
|
// IMPORTANT:
|
||||||
|
@ -1150,7 +1141,6 @@ void Label::visit(Renderer *renderer, const kmMat4 &parentTransform, bool parent
|
||||||
}
|
}
|
||||||
|
|
||||||
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