mirror of https://github.com/axmolengine/axmol.git
closed issue#4428:fixed label display incorrect if invoking getLetter and it's multi-line.
This commit is contained in:
parent
36cfd17e7b
commit
cc671835f8
|
@ -446,7 +446,7 @@ bool Label::setBMFontFilePath(const std::string& bmfontFilePath, const Point& im
|
||||||
reset();
|
reset();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
_bmFontPath = bmfontFilePath;
|
||||||
setFontAtlas(newAtlas);
|
setFontAtlas(newAtlas);
|
||||||
_currentLabelType = LabelType::BMFONT;
|
_currentLabelType = LabelType::BMFONT;
|
||||||
|
|
||||||
|
@ -624,17 +624,7 @@ void Label::alignText()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int index;
|
updateQuads();
|
||||||
for (int ctr = 0; ctr < _limitShowCount; ++ctr)
|
|
||||||
{
|
|
||||||
if (_lettersInfo[ctr].def.validDefinition)
|
|
||||||
{
|
|
||||||
updateSpriteWithLetterDefinition(_lettersInfo[ctr].def,textures[_lettersInfo[ctr].def.textureID]);
|
|
||||||
_reusedLetter->setPosition(_lettersInfo[ctr].position);
|
|
||||||
index = _batchNodes[_lettersInfo[ctr].def.textureID]->getTextureAtlas()->getTotalQuads();
|
|
||||||
_batchNodes[_lettersInfo[ctr].def.textureID]->insertQuadFromSprite(_reusedLetter,index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
updateColor();
|
updateColor();
|
||||||
}
|
}
|
||||||
|
@ -691,16 +681,30 @@ bool Label::setCurrentString(unsigned short *stringToSet)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Label::updateSpriteWithLetterDefinition(const FontLetterDefinition &theDefinition, Texture2D *theTexture)
|
void Label::updateQuads()
|
||||||
{
|
{
|
||||||
_reusedRect.size.height = theDefinition.height;
|
int index;
|
||||||
_reusedRect.size.width = theDefinition.width;
|
for (int ctr = 0; ctr < _limitShowCount; ++ctr)
|
||||||
_reusedRect.origin.x = theDefinition.U;
|
{
|
||||||
_reusedRect.origin.y = theDefinition.V;
|
auto &letterDef = _lettersInfo[ctr].def;
|
||||||
|
|
||||||
if(_reusedLetter->getBatchNode() != _batchNodes[theDefinition.textureID])
|
if (letterDef.validDefinition)
|
||||||
_reusedLetter->setBatchNode(_batchNodes[theDefinition.textureID]);
|
{
|
||||||
|
_reusedRect.size.height = letterDef.height;
|
||||||
|
_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->setTextureRect(_reusedRect,false,_reusedRect.size);
|
||||||
|
|
||||||
|
_reusedLetter->setPosition(_lettersInfo[ctr].position);
|
||||||
|
index = _batchNodes[letterDef.textureID]->getTextureAtlas()->getTotalQuads();
|
||||||
|
_lettersInfo[ctr].atlasIndex = index;
|
||||||
|
_batchNodes[letterDef.textureID]->insertQuadFromSprite(_reusedLetter,index);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Label::recordLetterInfo(const cocos2d::Point& point,const FontLetterDefinition& letterDef, int spriteIndex)
|
bool Label::recordLetterInfo(const cocos2d::Point& point,const FontLetterDefinition& letterDef, int spriteIndex)
|
||||||
|
@ -1056,6 +1060,10 @@ int Label::getFontSize() const
|
||||||
///// PROTOCOL STUFF
|
///// PROTOCOL STUFF
|
||||||
Sprite * Label::getLetter(int lettetIndex)
|
Sprite * Label::getLetter(int lettetIndex)
|
||||||
{
|
{
|
||||||
|
if (_fontDirty)
|
||||||
|
{
|
||||||
|
const_cast<Label*>(this)->updateFont();
|
||||||
|
}
|
||||||
if (_contentDirty)
|
if (_contentDirty)
|
||||||
{
|
{
|
||||||
updateContent();
|
updateContent();
|
||||||
|
@ -1063,7 +1071,9 @@ Sprite * Label::getLetter(int lettetIndex)
|
||||||
|
|
||||||
if (! _textSprite && lettetIndex < _limitShowCount)
|
if (! _textSprite && lettetIndex < _limitShowCount)
|
||||||
{
|
{
|
||||||
if(! _lettersInfo[lettetIndex].def.validDefinition)
|
auto &letterDef = _lettersInfo[lettetIndex].def;
|
||||||
|
|
||||||
|
if(! letterDef.validDefinition)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
Sprite* sp = static_cast<Sprite*>(this->getChildByTag(lettetIndex));
|
Sprite* sp = static_cast<Sprite*>(this->getChildByTag(lettetIndex));
|
||||||
|
@ -1071,18 +1081,18 @@ Sprite * Label::getLetter(int lettetIndex)
|
||||||
if (!sp)
|
if (!sp)
|
||||||
{
|
{
|
||||||
Rect uvRect;
|
Rect uvRect;
|
||||||
uvRect.size.height = _lettersInfo[lettetIndex].def.height;
|
uvRect.size.height = letterDef.height;
|
||||||
uvRect.size.width = _lettersInfo[lettetIndex].def.width;
|
uvRect.size.width = letterDef.width;
|
||||||
uvRect.origin.x = _lettersInfo[lettetIndex].def.U;
|
uvRect.origin.x = letterDef.U;
|
||||||
uvRect.origin.y = _lettersInfo[lettetIndex].def.V;
|
uvRect.origin.y = letterDef.V;
|
||||||
|
|
||||||
sp = Sprite::createWithTexture(_fontAtlas->getTexture(_lettersInfo[lettetIndex].def.textureID),uvRect);
|
sp = Sprite::createWithTexture(_fontAtlas->getTexture(letterDef.textureID),uvRect);
|
||||||
sp->setBatchNode(this);
|
sp->setBatchNode(_batchNodes[letterDef.textureID]);
|
||||||
sp->setAnchorPoint(Point::ANCHOR_MIDDLE);
|
sp->setPosition(Point(_lettersInfo[lettetIndex].position.x + uvRect.size.width / 2,
|
||||||
sp->setPosition(Point(_lettersInfo[lettetIndex].position.x+uvRect.size.width/2,_lettersInfo[lettetIndex].position.y-uvRect.size.height/2));
|
_lettersInfo[lettetIndex].position.y - uvRect.size.height / 2));
|
||||||
sp->setOpacity(_realOpacity);
|
sp->setOpacity(_realOpacity);
|
||||||
|
|
||||||
this->addSpriteWithoutQuad(sp, lettetIndex, lettetIndex);
|
_batchNodes[letterDef.textureID]->addSpriteWithoutQuad(sp, _lettersInfo[lettetIndex].atlasIndex, lettetIndex);
|
||||||
}
|
}
|
||||||
return sp;
|
return sp;
|
||||||
}
|
}
|
||||||
|
@ -1120,7 +1130,7 @@ void Label::computeStringNumLines()
|
||||||
|
|
||||||
int Label::getStringLength() const
|
int Label::getStringLength() const
|
||||||
{
|
{
|
||||||
return _currentUTF16String ? cc_wcslen(_currentUTF16String) : 0;
|
return _currentUTF16String ? cc_wcslen(_currentUTF16String) : _originalUTF8String.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
// RGBA protocol
|
// RGBA protocol
|
||||||
|
|
|
@ -116,6 +116,7 @@ public:
|
||||||
virtual bool setTTFConfig(const TTFConfig& ttfConfig);
|
virtual bool setTTFConfig(const TTFConfig& ttfConfig);
|
||||||
|
|
||||||
virtual bool setBMFontFilePath(const std::string& bmfontFilePath, const Point& imageOffset = Point::ZERO);
|
virtual bool setBMFontFilePath(const std::string& bmfontFilePath, const Point& imageOffset = Point::ZERO);
|
||||||
|
const std::string& getBMFontFilePath() const { return _bmFontPath;}
|
||||||
|
|
||||||
virtual bool setCharMap(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap);
|
virtual bool setCharMap(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap);
|
||||||
virtual bool setCharMap(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap);
|
virtual bool setCharMap(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap);
|
||||||
|
@ -248,6 +249,7 @@ protected:
|
||||||
|
|
||||||
Point position;
|
Point position;
|
||||||
Size contentSize;
|
Size contentSize;
|
||||||
|
int atlasIndex;
|
||||||
};
|
};
|
||||||
enum class LabelType {
|
enum class LabelType {
|
||||||
|
|
||||||
|
@ -282,7 +284,7 @@ protected:
|
||||||
bool setOriginalString(unsigned short *stringToSet);
|
bool setOriginalString(unsigned short *stringToSet);
|
||||||
void computeStringNumLines();
|
void computeStringNumLines();
|
||||||
|
|
||||||
void updateSpriteWithLetterDefinition(const FontLetterDefinition &theDefinition, Texture2D *theTexture);
|
void updateQuads();
|
||||||
|
|
||||||
virtual void updateColor() override;
|
virtual void updateColor() override;
|
||||||
|
|
||||||
|
@ -295,6 +297,8 @@ protected:
|
||||||
void updateFont();
|
void updateFont();
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
|
std::string _bmFontPath;
|
||||||
|
|
||||||
bool _isOpacityModifyRGB;
|
bool _isOpacityModifyRGB;
|
||||||
bool _contentDirty;
|
bool _contentDirty;
|
||||||
bool _fontDirty;
|
bool _fontDirty;
|
||||||
|
|
Loading…
Reference in New Issue