mirror of https://github.com/axmolengine/axmol.git
Merge pull request #5378 from Dhilan007/develop_label_multiilTexture
closed #4060:fixed Label wasn't implemented correctly when Label::_fontAtlas contains multiple texture.
This commit is contained in:
commit
43e51a9cb1
|
@ -1 +1 @@
|
|||
654ea57201d78ad72b48cd198ab0e9d937435c1b
|
||||
2b6e0f0359921c6f1328c545b48ff94e6575e332
|
|
@ -174,7 +174,7 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String)
|
|||
{
|
||||
_currentPageOrigY += _currentPageLineHeight;
|
||||
_currentPageOrigX = 0;
|
||||
if(_currentPageOrigY >= PAGE_HEIGHT)
|
||||
if(_currentPageOrigY + _currentPageLineHeight >= PAGE_HEIGHT)
|
||||
{
|
||||
_atlasTextures[_currentPage]->initWithData(_currentPageData, _currentPageDataSize, pixelFormat, PAGE_WIDTH, PAGE_HEIGHT, _pageContentSize );
|
||||
_currentPageOrigY = 0;
|
||||
|
|
|
@ -67,6 +67,7 @@ public:
|
|||
|
||||
bool prepareLetterDefinitions(unsigned short *utf16String);
|
||||
|
||||
inline const std::unordered_map<int, Texture2D*>& getTextures() const{ return _atlasTextures;}
|
||||
void addTexture(Texture2D &texture, int slot);
|
||||
float getCommonLineHeight() const;
|
||||
void setCommonLineHeight(float newHeight);
|
||||
|
|
|
@ -205,6 +205,7 @@ Label::Label(FontAtlas *atlas, TextHAlignment alignment, bool useDistanceField,b
|
|||
,_currNumLines(-1)
|
||||
{
|
||||
_cascadeColorEnabled = true;
|
||||
_batchNodes.push_back(this);
|
||||
}
|
||||
|
||||
Label::~Label()
|
||||
|
@ -430,9 +431,23 @@ float Label::getScaleX() const
|
|||
|
||||
void Label::alignText()
|
||||
{
|
||||
if(_textureAtlas)
|
||||
_textureAtlas->removeAllQuads();
|
||||
for (const auto& batchNode:_batchNodes)
|
||||
{
|
||||
batchNode->getTextureAtlas()->removeAllQuads();
|
||||
}
|
||||
_fontAtlas->prepareLetterDefinitions(_currentUTF16String);
|
||||
auto textures = _fontAtlas->getTextures();
|
||||
if (textures.size() > _batchNodes.size())
|
||||
{
|
||||
for (int index = _batchNodes.size(); index < textures.size(); ++index)
|
||||
{
|
||||
auto batchNode = SpriteBatchNode::createWithTexture(textures[index]);
|
||||
batchNode->setAnchorPoint(Point::ANCHOR_TOP_LEFT);
|
||||
batchNode->setPosition(Point::ZERO);
|
||||
Node::addChild(batchNode,0,Node::INVALID_TAG);
|
||||
_batchNodes.push_back(batchNode);
|
||||
}
|
||||
}
|
||||
LabelTextFormatter::createStringSprites(this);
|
||||
if(_width > 0 && _contentSize.width > _width && LabelTextFormatter::multilineText(this) )
|
||||
LabelTextFormatter::createStringSprites(this);
|
||||
|
@ -443,7 +458,7 @@ void Label::alignText()
|
|||
int strLen = cc_wcslen(_currentUTF16String);
|
||||
for(const auto &child : _children) {
|
||||
int tag = child->getTag();
|
||||
if(tag < 0 || tag >= strLen)
|
||||
if(tag >= strLen)
|
||||
SpriteBatchNode::removeChild(child, true);
|
||||
}
|
||||
|
||||
|
@ -470,7 +485,8 @@ void Label::alignText()
|
|||
|
||||
updateSpriteWithLetterDefinition(_reusedLetter,_lettersInfo[ctr].def,&_fontAtlas->getTexture(_lettersInfo[ctr].def.textureID));
|
||||
_reusedLetter->setPosition(_lettersInfo[ctr].position);
|
||||
insertQuadFromSprite(_reusedLetter,vaildIndex++);
|
||||
int index = _batchNodes[_lettersInfo[ctr].def.textureID]->getTextureAtlas()->getTotalQuads();
|
||||
_batchNodes[_lettersInfo[ctr].def.textureID]->insertQuadFromSprite(_reusedLetter,index);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -562,7 +578,7 @@ Sprite * Label::updateSpriteWithLetterDefinition(Sprite *spriteToUpdate, const F
|
|||
SpriteFrame *frame = SpriteFrame::createWithTexture(theTexture, uvRect);
|
||||
if (frame)
|
||||
{
|
||||
spriteToUpdate->setBatchNode(this);
|
||||
spriteToUpdate->setBatchNode(_batchNodes[theDefinition.textureID]);
|
||||
spriteToUpdate->setSpriteFrame(frame);
|
||||
}
|
||||
|
||||
|
@ -644,7 +660,7 @@ void Label::onDraw()
|
|||
CC_PROFILER_START("CCSpriteBatchNode - draw");
|
||||
|
||||
// Optimization: Fast Dispatch
|
||||
if( _textureAtlas->getTotalQuads() == 0 )
|
||||
if( _batchNodes.size() == 1 && _textureAtlas->getTotalQuads() == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -657,11 +673,16 @@ void Label::onDraw()
|
|||
}
|
||||
|
||||
for(const auto &child: _children)
|
||||
{
|
||||
child->updateTransform();
|
||||
}
|
||||
|
||||
GL::blendFunc( _blendFunc.src, _blendFunc.dst );
|
||||
|
||||
_textureAtlas->drawQuads();
|
||||
for (const auto& batchNode:_batchNodes)
|
||||
{
|
||||
batchNode->getTextureAtlas()->drawQuads();
|
||||
}
|
||||
|
||||
CC_PROFILER_STOP("CCSpriteBatchNode - draw");
|
||||
}
|
||||
|
@ -673,6 +694,23 @@ void Label::draw()
|
|||
Director::getInstance()->getRenderer()->addCommand(&_customCommand);
|
||||
}
|
||||
|
||||
void Label::visit()
|
||||
{
|
||||
if (! _visible)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
kmGLPushMatrix();
|
||||
|
||||
transform();
|
||||
draw();
|
||||
|
||||
kmGLPopMatrix();
|
||||
|
||||
setOrderOfArrival(0);
|
||||
}
|
||||
|
||||
///// PROTOCOL STUFF
|
||||
|
||||
Sprite * Label::getLetter(int ID)
|
||||
|
|
|
@ -143,6 +143,7 @@ public:
|
|||
void addChild(Node * child, int zOrder=0, int tag=0) override;
|
||||
|
||||
virtual std::string getDescription() const override;
|
||||
virtual void visit() override;
|
||||
virtual void draw(void) override;
|
||||
virtual void onDraw();
|
||||
|
||||
|
@ -203,6 +204,8 @@ private:
|
|||
|
||||
CustomCommand _customCommand;
|
||||
int _currNumLines;
|
||||
|
||||
std::vector<SpriteBatchNode*> _batchNodes;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -167,12 +167,12 @@ public:
|
|||
virtual void draw(void) override;
|
||||
virtual std::string getDescription() const override;
|
||||
|
||||
protected:
|
||||
/** Inserts a quad at a certain index into the texture atlas. The Sprite won't be added into the children array.
|
||||
This method should be called only when you are dealing with very big AtlasSrite and when most of the Sprite won't be updated.
|
||||
For example: a tile map (TMXMap) or a label with lots of characters (LabelBMFont)
|
||||
*/
|
||||
void insertQuadFromSprite(Sprite *sprite, ssize_t index);
|
||||
protected:
|
||||
/** Updates a quad at a certain index into the texture atlas. The Sprite won't be added into the children array.
|
||||
This method should be called only when you are dealing with very big AtlasSrite and when most of the Sprite won't be updated.
|
||||
For example: a tile map (TMXMap) or a label with lots of characters (LabelBMFont)
|
||||
|
|
|
@ -60,6 +60,7 @@ static std::function<Layer*()> createFunctions[] =
|
|||
CL(LabelTTFAlignmentNew),
|
||||
CL(LabelFNTBounds),
|
||||
CL(LabelTTFLongLineWrapping),
|
||||
CL(LabelTTFLargeText),
|
||||
CL(LabelTTFColor),
|
||||
CL(LabelTTFFontsTestNew),
|
||||
CL(LabelTTFDynamicAlignment),
|
||||
|
@ -978,6 +979,29 @@ std::string LabelTTFLongLineWrapping::subtitle() const
|
|||
return "Uses the new Label with TTF. Testing auto-wrapping";
|
||||
}
|
||||
|
||||
LabelTTFLargeText::LabelTTFLargeText()
|
||||
{
|
||||
auto size = Director::getInstance()->getWinSize();
|
||||
|
||||
// Long sentence
|
||||
TTFConfig ttfConfig("fonts/wt021.ttf",36,GlyphCollection::DYNAMIC);
|
||||
std::string text = FileUtils::getInstance()->getStringFromFile("commonly_used_words.txt");
|
||||
auto label = Label::createWithTTF(ttfConfig,text, TextHAlignment::CENTER, size.width);
|
||||
label->setPosition( Point(size.width/2, size.height/2) );
|
||||
label->setAnchorPoint(Point::ANCHOR_MIDDLE);
|
||||
addChild(label);
|
||||
}
|
||||
|
||||
std::string LabelTTFLargeText::title() const
|
||||
{
|
||||
return "New Label + .TTF";
|
||||
}
|
||||
|
||||
std::string LabelTTFLargeText::subtitle() const
|
||||
{
|
||||
return "Uses the new Label with TTF. Testing large text";
|
||||
}
|
||||
|
||||
LabelTTFColor::LabelTTFColor()
|
||||
{
|
||||
auto size = Director::getInstance()->getWinSize();
|
||||
|
|
|
@ -420,6 +420,17 @@ protected:
|
|||
void onDraw();
|
||||
};
|
||||
|
||||
class LabelTTFLargeText : public AtlasDemoNew
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(LabelTTFLargeText);
|
||||
|
||||
LabelTTFLargeText();
|
||||
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
// we don't support linebreak mode
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
三画
|
||||
三于干亏士工土才寸下大丈与万上小口巾山千乞川亿个勺久凡及夕丸么广
|
||||
亡门义之尸弓己已子卫也女飞刃习叉马乡
|
||||
|
||||
四画
|
||||
丰王井开夫天无元专云扎艺木五支厅不太犬区历尤友匹车巨牙屯比互切瓦
|
||||
止少日中冈贝内水见午牛手毛气升长仁什片仆化仇币仍仅斤爪反介父从今
|
||||
凶分乏公仓月氏勿欠风丹匀乌凤勾文六方火为斗忆订计户认心尺引丑巴孔
|
||||
队办以允予劝双书幻
|
||||
|
||||
五画
|
||||
玉刊示末未击打巧正扑扒功扔去甘世古节本术可丙左厉右石布龙平灭轧东
|
||||
卡北占业旧帅归且旦目叶甲申叮电号田由史只央兄叼叫另叨叹四生失禾丘
|
||||
付仗代仙们仪白仔他斥瓜乎丛令用甩印乐句匆册犯外处冬鸟务包饥主市立
|
||||
闪兰半汁汇头汉宁穴它讨写让礼训必议讯记永司尼民出辽奶奴加召皮边发
|
||||
孕圣对台矛纠母幼丝
|
||||
|
||||
六画
|
||||
式刑动扛寺吉扣考托老执巩圾扩扫地扬场耳共芒亚芝朽朴机权过臣再协西
|
||||
压厌在有百存而页匠夸夺灰达列死成夹轨邪划迈毕至此贞师尘尖劣光当早
|
||||
吐吓虫曲团同吊吃因吸吗屿帆岁回岂刚则肉网年朱先丢舌竹迁乔伟传乒乓
|
||||
休伍伏优伐延件任伤价份华仰仿伙伪自血向似后行舟全会杀合兆企众爷伞
|
||||
创肌朵杂危旬旨负各名多争色壮冲冰庄庆亦刘齐交次衣产决充妄闭问闯羊
|
||||
并关米灯州汗污江池汤忙兴宇守宅字安讲军许论农讽设访寻那迅尽导异孙
|
||||
阵阳收阶阴防奸如妇好她妈戏羽观欢买红纤级约纪驰巡
|
||||
|
||||
七画
|
||||
寿弄麦形进戒吞远违运扶抚坛技坏扰拒找批扯址走抄坝贡攻赤折抓扮抢孝
|
||||
均抛投坟抗坑坊抖护壳志扭块声把报却劫芽花芹芬苍芳严芦劳克苏杆杠杜
|
||||
材村杏极李杨求更束豆两丽医辰励否还歼来连步坚旱盯呈时吴助县里呆园
|
||||
旷围呀吨足邮男困吵串员听吩吹呜吧吼别岗帐财针钉告我乱利秃秀私每兵
|
||||
估体何但伸作伯伶佣低你住位伴身皂佛近彻役返余希坐谷妥含邻岔肝肚肠
|
||||
龟免狂犹角删条卵岛迎饭饮系言冻状亩况床库疗应冷这序辛弃冶忘闲间闷
|
||||
判灶灿弟汪沙汽沃泛沟没沈沉怀忧快完宋宏牢究穷灾良证启评补初社识诉
|
||||
诊词译君灵即层尿尾迟局改张忌际陆阿陈阻附妙妖妨努忍劲鸡驱纯纱纳纲
|
||||
驳纵纷纸纹纺驴纽
|
||||
|
||||
八画
|
||||
奉玩环武青责现表规抹拢拔拣担坦押抽拐拖拍者顶拆拥抵拘势抱垃拉拦拌
|
||||
幸招坡披拨择抬其取苦若茂苹苗英范直茄茎茅林枝杯柜析板松枪构杰述枕
|
||||
丧或画卧事刺枣雨卖矿码厕奔奇奋态欧垄妻轰顷转斩轮软到非叔肯齿些虎
|
||||
虏肾贤尚旺具果味昆国昌畅明易昂典固忠咐呼鸣咏呢岸岩帖罗帜岭凯败贩
|
||||
购图钓制知垂牧物乖刮秆和季委佳侍供使例版侄侦侧凭侨佩货依的迫质欣
|
||||
征往爬彼径所舍金命斧爸采受乳贪念贫肤肺肢肿胀朋股肥服胁周昏鱼兔狐
|
||||
忽狗备饰饱饲变京享店夜庙府底剂郊废净盲放刻育闸闹郑券卷单炒炊炕炎
|
||||
炉沫浅法泄河沾泪油泊沿泡注泻泳泥沸波泼泽治怖性怕怜怪学宝宗定宜审
|
||||
宙官空帘实试郎诗肩房诚衬衫视话诞询该详建肃录隶居届刷屈弦承孟孤陕
|
||||
降限妹姑姐姓始驾参艰线练组细驶织终驻驼绍经贯
|
||||
|
||||
九画
|
||||
奏春帮珍玻毒型挂封持项垮挎城挠政赴赵挡挺括拴拾挑指垫挣挤拼挖按挥
|
||||
挪某甚革荐巷带草茧茶荒茫荡荣故胡南药标枯柄栋相查柏柳柱柿栏树要咸
|
||||
威歪研砖厘厚砌砍面耐耍牵残殃轻鸦皆背战点临览竖省削尝是盼眨哄显哑
|
||||
冒映星昨畏趴胃贵界虹虾蚁思蚂虽品咽骂哗咱响哈咬咳哪炭峡罚贱贴骨钞
|
||||
钟钢钥钩卸缸拜看矩怎牲选适秒香种秋科重复竿段便俩贷顺修保促侮俭俗
|
||||
俘信皇泉鬼侵追俊盾待律很须叙剑逃食盆胆胜胞胖脉勉狭狮独狡狱狠贸怨
|
||||
急饶蚀饺饼弯将奖哀亭亮度迹庭疮疯疫疤姿亲音帝施闻阀阁差养美姜叛送
|
||||
类迷前首逆总炼炸炮烂剃洁洪洒浇浊洞测洗活派洽染济洋洲浑浓津恒恢恰
|
||||
恼恨举觉宣室宫宪突穿窃客冠语扁袄祖神祝误诱说诵垦退既屋昼费陡眉孩
|
||||
除险院娃姥姨姻娇怒架贺盈勇怠柔垒绑绒结绕骄绘给络骆绝绞统
|
Loading…
Reference in New Issue