mirror of https://github.com/axmolengine/axmol.git
Merge pull request #6062 from Dhilan007/develop_label
TextFieldTTF:fixed display incorrect color.
This commit is contained in:
commit
f946124d37
|
@ -737,9 +737,6 @@ void Label::updateQuads()
|
|||
_reusedRect.size.width = letterDef.width;
|
||||
_reusedRect.origin.x = letterDef.U;
|
||||
_reusedRect.origin.y = letterDef.V;
|
||||
|
||||
if(_reusedLetter->getBatchNode() != _batchNodes[letterDef.textureID])
|
||||
_reusedLetter->setBatchNode(_batchNodes[letterDef.textureID]);
|
||||
_reusedLetter->setTextureRect(_reusedRect,false,_reusedRect.size);
|
||||
|
||||
_reusedLetter->setPosition(_lettersInfo[ctr].position);
|
||||
|
@ -1015,6 +1012,7 @@ void Label::createSpriteWithFontDefinition()
|
|||
_textSprite->setAnchorPoint(Point::ANCHOR_BOTTOM_LEFT);
|
||||
this->setContentSize(_textSprite->getContentSize());
|
||||
texture->release();
|
||||
_textSprite->setBlendFunc(_blendFunc);
|
||||
|
||||
Node::addChild(_textSprite,0,Node::INVALID_TAG);
|
||||
|
||||
|
@ -1086,6 +1084,7 @@ void Label::drawTextSprite(Renderer *renderer, bool parentTransformUpdated)
|
|||
if (_shadowEnabled && _shadowNode == nullptr)
|
||||
{
|
||||
_shadowNode = Sprite::createWithTexture(_textSprite->getTexture());
|
||||
_shadowNode->setBlendFunc(_blendFunc);
|
||||
_shadowNode->setAnchorPoint(Point::ANCHOR_BOTTOM_LEFT);
|
||||
_shadowNode->setColor(_shadowColor);
|
||||
_shadowNode->setOpacity(_effectColorF.a * _displayedOpacity);
|
||||
|
|
|
@ -206,7 +206,7 @@ public:
|
|||
/** Sets the text color
|
||||
*
|
||||
*/
|
||||
void setTextColor(const Color4B &color);
|
||||
virtual void setTextColor(const Color4B &color);
|
||||
|
||||
const Color4B& getTextColor() const { return _textColor;}
|
||||
|
||||
|
@ -372,7 +372,7 @@ protected:
|
|||
int _shadowBlurRadius;
|
||||
kmMat4 _parentTransform;
|
||||
Color3B _shadowColor;
|
||||
Node* _shadowNode;
|
||||
Sprite* _shadowNode;
|
||||
|
||||
Color4B _textColor;
|
||||
Color4F _textColorF;
|
||||
|
|
|
@ -57,8 +57,10 @@ TextFieldTTF::TextFieldTTF()
|
|||
, _inputText("")
|
||||
, _placeHolder("") // prevent Label initWithString assertion
|
||||
, _secureTextEntry(false)
|
||||
, _colorText(Color4B::WHITE)
|
||||
{
|
||||
_colorSpaceHolder.r = _colorSpaceHolder.g = _colorSpaceHolder.b = 127;
|
||||
_colorSpaceHolder.a = 255;
|
||||
}
|
||||
|
||||
TextFieldTTF::~TextFieldTTF()
|
||||
|
@ -112,6 +114,7 @@ bool TextFieldTTF::initWithPlaceHolder(const std::string& placeholder, const Siz
|
|||
setFontName(fontName);
|
||||
setFontSize(fontSize);
|
||||
setAlignment(alignment,TextVAlignment::CENTER);
|
||||
Label::setTextColor(_colorSpaceHolder);
|
||||
Label::setString(_placeHolder);
|
||||
|
||||
return true;
|
||||
|
@ -121,6 +124,7 @@ bool TextFieldTTF::initWithPlaceHolder(const std::string& placeholder, const std
|
|||
_placeHolder = std::string(placeholder);
|
||||
setFontName(fontName);
|
||||
setFontSize(fontSize);
|
||||
Label::setTextColor(_colorSpaceHolder);
|
||||
Label::setString(_placeHolder);
|
||||
|
||||
return true;
|
||||
|
@ -238,6 +242,7 @@ void TextFieldTTF::deleteBackward()
|
|||
{
|
||||
_inputText = "";
|
||||
_charCount = 0;
|
||||
Label::setTextColor(_colorSpaceHolder);
|
||||
Label::setString(_placeHolder);
|
||||
return;
|
||||
}
|
||||
|
@ -252,10 +257,10 @@ const std::string& TextFieldTTF::getContentText()
|
|||
return _inputText;
|
||||
}
|
||||
|
||||
void TextFieldTTF::setColor(const Color3B& color)
|
||||
void TextFieldTTF::setTextColor(const Color4B &color)
|
||||
{
|
||||
_colorText = color;
|
||||
Label::setColor(color);
|
||||
Label::setTextColor(_colorText);
|
||||
}
|
||||
|
||||
void TextFieldTTF::visit(Renderer *renderer, const kmMat4 &parentTransform, bool parentTransformUpdated)
|
||||
|
@ -267,12 +272,20 @@ void TextFieldTTF::visit(Renderer *renderer, const kmMat4 &parentTransform, bool
|
|||
Label::visit(renderer,parentTransform,parentTransformUpdated);
|
||||
}
|
||||
|
||||
const Color3B& TextFieldTTF::getColorSpaceHolder()
|
||||
const Color4B& TextFieldTTF::getColorSpaceHolder()
|
||||
{
|
||||
return _colorSpaceHolder;
|
||||
}
|
||||
|
||||
void TextFieldTTF::setColorSpaceHolder(const Color3B& color)
|
||||
{
|
||||
_colorSpaceHolder.r = color.r;
|
||||
_colorSpaceHolder.g = color.g;
|
||||
_colorSpaceHolder.b = color.b;
|
||||
_colorSpaceHolder.a = 255;
|
||||
}
|
||||
|
||||
void TextFieldTTF::setColorSpaceHolder(const Color4B& color)
|
||||
{
|
||||
_colorSpaceHolder = color;
|
||||
}
|
||||
|
@ -311,12 +324,12 @@ void TextFieldTTF::setString(const std::string &text)
|
|||
// if there is no input text, display placeholder instead
|
||||
if (! _inputText.length())
|
||||
{
|
||||
Label::setColor(_colorSpaceHolder);
|
||||
Label::setTextColor(_colorSpaceHolder);
|
||||
Label::setString(_placeHolder);
|
||||
}
|
||||
else
|
||||
{
|
||||
Label::setColor(_colorText);
|
||||
Label::setTextColor(_colorText);
|
||||
Label::setString(displayText);
|
||||
}
|
||||
_charCount = _calcCharCount(_inputText.c_str());
|
||||
|
@ -333,6 +346,7 @@ void TextFieldTTF::setPlaceHolder(const std::string& text)
|
|||
_placeHolder = text;
|
||||
if (! _inputText.length())
|
||||
{
|
||||
Label::setTextColor(_colorSpaceHolder);
|
||||
Label::setString(_placeHolder);
|
||||
}
|
||||
}
|
||||
|
@ -348,7 +362,7 @@ void TextFieldTTF::setSecureTextEntry(bool value)
|
|||
if (_secureTextEntry != value)
|
||||
{
|
||||
_secureTextEntry = value;
|
||||
setString(getString());
|
||||
setString(_inputText);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -145,10 +145,13 @@ public:
|
|||
inline void setDelegate(TextFieldDelegate* delegate) { _delegate = delegate; };
|
||||
|
||||
inline int getCharCount() const { return _charCount; };
|
||||
virtual const Color3B& getColorSpaceHolder();
|
||||
virtual void setColorSpaceHolder(const Color3B& color);
|
||||
|
||||
virtual const Color4B& getColorSpaceHolder();
|
||||
|
||||
virtual void setColor(const Color3B& color) override;
|
||||
virtual void setColorSpaceHolder(const Color3B& color);
|
||||
virtual void setColorSpaceHolder(const Color4B& color);
|
||||
|
||||
virtual void setTextColor(const Color4B& textColor) override;
|
||||
|
||||
// input text property
|
||||
virtual void setString(const std::string& text) override;
|
||||
|
@ -181,8 +184,8 @@ protected:
|
|||
std::string _inputText;
|
||||
|
||||
std::string _placeHolder;
|
||||
Color3B _colorSpaceHolder;
|
||||
Color3B _colorText;
|
||||
Color4B _colorSpaceHolder;
|
||||
Color4B _colorText;
|
||||
|
||||
bool _secureTextEntry;
|
||||
|
||||
|
|
Loading…
Reference in New Issue