Browse Source

Add text next to each hole

main
Starbeamrainbowlabs 2 years ago
parent
commit
e9f5f73668
Signed by: sbrl GPG Key ID: 1BE5172E637709C2
  1. 8
      MusicBoxConverter/MusicBoxScoreGenerator.cs
  2. 20
      MusicBoxConverter/SvgWriter.cs

8
MusicBoxConverter/MusicBoxScoreGenerator.cs

@ -130,6 +130,7 @@ namespace MusicBoxConverter
svg.WriteRectangle(Offset, area, "red", 0.75f);
int noteIndex = 0;
foreach (Note note in AllNotes())
{
if(Debug) {
@ -155,6 +156,13 @@ namespace MusicBoxConverter
new Vector2(HoleSize, HoleSize)
);
svg.WriteText(
holePosition.Subtract(new Vector2(-HoleSize * 2, HoleSize/2 + -svg.FontSizeRegular/2)),
$"{noteIndex}",
"regular"
);
noteIndex++;
}
svg.Complete();

20
MusicBoxConverter/SvgWriter.cs

@ -27,6 +27,10 @@ namespace MusicBoxConverter
public string UnitSuffix { get; set; } = "";
public float FontSizeRegular { get; set; } = 3;
private bool haveWrittenFontStyles = false;
public SvgWriter(string outputFilename, string widthspec = "100%", string heightspec = "100%", Rectangle viewBox = null)
{
xml = XmlWriter.Create(
@ -57,6 +61,22 @@ namespace MusicBoxConverter
xml.Close();
}
public void WriteText(Vector2 pos, string text, string className)
{
if (!haveWrittenFontStyles)
{
xml.WriteElementString("style", $".regular {{ font: {FontSizeRegular}{UnitSuffix} sans-serif; }}");
haveWrittenFontStyles = true;
}
xml.WriteStartElement("text");
xml.WriteAttributeString("x", $"{pos.X}{UnitSuffix}");
xml.WriteAttributeString("y", $"{pos.Y}{UnitSuffix}");
xml.WriteAttributeString("class", className);
xml.WriteString(text);
xml.WriteEndElement();
}
public void WriteLine(Vector2 start, Vector2 end, string strokeStyle = "darkgreen", float strokeWidth = 3)
{
xml.WriteStartElement("line");

Loading…
Cancel
Save