Port AddPolygon -> WritePolygon from the FloatingIslands, but we should consider creating a NuGet package.

This commit is contained in:
Starbeamrainbowlabs 2019-02-22 01:06:01 +00:00
parent c48a5d01ce
commit bd774bc67c
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
2 changed files with 20 additions and 2 deletions

View File

@ -69,8 +69,9 @@ namespace MusicBoxConverter
SvgWriter svg = new SvgWriter( SvgWriter svg = new SvgWriter(
destinationFilename, destinationFilename,
$"{size.X}mm", $"{size.Y}mm" $"{size.X}mm", $"{size.Y}mm"
); ) {
svg.UnitSuffix = "mm"; UnitSuffix = "mm"
};
// Draw the note lines // Draw the note lines
for(float i = 0; i < area.Y; i += ScaleFactor.Y) { for(float i = 0; i < area.Y; i += ScaleFactor.Y) {

View File

@ -1,5 +1,6 @@
using System; using System;
using System.IO; using System.IO;
using System.Linq;
using System.Xml; using System.Xml;
using SBRL.Utilities; using SBRL.Utilities;
@ -17,6 +18,9 @@ namespace MusicBoxConverter
} }
} }
/// <summary>
/// TODO: Replace this with the (much) better version from the FloatingIslands
/// </summary>
public class SvgWriter public class SvgWriter
{ {
public XmlWriter xml; public XmlWriter xml;
@ -106,5 +110,18 @@ namespace MusicBoxConverter
xml.WriteAttributeString("fill", fillStyle); xml.WriteAttributeString("fill", fillStyle);
xml.WriteEndElement(); xml.WriteEndElement();
} }
/// <summary>
/// Adds a solid n-sided polygon to the image.
/// </summary>
/// <param name="fillStyle">The colour to fill the polygon with.</param>
/// <param name="points">The co-ordinates that make up the polygon.</param>
public void WritePolygon(string fillStyle, params Vector2[] points)
{
xml.WriteStartElement("polygon");
xml.WriteAttributeString("fill", fillStyle);
string pointsSpec = string.Join(" ", points.Select((Vector2 point) => $"{point.X},{point.Y}"));
xml.WriteAttributeString("points", pointsSpec);
xml.WriteEndElement();
}
} }
} }