//frompath (import) has two varieties: they will take // - take a folder containing all elements, each with a char number // - take a simple png //fromstream (load) will take the png and all the rectangles, and the char maps from stream //save will save as .font public static new FontSheet Import(string path) { //get all extra stat from an XML if (File.Exists(path + "FontData.xml")) { XmlDocument doc = new XmlDocument(); doc.Load(path + "FontData.xml"); int spaceWidth = Convert.ToInt32(doc.SelectSingleNode("FontData/SpaceWidth").InnerText); int charHeight = Convert.ToInt32(doc.SelectSingleNode("FontData/CharHeight").InnerText); int charSpace = Convert.ToInt32(doc.SelectSingleNode("FontData/CharSpace").InnerText); int lineSpace = Convert.ToInt32(doc.SelectSingleNode("FontData/LineSpace").InnerText); HashSet <int> colorlessGlyphs = new HashSet <int>(); XmlNode glyphNodes = doc.SelectSingleNode("FontData/Colorless"); foreach (XmlNode glyphNode in glyphNodes.SelectNodes("Glyph")) { int glyphIdx = Convert.ToInt32(glyphNode.InnerText, 16); colorlessGlyphs.Add(glyphIdx); } string[] pngs = Directory.GetFiles(path, "*.png", SearchOption.TopDirectoryOnly); List <ImageInfo> sheets = new List <ImageInfo>(); foreach (string dir in pngs) { int png = Convert.ToInt32(Path.GetFileNameWithoutExtension(dir), 16); Texture2D newSheet = null; using (FileStream fileStream = new FileStream(dir, FileMode.Open, FileAccess.Read, FileShare.Read)) newSheet = ImportTex(fileStream); sheets.Add(new ImageInfo(png, newSheet)); } if (sheets.Count == 0) { return(null); } Canvas canvas = new Canvas(); canvas.SetCanvasDimensions(Canvas.INFINITE_SIZE, Canvas.INFINITE_SIZE); OptimalMapper mapper = new OptimalMapper(canvas, 0.975f, 10); Atlas atlas = mapper.Mapping(sheets); Rectangle[] rects = new Rectangle[sheets.Count]; Dictionary <int, GlyphData> chars = new Dictionary <int, GlyphData>(); Texture2D tex = new Texture2D(device, atlas.Width, atlas.Height); for (int ii = 0; ii < atlas.MappedImages.Count; ii++) { MappedImageInfo info = atlas.MappedImages[ii]; BaseSheet.Blit(info.ImageInfo.Texture, tex, 0, 0, info.ImageInfo.Width, info.ImageInfo.Height, info.X, info.Y); rects[ii] = new Rectangle(info.X, info.Y, info.ImageInfo.Width, info.ImageInfo.Height); chars[info.ImageInfo.ID] = new GlyphData(ii, colorlessGlyphs.Contains(info.ImageInfo.ID)); info.ImageInfo.Texture.Dispose(); } return(new FontSheet(tex, rects, spaceWidth, charHeight, charSpace, lineSpace, chars)); } else { throw new Exception("Error finding XML file in " + path + "."); } }
public List <IMappedImageInfo> Liste_avion(int id_hangar) { int x = 0; ConsoleManager.Show(); Console.WriteLine("connection non open"); connection.Open(); ConsoleManager.Show(); Console.WriteLine("connection open"); MySqlCommand command = connection.CreateCommand(); command.CommandText = "select id, width, length from plane where id_hangar=@ln"; command.Parameters.AddWithValue("@ln", id_hangar); MySqlDataReader reader1; reader1 = command.ExecuteReader(); ConsoleManager.Show(); Console.WriteLine("commande executé"); //parcours deux fois la ligne donc va au resultat de la deuxieme ligne de la colonne 0 /* exemple de manipulation du resultat */ while (reader1.Read()) { x++; } ConsoleManager.Show(); Console.WriteLine(x); connection.Close(); connection.Open(); MySqlCommand commandb = connection.CreateCommand(); commandb.CommandText = "select id, width, length, x, y from plane INNER JOIN optimisation ON plane.id=optimisation.id_plane where optimisation.id_hangar=@ln"; commandb.Parameters.AddWithValue("@ln", id_hangar); List <IMappedImageInfo> liste = new List <IMappedImageInfo>(); MySqlDataReader reader2 = commandb.ExecuteReader(); int l = 0; while (l != x) { reader2.Read(); ImageInfo image = new ImageInfo(reader2.GetInt32(0), reader2.GetInt32(1), reader2.GetInt32(2)); MappedImageInfo maped = new MappedImageInfo(reader2.GetInt32(3), reader2.GetInt32(4), image); liste.Add(maped); ConsoleManager.Show(); Console.WriteLine(reader2.GetInt32(0)); l++; } return(liste); }
//frompath (import) will take a folder containing all elements //fromstream (load) will take the png and all the rectangles from stream //save will save as .atlas public static new SpriteSheet Import(string path) { string[] pngs = Directory.GetFiles(path, "*.png", SearchOption.TopDirectoryOnly); List <ImageInfo> sheets = new List <ImageInfo>(); int index = 0; foreach (string dir in pngs) { Texture2D newSheet = null; using (FileStream fileStream = new FileStream(dir, FileMode.Open, FileAccess.Read, FileShare.Read)) newSheet = ImportTex(fileStream); sheets.Add(new ImageInfo(index, newSheet)); index++; } if (sheets.Count == 0) { return(null); } Canvas canvas = new Canvas(); canvas.SetCanvasDimensions(Canvas.INFINITE_SIZE, Canvas.INFINITE_SIZE); OptimalMapper mapper = new OptimalMapper(canvas); Atlas atlas = mapper.Mapping(sheets); Rectangle[] rects = new Rectangle[sheets.Count]; Texture2D tex = new Texture2D(device, atlas.Width, atlas.Height); for (int ii = 0; ii < atlas.MappedImages.Count; ii++) { MappedImageInfo info = atlas.MappedImages[ii]; BaseSheet.Blit(info.ImageInfo.Texture, tex, 0, 0, info.ImageInfo.Width, info.ImageInfo.Height, info.X, info.Y); rects[info.ImageInfo.ID] = new Rectangle(info.X, info.Y, info.ImageInfo.Width, info.ImageInfo.Height); info.ImageInfo.Texture.Dispose(); } return(new SpriteSheet(tex, rects)); }