Post-execution effects:
Front-End use:
Backstage Superrichtext Parsing code
void Superrichtext::rendernode (Tinyxml2::xmlnode *node) {
while (NODE!=NULLPTR) {
if (Node->totext ()) {
Cclog ("Text info:%s", Node->totext ()->value ());
Auto N=node->totext ();
std::u16string text;
Stringutils::utf8toutf16 (N->value (), text);
Std::u16string::size_type pos=0;
Pos=text.find (' \ n ');
while ((Pos!=std::u16string::npos)) {
Text.erase (pos,1);
Pos=text.find (' \ n ', POS);
}
pos=0;
Pos=text.find (' \ R ');
while ((Pos!=std::u16string::npos)) {
Text.erase (pos,1);
Pos=text.find (' \ R ', POS);
}
Std::string Utf8text;
Stringutils::utf16toutf8 (Text,utf8text);
Auto Font=_fontlist[_fontlist.size ()-1];
Auto Textelement=ui::richelementtext::create (0,font.color,font.opacity,utf8text,font.fontname,font.fontsize);
_line->pushbackelement (TextElement);
}else if (node->toelement ()) {
Auto N=node->toelement ();
std::string name=n->name ();
Std::transform (Name.begin (), Name.end (), Name.begin (),:: ToUpper);
if (name== "FONT") {
Cclog ("Font label");
Auto Attr=n->firstattribute ();
FontInfo newfont=_fontlist[_fontlist.size ()-1];
while (ATTR!=NULLPTR) {
Traverse All Properties
std::string attrname=attr->name ();
Std::transform (Attrname.begin (), Attrname.end (), Attrname.begin (),:: ToUpper);
if (attrname== "face") {
Set font
Newfont.fontname=attr->value ();
}else if (attrname== "COLOR") {
Set color
NEWFONT.COLOR=CHARTOCOLOR3B (Attr->value ());
}else if (attrname== "SIZE") {
Set size
Newfont.fontsize=attr->intvalue ();
}else if (attrname== "OPACITY") {
Set opacity
Newfont.opacity=attr->intvalue ();
}
Attr=attr->next ();
}
_fontlist.push_back (NewFont);//Add a new font
Rendernode (N->firstchild ());//Continue rendering subset
_fontlist.pop_back ();//Remove new font
}else if (name== "IMG") {
Cclog ("Picture label");
Properties of the picture label
Auto Attr=n->firstattribute ();
const char *SRC;
color3b Col (255,255,255);
Glubyte opacity=255;
while (ATTR!=NULLPTR) {
Traverse All Properties
std::string attrname=attr->name ();
Std::transform (Attrname.begin (), Attrname.end (), Attrname.begin (),:: ToUpper);
if (attrname== "SRC") {
Set Picture path
Src=attr->value ();
}else if (attrname== "COLOR") {
Set color
COL=CHARTOCOLOR3B (Attr->value ());
}else if (attrname== "OPACITY") {
Set opacity
Opacity=attr->intvalue ();
}
Attr=attr->next ();
}
Auto Img=ui::richelementimage::create (0,COL,OPACITY,SRC);
_line->pushbackelement (IMG);
}else if (name== "BR") {
Cclog ("newline label");
Addnewline ();
}
}
Node=node->nextsibling ();
}
}
Cocos2d-x using Rich text controls to parse Xhml tags (text labels, picture labels, wrap labels, label properties)