//---------------------------------------------------------------------------- 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; }
//---------------------------------------------------------------------------- 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; }
//---------------------------------------------------------------------------- bool Project::Load(const std::string &filename) { std::string name; int width = 0; int height = 0; std::string sceneFilename; std::string uiFilename; std::string languageFilename; char *buffer = 0; int bufferSize = 0; if (PX2_RM.LoadBuffer(filename, bufferSize, buffer)) { XMLData data; if (data.LoadBuffer(buffer, bufferSize)) { XMLNode rootNode = data.GetRootNode(); // general XMLNode generalNode = rootNode.GetChild("general"); if (!generalNode.IsNull()) { name = generalNode.AttributeToString("name"); SetScreenOrientation(_FromSOStr(generalNode.AttributeToString("screenorientation"))); width = generalNode.AttributeToInt("width"); height = generalNode.AttributeToInt("height"); std::string colorStr = generalNode.AttributeToString("backcolor"); StringTokenizer stk(colorStr, ","); Float4 color = Float4::MakeColor( StringHelp::StringToInt(stk[0]), StringHelp::StringToInt(stk[1]), StringHelp::StringToInt(stk[2]), StringHelp::StringToInt(stk[3])); std::string projcolorStr = generalNode.AttributeToString("projcolor"); StringTokenizer stkprojcolor(projcolorStr, ","); Float4 projcolor = Float4::MakeColor( StringHelp::StringToInt(stkprojcolor[0]), StringHelp::StringToInt(stkprojcolor[1]), StringHelp::StringToInt(stkprojcolor[2]), StringHelp::StringToInt(stkprojcolor[3])); Sizef size = Sizef((float)width, (float)height); SetName(name); SetSize(size); mViewRect = Rectf(0.0f, 0.0f, size.Width, size.Height); SetBackgroundColor(color); SetProjBackgroundColor(projcolor); } // scene XMLNode sceneNode = rootNode.GetChild("scene"); if (!sceneNode.IsNull()) { sceneFilename = sceneNode.AttributeToString("filename"); SetSceneFilename(sceneFilename); } XMLNode renderNode = rootNode.GetChild("render_setting"); if (!renderNode.IsNull()) { } // language XMLNode languageNode = rootNode.GetChild("language"); // publish XMLNode publishNode = rootNode.GetChild("publish"); // setting XMLNode settingNode = rootNode.GetChild("setting"); if (!settingNode.IsNull()) { if (settingNode.HasAttribute("uicamerapercent")) mEdit_UICameraPercent = settingNode.AttributeToFloat("uicamerapercent"); } // split file names std::string outPath; std::string outBaseName; std::string outExt; StringHelp::SplitFullFilename(filename, outPath, outBaseName, outExt); // ui mUIFilename = outPath + outBaseName + "_ui.px2obj"; } } else { return false; } return true; }