private void btnLoadSprite_Click(object sender, EventArgs e) { if (openFile.ShowDialog() != DialogResult.OK) { return; } Sprite spTest = null; string filename = openFile.FileName; try { spTest = new Sprite(filename, int.Parse(txtWidth.Text), int.Parse(txtHeight.Text)); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.GetType().Name); System.Diagnostics.Debug.WriteLine(ex.Message); } if (spTest != null) { SetSprite(spTest); } else { // since loading the sprite from the file failed, try it as a resource file. AgateResourceCollection resources = AgateResourceLoader.LoadResources(filename); AgateFileProvider.Images.Clear(); AgateFileProvider.Images.AddPath(System.IO.Path.GetDirectoryName(filename)); if (resources.Sprites.ToArray().Length == 1) { var sprites = resources.Sprites.ToArray(); Sprite sp = new Sprite(resources, sprites[0].Name); SetSprite(sp); } else { frmChooseSprite frm = new frmChooseSprite(); if (frm.ShowDialog(this, resources) == DialogResult.OK) { Sprite sp = new Sprite(resources, frm.SelectedSprite); SetSprite(sp); } } } }
/// <summary> /// Returns true if the file was saved and an existing operation should /// continue. /// </summary> /// <returns></returns> private bool Save(AgateResourceCollection resources) { try { AgateResourceLoader.SaveResources(resources, mFilename); return(true); } catch (IOException e) { MessageBox.Show("An error has occurred:" + Environment.NewLine + e.Message); return(false); } }
private void Open() { if (CloseFile() == false) { return; } if (openFileDialog.ShowDialog(this) == DialogResult.Cancel) { return; } Resources = AgateResourceLoader.LoadResources(openFileDialog.FileName); mFilename = openFileDialog.FileName; UpdateControls(); }
internal void SaveFont(string resourceFile, string fontName, string imageFile) { AgateResourceCollection resources; if (File.Exists(resourceFile)) { resources = AgateResourceLoader.LoadResources(resourceFile); } else { resources = new AgateResourceCollection(); } if (Path.IsPathRooted(resourceFile) == false) { resourceFile = Path.Combine(Directory.GetCurrentDirectory(), resourceFile); } string localImagePath; string dir = Path.GetDirectoryName(resourceFile); if (Path.IsPathRooted(imageFile) == false) { localImagePath = imageFile; imageFile = Path.Combine(Path.GetDirectoryName(resourceFile), imageFile); } else { localImagePath = GetRelativePath(dir, imageFile); } SaveImage(imageFile); localImagePath = localImagePath.Replace(Path.DirectorySeparatorChar.ToString(), "/"); BitmapFontResource res = new BitmapFontResource(fontName); res.Image = localImagePath; res.FontMetrics = ((BitmapFontImpl)Font.Impl).FontMetrics.Clone(); resources.Add(res); AgateResourceLoader.SaveResources(resources, resourceFile); }