Files
SoundFlix/FractalVisualizer/UI/HudBitmapFont.cs
T
Michal Vrba 6a1bdfb935 Add real-time note detection and NOTEDROP visualization
Implemented musical note detection in AudioAnalyzer, exposing dominant note and strength in AudioFeatures. Updated HUD to display detected note. Added "NOTEDROP" fractal preset that animates detected notes as colored glyphs. Extended bitmap font to support sharps. Increased fractal preset count and adjusted HUD layout.
2026-02-13 20:43:29 +01:00

87 lines
4.5 KiB
C#

using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace FractalVisualizer.UI;
public sealed class HudBitmapFont
{
private static readonly Dictionary<char, string[]> Glyphs = new()
{
['A'] = ["01110", "10001", "10001", "11111", "10001", "10001", "10001"],
['B'] = ["11110", "10001", "10001", "11110", "10001", "10001", "11110"],
['C'] = ["01111", "10000", "10000", "10000", "10000", "10000", "01111"],
['D'] = ["11110", "10001", "10001", "10001", "10001", "10001", "11110"],
['E'] = ["11111", "10000", "10000", "11110", "10000", "10000", "11111"],
['F'] = ["11111", "10000", "10000", "11110", "10000", "10000", "10000"],
['G'] = ["01111", "10000", "10000", "10111", "10001", "10001", "01111"],
['H'] = ["10001", "10001", "10001", "11111", "10001", "10001", "10001"],
['I'] = ["01110", "00100", "00100", "00100", "00100", "00100", "01110"],
['J'] = ["00001", "00001", "00001", "00001", "10001", "10001", "01110"],
['K'] = ["10001", "10010", "10100", "11000", "10100", "10010", "10001"],
['L'] = ["10000", "10000", "10000", "10000", "10000", "10000", "11111"],
['M'] = ["10001", "11011", "10101", "10001", "10001", "10001", "10001"],
['N'] = ["10001", "11001", "10101", "10011", "10001", "10001", "10001"],
['O'] = ["01110", "10001", "10001", "10001", "10001", "10001", "01110"],
['P'] = ["11110", "10001", "10001", "11110", "10000", "10000", "10000"],
['Q'] = ["01110", "10001", "10001", "10001", "10101", "10010", "01101"],
['R'] = ["11110", "10001", "10001", "11110", "10100", "10010", "10001"],
['S'] = ["01111", "10000", "10000", "01110", "00001", "00001", "11110"],
['T'] = ["11111", "00100", "00100", "00100", "00100", "00100", "00100"],
['U'] = ["10001", "10001", "10001", "10001", "10001", "10001", "01110"],
['V'] = ["10001", "10001", "10001", "10001", "10001", "01010", "00100"],
['W'] = ["10001", "10001", "10001", "10001", "10101", "11011", "10001"],
['X'] = ["10001", "10001", "01010", "00100", "01010", "10001", "10001"],
['Y'] = ["10001", "10001", "01010", "00100", "00100", "00100", "00100"],
['Z'] = ["11111", "00001", "00010", "00100", "01000", "10000", "11111"],
['0'] = ["01110", "10001", "10011", "10101", "11001", "10001", "01110"],
['1'] = ["00100", "01100", "00100", "00100", "00100", "00100", "01110"],
['2'] = ["01110", "10001", "00001", "00010", "00100", "01000", "11111"],
['3'] = ["11110", "00001", "00001", "01110", "00001", "00001", "11110"],
['4'] = ["00010", "00110", "01010", "10010", "11111", "00010", "00010"],
['5'] = ["11111", "10000", "10000", "11110", "00001", "00001", "11110"],
['6'] = ["01110", "10000", "10000", "11110", "10001", "10001", "01110"],
['7'] = ["11111", "00001", "00010", "00100", "01000", "01000", "01000"],
['8'] = ["01110", "10001", "10001", "01110", "10001", "10001", "01110"],
['9'] = ["01110", "10001", "10001", "01111", "00001", "00001", "01110"],
['#'] = ["01010", "11111", "01010", "01010", "11111", "01010", "00000"],
['.'] = ["00000", "00000", "00000", "00000", "00000", "00110", "00110"],
['-'] = ["00000", "00000", "00000", "01110", "00000", "00000", "00000"],
[':'] = ["00000", "00110", "00110", "00000", "00110", "00110", "00000"],
[' '] = ["00000", "00000", "00000", "00000", "00000", "00000", "00000"]
};
public void DrawText(SpriteBatch spriteBatch, Texture2D pixel, string text, int x, int y, int scale, Color color)
{
int cursorX = x;
for (int i = 0; i < text.Length; i++)
{
char c = char.ToUpperInvariant(text[i]);
if (!Glyphs.TryGetValue(c, out string[]? glyph))
{
glyph = Glyphs[' '];
}
DrawGlyph(spriteBatch, pixel, glyph, cursorX, y, scale, color);
cursorX += (6 * scale);
}
}
private static void DrawGlyph(SpriteBatch spriteBatch, Texture2D pixel, string[] glyph, int x, int y, int scale, Color color)
{
for (int row = 0; row < glyph.Length; row++)
{
string line = glyph[row];
for (int col = 0; col < line.Length; col++)
{
if (line[col] != '1')
{
continue;
}
spriteBatch.Draw(pixel, new Rectangle(x + (col * scale), y + (row * scale), scale, scale), color);
}
}
}
}