Browse Source

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

main
Starbeamrainbowlabs 4 years ago
parent
commit
bd774bc67c
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
  1. 5
      MusicBoxConverter/MusicBoxScoreGenerator.cs
  2. 17
      MusicBoxConverter/SvgWriter.cs

5
MusicBoxConverter/MusicBoxScoreGenerator.cs

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

17
MusicBoxConverter/SvgWriter.cs

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;
using System.Xml;
using SBRL.Utilities;
@ -17,6 +18,9 @@ namespace MusicBoxConverter @@ -17,6 +18,9 @@ namespace MusicBoxConverter
}
}
/// <summary>
/// TODO: Replace this with the (much) better version from the FloatingIslands
/// </summary>
public class SvgWriter
{
public XmlWriter xml;
@ -106,5 +110,18 @@ namespace MusicBoxConverter @@ -106,5 +110,18 @@ namespace MusicBoxConverter
xml.WriteAttributeString("fill", fillStyle);
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();
}
}
}

Loading…
Cancel
Save