bool TextureAtlas::LoadFromFile(const std::string& filePath) { FileManager fr; fr.OpenFile(filePath); tinyxml2::XMLDocument doc; if (doc.Parse(fr.ReadText().c_str())) return false; const tinyxml2::XMLElement* element = doc.FirstChildElement(); m_texture = uthRS.LoadTexture(element->FindAttribute("imagePath")->Value()); if (!m_texture) return false; for (const tinyxml2::XMLElement* child = element->FirstChildElement(); child != nullptr; child = child->NextSiblingElement()) { std::string name(child->FindAttribute("name")->Value()); pmath::Rect rect; float x = child->FindAttribute("x")->FloatValue(), y = child->FindAttribute("y")->FloatValue(); rect.position.x = x / m_texture->GetSize().x; rect.position.y = y / m_texture->GetSize().y; rect.size.x = child->FindAttribute("width")->FloatValue() / m_texture->GetSize().x; rect.size.y = child->FindAttribute("height")->FloatValue() / m_texture->GetSize().y; m_textureRects.insert(std::make_pair(name, rect)); } return true; }
bool Font::LoadFromFile(const std::string& filePath) { FileManager fr; fr.OpenFile(filePath); m_fontData = fr.ReadBinary(); if (!m_fontData.ptr()) return false; m_loaded = true; return true; }
int main(int argc, char *argv[]) { if (argc < 2) { usage(); return 0; } FileManager fm; Utils u; Editor ed (fm); const char *fileName; int fopenfileatline = FALSE; int ffde = FALSE; int fhelp = FALSE, fvers = FALSE; for (int i = 0; i < argc; i++) { if ((strcmp("-h", argv[i]) == 0) || (strcmp("--help", argv[i]) == 0)) { show_help(); fhelp = TRUE; break; } if ((strcmp("--version", argv[i]) == 0)) { show_version(); fvers = TRUE; break; } if (argv[i][0] == '+') { fopenfileatline = TRUE; break; } if (fm.FileExists(argv[i]) < 0) { ffde = TRUE; fileName = argv[i]; break; } } // Check flags if (fhelp || fvers) return 0; if (ffde) { if (fm.CreateFile(fileName) == 0) { if (fm.OpenFile(fileName) < 0) { printf("[" RED "*" NORMAL "] No se pudo abrir el archivo \"%s\"\n", fileName); return -1; } else { if (ed.EditFile() < 0) { printf("[" RED "*" NORMAL "] No se pudo editar el archivo \"%s\"\n", fileName); return -1; } } } else printf("[" RED "*" NORMAL "] No se pudo crear el archivo \"%s\"\n", fileName); } else { if (fopenfileatline) { } else { if (fm.OpenFile(fileName) < 0) { printf("[" RED "*" NORMAL "] No se pudo abrir el archivo \"%s\"\n", fileName); return -1; } else { if (ed.EditFile() < 0) { printf("[" RED "*" NORMAL "] No se pudo editar el archivo \"%s\"\n", fileName); return -1; } } } } return 0; }