public void Compile() { if (Target.InputPaths.Count != 1) { throw new ContentFileException(Target.RawTarget.Name, "One input file expected"); } if (Target.OutputPaths.Count != 1) { throw new ContentFileException(Target.RawTarget.Name, "One output file expected"); } ParsedPath pinboardPath = Target.InputPaths[0]; ParsedPath jsonPath = Target.OutputPaths[0]; PinboardFileV1 pinboard = PinboardFileCache.Load(pinboardPath); Rectangle[] rectangles = new Rectangle[pinboard.RectInfos.Count + 1]; rectangles[0] = new Rectangle(pinboard.ScreenRectInfo.X, pinboard.ScreenRectInfo.Y, pinboard.ScreenRectInfo.Width, pinboard.ScreenRectInfo.Height); for (int i = 0; i < pinboard.RectInfos.Count; i++) { rectangles[i + 1] = new Rectangle(pinboard.RectInfos[i].X, pinboard.RectInfos[i].Y, pinboard.RectInfos[i].Width, pinboard.RectInfos[i].Height); } if (!Directory.Exists(jsonPath.VolumeAndDirectory)) { Directory.CreateDirectory(jsonPath.VolumeAndDirectory); } // TODO: Write out the file throw new NotImplementedException(); }
public static PinboardFileV1 Load(ParsedPath pinboardFileName) { PinboardFileV1 data = null; if (pinboardFiles == null) { pinboardFiles = new Dictionary <ParsedPath, PinboardFileV1>(); } if (pinboardFiles.TryGetValue(pinboardFileName, out data)) { return(data); } try { data = PinboardFileReaderV1.ReadFile(pinboardFileName); } catch { throw new ContentFileException("Unable to read pinboard file '{0}'".CultureFormat(pinboardFileName)); } pinboardFiles.Add(pinboardFileName, data); return(data); }
private RectanglesContent CreateRectangleData(IEnumerable <ParsedPath> distinctPinboardFiles, Dictionary <ParsedPath, PinboardFileV1> pinboards) { RectanglesContent rectData = new RectanglesContent(); rectData.Namespace = Target.Properties.GetRequiredValue("Namespace"); rectData.Classes = new List <RectanglesContent.Class>(); foreach (var pinboardFile in distinctPinboardFiles) { PinboardFileV1 pinboard = pinboards[pinboardFile]; RectanglesContent.Class rectClass = new RectanglesContent.Class(); rectClass.ClassNamePrefix = pinboardFile.File; List <string> names = new List <string>(); names.Add("Screen"); foreach (var rectInfo in pinboard.RectInfos) { names.Add(rectInfo.Name); } rectClass.RectangleNames = names; rectData.Classes.Add(rectClass); } return(rectData); }
private void SetPinboardData(PinboardFileV1 data) { this.data = data; this.pinboardControl.Data = data; this.pinboardControl.Visible = true; if (!this.propertiesForm.Visible) { this.propertiesForm.Show(this); } }
private void OpenFile(string fileName) { PinboardFileV1 data = null; try { data = PinboardFileReaderV1.ReadFile(new ParsedPath(fileName, PathType.File)); } catch { MessageBox.Show("Unable to load pinboard file", "Error Loading File", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.fileName = fileName; SetPinboardData(data); SetPinboardSize(); }
public void Compile() { ParsedPath pinboardFileName = Target.InputFiles.Where(f => f.Extension == ".pinboard").First(); ParsedPath xnbFileName = Target.OutputFiles.Where(f => f.Extension == ".xnb").First(); PinboardFileV1 pinboard = PinboardFileCache.Load(pinboardFileName); Rectangle[] rectangles = new Rectangle[pinboard.RectInfos.Count + 1]; rectangles[0] = new Rectangle(pinboard.ScreenRectInfo.X, pinboard.ScreenRectInfo.Y, pinboard.ScreenRectInfo.Width, pinboard.ScreenRectInfo.Height); for (int i = 0; i < pinboard.RectInfos.Count; i++) { rectangles[i + 1] = new Rectangle(pinboard.RectInfos[i].X, pinboard.RectInfos[i].Y, pinboard.RectInfos[i].Width, pinboard.RectInfos[i].Height); } if (!Directory.Exists(xnbFileName.VolumeAndDirectory)) { Directory.CreateDirectory(xnbFileName.VolumeAndDirectory); } XnbFileWriterV5.WriteFile(rectangles, xnbFileName); }
private void ReconcilePinboards( IEnumerable <ParsedPath> pinboardFiles, IEnumerable <ParsedPath> distinctPinboardFiles, Dictionary <ParsedPath, PinboardFileV1> pinboards) { foreach (var distinctPinboardFile in distinctPinboardFiles) { PinboardFileV1 goldPinboard = null; ParsedPath goldPinboardFile = null; foreach (var pinboardFile in pinboardFiles.Where(p => p.File == distinctPinboardFile.File)) { if (goldPinboard == null) { goldPinboard = pinboards[pinboardFile]; goldPinboardFile = pinboardFile; } else { PinboardFileV1 pinboard = pinboards[pinboardFile]; if (goldPinboard.RectInfos.Count != pinboard.RectInfos.Count) { throw new ContentFileException(Context.ContentFile, Target.LineNumber, string.Format("Pinboard '{0}' and '{1}' have a different number of rectangles", goldPinboardFile, pinboardFile)); } for (int i = 0; i < goldPinboard.RectInfos.Count; i++) { if (goldPinboard.RectInfos[i].Name != pinboard.RectInfos[i].Name) { throw new ContentFileException(Context.ContentFile, Target.LineNumber, string.Format("RectangleInfo named {0} at depth {1} in pinboard '{2}' is different from pinboard '{3}'", goldPinboard.RectInfos[i].Name, i, goldPinboardFile, pinboardFile)); } } } } } }
private Dictionary <ParsedPath, PinboardFileV1> ReadPinboardFiles(IEnumerable <ParsedPath> pinboardFiles) { Dictionary <ParsedPath, PinboardFileV1> pinboards = new Dictionary <ParsedPath, PinboardFileV1>(); foreach (var pinboardFile in pinboardFiles) { Context.Output.Message(MessageImportance.Low, "Reading pinboard file '{0}'", pinboardFile); PinboardFileV1 pinboard = null; try { pinboard = PinboardFileReaderV1.ReadFile(pinboardFile); } catch (Exception e) { throw new ContentFileException(Context.ContentFile, Target.LineNumber, String.Format("Unable to read pinboard file '{0}'", pinboardFile), e); } pinboards.Add(pinboardFile, pinboard); } return(pinboards); }
public void Compile() { IEnumerable <ParsedPath> svgFileNames = Target.InputFiles.Where(f => f.Extension == ".svg"); ParsedPath pinboardFileName = Target.InputFiles.Where(f => f.Extension == ".pinboard").First(); ParsedPath xnbFileName = Target.OutputFiles.Where(f => f.Extension == ".xnb").First(); PinboardFileV1 pinboardFile = PinboardFileCache.Load(pinboardFileName); List <ImagePlacement> placements = new List <ImagePlacement>(); string rectangleName = this.Target.Properties.GetRequiredValue("Rectangle"); PinboardFileV1.RectangleInfo rectInfo = pinboardFile.GetRectangleInfoByName(rectangleName); if (rectInfo == null) { throw new ContentFileException("Rectangle {0} not found in pinboard file {1}".CultureFormat(rectangleName, pinboardFileName)); } string converterName = Target.Properties.GetOptionalValue("Converter", "Inkscape").ToLower(); if (converterName != "inkscape" && converterName != "rsvg") { throw new ContentFileException("Unknown SVG converter '{0}'".CultureFormat(converterName)); } ParsedPath combinedPngPathName = xnbFileName.WithExtension(".png"); try { int row = 0; foreach (var svgFileName in svgFileNames) { int col = 0; if (rectInfo == null) { throw new InvalidOperationException( "Rectangle '{0}' not found in pinboard '{1}'".CultureFormat(rectangleName, pinboardFileName)); } // TODO-johnls: This should probably go in an intermediate file directory ParsedPath pngFile = xnbFileName.WithFileAndExtension(String.Format("{0}_{1}_{2}.png", svgFileName.File, row, col)); placements.Add(new ImagePlacement(pngFile, new Rectangle(col * rectInfo.Width, row * rectInfo.Height, rectInfo.Width, rectInfo.Height))); switch (converterName) { default: case "rsvg": ImageTools.SvgToPngWithRSvg(svgFileName, pngFile, rectInfo.Width, rectInfo.Height); break; case "inkscape": ImageTools.SvgToPngWithInkscape(svgFileName, pngFile, rectInfo.Width, rectInfo.Height); break; } } ImageTools.CombinePngs(placements, combinedPngPathName); Texture2DContent textureContent; ImageTools.CompressPngToTexture2DContent( combinedPngPathName, this.Target.Properties.GetOptionalValue("CompressionType", "None"), out textureContent); XnbFileWriterV5.WriteFile(textureContent, xnbFileName); } finally { foreach (var placement in placements) { if (File.Exists(placement.ImageFile)) { File.Delete(placement.ImageFile); } } if (File.Exists(combinedPngPathName)) { File.Delete(combinedPngPathName); } } }
public void Compile() { IEnumerable <ParsedPath> svgPaths = Target.InputFiles.Where(f => f.Extension == ".svg"); ParsedPath pinboardPath = Target.InputFiles.Where(f => f.Extension == ".pinboard").First(); ParsedPath pngPath = Target.OutputFiles.Where(f => f.Extension == ".png").First(); PinboardFileV1 pinboardFile = PinboardFileCache.Load(pinboardPath); List <ImagePlacement> placements = new List <ImagePlacement>(); string[] rectangleNames; Target.Properties.GetRequiredValue("Rectangles", out rectangleNames); if (svgPaths.Count() != rectangleNames.Length) { throw new ContentFileException("Number of .svg files ({0}) does match number of RectangleNames ({1})" .CultureFormat(svgPaths.Count(), rectangleNames.Length)); } string s = Target.Properties.GetOptionalValue("Rotation", "None"); ImageRotation rotation; if (!Enum.TryParse(s, out rotation)) { throw new ContentFileException("Invalid value '{0}' for given for rotation. Valid are None, Left, Right, UpsideDown".CultureFormat(s)); } int i = 0; try { if (!Directory.Exists(pngPath.VolumeAndDirectory)) { Directory.CreateDirectory(pngPath.VolumeAndDirectory); } foreach (var svgPath in svgPaths) { PinboardFileV1.RectangleInfo rectInfo = pinboardFile.GetRectangleInfoByName(rectangleNames[i]); ParsedPath tempPngPath = pngPath.WithFileAndExtension(String.Format("{0}_{1}.png", pngPath.File, i)); if (rectInfo == null) { throw new ContentFileException("Rectangle '{0}' not found in pinboard file '{1}'" .CultureFormat(rectangleNames[i], pinboardFile)); } ImageTools.SvgToPngWithInkscape(svgPath, tempPngPath, rectInfo.Width, rectInfo.Height); placements.Add(new ImagePlacement( tempPngPath, new Cairo.Rectangle(rectInfo.X, rectInfo.Y, rectInfo.Width, rectInfo.Height))); i++; } ImageTools.CombinePngs(placements, pngPath); ImageTools.RotatePng(pngPath, rotation); } finally { foreach (var placement in placements) { if (File.Exists(placement.ImageFile)) { File.Delete(placement.ImageFile); } } } }
private void ApplyButton_Click(object sender, EventArgs e) { applyButton.Focus(); if (inErrorState) { ResetColors(); } inErrorState = true; PinboardFileV1 data = pinboardControl.Data; PinboardFileV1.RectangleInfo selection = pinboardControl.Selection; int selectionIndex = pinboardControl.SelectionIndex; if (pinboardControl.SelectionIndex == -1) { Size savedSize = selection.Size; int width; if (!int.TryParse(widthTextBox.Text, out width) || width < 128 || width > 2048) { widthTextBox.ForeColor = Color.Red; widthTextBox.Focus(); return; } selection.Width = width; int height; if (!int.TryParse(heightTextBox.Text, out height) || height < 128 || height > 2048) { heightTextBox.ForeColor = Color.Red; heightTextBox.Focus(); return; } selection.Height = height; RaiseScreenSizeChangedEvent(savedSize); } else { string name = nameTextBox.Text; bool duplicate = false; if (name != selection.Name) { if (name == data.ScreenRectInfo.Name) { duplicate = true; } else { for (int i = 0; i < data.RectInfos.Count; i++) { if (i == selectionIndex) { continue; } PinboardFileV1.RectangleInfo rectInfo = data.RectInfos[i]; if (name == rectInfo.Name) { duplicate = true; break; } } } } if (name.Length == 0 || duplicate) { nameTextBox.ForeColor = Color.Red; nameTextBox.Focus(); return; } selection.Name = name; int x; if (!int.TryParse(xTextBox.Text, out x) || x < 0 || x > data.ScreenRectInfo.Width - selection.Width) { xTextBox.ForeColor = Color.Red; xTextBox.Focus(); return; } selection.X = x; int y; if (!int.TryParse(yTextBox.Text, out y) || y < 0 || y > data.ScreenRectInfo.Height - selection.Height) { yTextBox.ForeColor = Color.Red; yTextBox.Focus(); return; } selection.Y = y; int width; if (!int.TryParse(widthTextBox.Text, out width) || width < 1 || width > data.ScreenRectInfo.Width - selection.X) { widthTextBox.ForeColor = Color.Red; widthTextBox.Focus(); return; } selection.Width = width; int height; if (!int.TryParse(heightTextBox.Text, out height) || height < 1 || height > data.ScreenRectInfo.Height - selection.Y) { heightTextBox.ForeColor = Color.Red; heightTextBox.Focus(); return; } selection.Height = height; } inErrorState = false; pinboardControl.DataDirty = true; }