1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-07-02 08:56:35 +02:00
MLEM/MLEM/Formatting/Codes/UnderlineCode.cs

33 lines
1.3 KiB
C#
Raw Normal View History

2020-05-15 21:31:37 +02:00
using System.Text.RegularExpressions;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MLEM.Extensions;
using MLEM.Font;
using MLEM.Misc;
namespace MLEM.Formatting.Codes {
/// <inheritdoc />
2020-05-15 21:31:37 +02:00
public class UnderlineCode : FontCode {
private readonly float thickness;
private readonly float yOffset;
/// <inheritdoc />
2020-05-15 21:31:37 +02:00
public UnderlineCode(Match match, Regex regex, float thickness, float yOffset) : base(match, regex, null) {
this.thickness = thickness;
this.yOffset = yOffset;
}
/// <inheritdoc />
2020-05-15 21:31:37 +02:00
public override bool DrawCharacter(GameTime time, SpriteBatch batch, char c, string cString, int indexInToken, ref Vector2 pos, GenericFont font, ref Color color, ref float scale, float depth) {
// don't underline spaces at the end of lines
if (c == ' ' && this.Token.DisplayString.Length > indexInToken + 1 && this.Token.DisplayString[indexInToken + 1] == '\n')
2020-05-15 21:31:37 +02:00
return false;
2020-05-15 22:15:24 +02:00
var size = font.MeasureString(cString) * scale;
var thicc = size.Y * this.thickness;
batch.Draw(batch.GetBlankTexture(), new RectangleF(pos.X, pos.Y + this.yOffset * size.Y - thicc, size.X, thicc), color);
2020-05-15 21:31:37 +02:00
return false;
}
}
}