mirror of https://github.com/axmolengine/axmol.git
Bug fixes for new label
This commit is contained in:
parent
4bbcd91bdf
commit
b45abf3f2d
|
@ -114,6 +114,8 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String)
|
||||||
std::unordered_map<unsigned short, FontLetterDefinition> fontDefs;
|
std::unordered_map<unsigned short, FontLetterDefinition> fontDefs;
|
||||||
int length = cc_wcslen(utf16String);
|
int length = cc_wcslen(utf16String);
|
||||||
|
|
||||||
|
auto yDelta = _currentPageLineHeight * 0.7;
|
||||||
|
|
||||||
//find out new letter
|
//find out new letter
|
||||||
for (int i = 0; i < length; ++i)
|
for (int i = 0; i < length; ++i)
|
||||||
{
|
{
|
||||||
|
@ -150,7 +152,7 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String)
|
||||||
tempDef.letteCharUTF16 = utf16String[i];
|
tempDef.letteCharUTF16 = utf16String[i];
|
||||||
tempDef.width = tempRect.size.width + _letterPadding;
|
tempDef.width = tempRect.size.width + _letterPadding;
|
||||||
tempDef.height = _currentPageLineHeight - 1;
|
tempDef.height = _currentPageLineHeight - 1;
|
||||||
tempDef.offsetY = tempRect.origin.y;
|
tempDef.offsetY = tempRect.origin.y + yDelta;
|
||||||
tempDef.commonLineHeight = _currentPageLineHeight;
|
tempDef.commonLineHeight = _currentPageLineHeight;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -215,13 +215,15 @@ FontAtlas * FontDefinitionTTF::createFontAtlas()
|
||||||
|
|
||||||
// set the common line height
|
// set the common line height
|
||||||
retAtlas->setCommonLineHeight(_commonLineHeight * 0.8);
|
retAtlas->setCommonLineHeight(_commonLineHeight * 0.8);
|
||||||
|
auto yDelta = _commonLineHeight * 0.7;
|
||||||
|
|
||||||
for( auto &item: _fontLettersDefinitionUTF16 )
|
for( auto &item: _fontLettersDefinitionUTF16 )
|
||||||
{
|
{
|
||||||
if ( item.second.validDefinition )
|
if ( item.second.validDefinition )
|
||||||
{
|
{
|
||||||
FontLetterDefinition tempDefinition = item.second;
|
FontLetterDefinition tempDefinition = item.second;
|
||||||
tempDefinition.offsetX = 0;
|
tempDefinition.offsetX = 0;
|
||||||
|
tempDefinition.offsetY += yDelta;
|
||||||
tempDefinition.anchorX = 0.0f;
|
tempDefinition.anchorX = 0.0f;
|
||||||
tempDefinition.anchorY = 1.0f;
|
tempDefinition.anchorY = 1.0f;
|
||||||
retAtlas->addLetterDefinition(tempDefinition);
|
retAtlas->addLetterDefinition(tempDefinition);
|
||||||
|
|
|
@ -194,6 +194,8 @@ bool Label::setText(const std::string& stringToRender, float lineWidth, TextHAli
|
||||||
// align text
|
// align text
|
||||||
alignText();
|
alignText();
|
||||||
|
|
||||||
|
updateColor();
|
||||||
|
|
||||||
// done here
|
// done here
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -438,6 +440,8 @@ bool Label::recordLetterInfo(const cocos2d::Point& point,unsigned short int theC
|
||||||
if (static_cast<std::size_t>(spriteIndex) >= _lettersInfo.size())
|
if (static_cast<std::size_t>(spriteIndex) >= _lettersInfo.size())
|
||||||
{
|
{
|
||||||
LetterInfo tmpInfo;
|
LetterInfo tmpInfo;
|
||||||
|
|
||||||
|
memset(&tmpInfo, 0, sizeof(tmpInfo));
|
||||||
_lettersInfo.push_back(tmpInfo);
|
_lettersInfo.push_back(tmpInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -454,6 +458,8 @@ bool Label::recordPlaceholderInfo(int spriteIndex)
|
||||||
if (static_cast<std::size_t>(spriteIndex) >= _lettersInfo.size())
|
if (static_cast<std::size_t>(spriteIndex) >= _lettersInfo.size())
|
||||||
{
|
{
|
||||||
LetterInfo tmpInfo;
|
LetterInfo tmpInfo;
|
||||||
|
|
||||||
|
memset(&tmpInfo, 0, sizeof(tmpInfo));
|
||||||
_lettersInfo.push_back(tmpInfo);
|
_lettersInfo.push_back(tmpInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -241,8 +241,6 @@ bool LabelTextFormatter::alignText(LabelTextFormatProtocol *theLabel)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int index = static_cast<int>(i + lineLength - 1 + lineNumber);
|
int index = static_cast<int>(i + lineLength - 1 + lineNumber);
|
||||||
if(currentChar == 0)
|
|
||||||
index -= 1;
|
|
||||||
if (index < 0) continue;
|
if (index < 0) continue;
|
||||||
|
|
||||||
LetterInfo* info = &leterInfo->at( index );
|
LetterInfo* info = &leterInfo->at( index );
|
||||||
|
|
Loading…
Reference in New Issue