本文整理汇总了C++中XMLNode::IterateChild方法的典型用法代码示例。如果您正苦于以下问题:C++ XMLNode::IterateChild方法的具体用法?C++ XMLNode::IterateChild怎么用?C++ XMLNode::IterateChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLNode
的用法示例。
在下文中一共展示了XMLNode::IterateChild方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AddTexPack
//----------------------------------------------------------------------------
bool ResourceManager::AddTexPack (const std::string &texPackPath)
{
if (mTexPacks.find(texPackPath) != mTexPacks.end())
return false;
int bufferSize = 0;
char *buffer = 0;
if (GetBuffer(texPackPath, bufferSize, buffer))
{
std::string outPath;
std::string outBaseName;
std::string outExt;
StringHelp::SplitFullFilename(texPackPath, outPath, outBaseName, outExt);
XMLData data;
if (data.LoadBuffer(buffer, bufferSize))
{
XMLNode rootNode = data.GetRootNode();
std::string imagePath = rootNode.AttributeToString("imagePath");
int width = rootNode.AttributeToInt("width");
int height = rootNode.AttributeToInt("height");
TexPack pack;
pack.ImagePath = imagePath;
pack.Width = width;
pack.Height = height;
XMLNode childNode = rootNode.IterateChild();
while (!childNode.IsNull())
{
std::string eleName;
int x = 0;
int y = 0;
int w = 0;
int h = 0;
int oX = 0;
int oY = 0;
int oW = 0;
int oH = 0;
bool rolated = false;
if (childNode.HasAttribute("n"))
eleName = childNode.AttributeToString("n");
if (childNode.HasAttribute("x"))
x = childNode.AttributeToInt("x");
if (childNode.HasAttribute("y"))
y = childNode.AttributeToInt("y");
if (childNode.HasAttribute("w"))
w = childNode.AttributeToInt("w");
if (childNode.HasAttribute("h"))
h = childNode.AttributeToInt("h");
if (childNode.HasAttribute("oX"))
oX = childNode.AttributeToInt("oX");
if (childNode.HasAttribute("oY"))
oY = childNode.AttributeToInt("oY");
if (childNode.HasAttribute("oW"))
oW = childNode.AttributeToInt("oW");
if (childNode.HasAttribute("oH"))
oH = childNode.AttributeToInt("oH");
if (childNode.HasAttribute("r"))
rolated = (std::string(childNode.AttributeToString("r"))=="y");
TexPackElement ele;
ele.X = x;
ele.Y = y;
ele.W = w;
ele.H = h;
ele.OX = oX;
ele.OY = oY;
ele.OW = oW;
ele.OH = oH;
ele.Rolated = rolated;
ele.TexWidth = width;
ele.TexHeight = height;
ele.ElementName = eleName;
ele.ImagePathFull = outPath+imagePath;
pack.Elements.push_back(ele);
std::string allStr = texPackPath+eleName;
mPackElements[allStr] = ele;
childNode = rootNode.IterateChild(childNode);
}
mTexPacks[texPackPath] = pack;
}
delete1(buffer);
return true;
}
return false;
}
示例2: Initlize
//----------------------------------------------------------------------------
bool FontBitmapImpl::Initlize (int fontWidth, int fontHeight,
const char *fontFilename, CharCodingType codingType, unsigned int fontExtStyle)
{
Font::Initlize(fontWidth, fontHeight, fontFilename, codingType, fontExtStyle);
mFontFilename = fontFilename;
if (CCT_UTF8 == codingType)
{
mCharCodingObj = new0 CharCodingUTF8();
}
else if (CCT_GBK == codingType)
{
mCharCodingObj = new0 CharCodingGBK();
}
mGlyphMap = this;
std::string outPath;
std::string outBaseFilename;
StringHelp::SplitFilename(fontFilename, outPath, outBaseFilename);
int bufferSize = 0;
char *buffer = 0;
if (PX2_RM.LoadBuffer(fontFilename, bufferSize, buffer))
{
XMLData data;
if (data.LoadBuffer(buffer, bufferSize))
{
float imageWidth = 0.0f;
float imageHeight = 0.0f;
XMLNode rootNode = data.GetRootNode();
XMLNode child = rootNode.IterateChild();
while (!child.IsNull())
{
const std::string &nodeName = child.GetName();
if ("image" == nodeName)
{
const char *text = child.GetText();
std::string imagePath = outPath + text;
mFontTex = DynamicCast<Texture2D>(PX2_RM.BlockLoad(imagePath));
if (mFontTex)
{
imageWidth = (float)mFontTex->GetWidth();
imageHeight = (float)mFontTex->GetHeight();
}
}
else if ("symbol" == nodeName)
{
std::string ch = child.GetChild("char").GetText();
int x = StringHelp::StringToInt(child.GetChild("x").GetText());
int y = StringHelp::StringToInt(child.GetChild("y").GetText());
int width = StringHelp::StringToInt(child.GetChild("width").GetText());
int height = StringHelp::StringToInt(child.GetChild("height").GetText());
unsigned int unicode = mCharCodingObj->ToUnicode((const unsigned char*)ch.c_str());
BitmapFontGlyph glyph;
glyph.X = x;
glyph.Y = y;
glyph.numWidth = width;
glyph.numHeight = height;
float u0 = (float)x/imageWidth;
float v0 = 1.0f-(float)(y+height)/imageHeight;
float u1 = (x+width)/imageWidth;
float v1 = v0 + (float)height/imageHeight;
glyph.RectUV = Rectf(u0, v0, u1, v1);
mMapGlyph[unicode] = glyph;
}
child = rootNode.IterateChild(child);
}
}
}
return true;
}