mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-09-28 17:11:06 +02:00
38 lines
No EOL
1.4 KiB
C#
38 lines
No EOL
1.4 KiB
C#
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 />
|
|
public class UnderlineCode : Code {
|
|
|
|
private readonly float thickness;
|
|
private readonly float yOffset;
|
|
|
|
/// <inheritdoc />
|
|
public UnderlineCode(Match match, Regex regex, float thickness, float yOffset) : base(match, regex) {
|
|
this.thickness = thickness;
|
|
this.yOffset = yOffset;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
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')
|
|
return false;
|
|
var (w, h) = font.MeasureString(cString) * scale;
|
|
var t = h * this.thickness;
|
|
batch.Draw(batch.GetBlankTexture(), new RectangleF(pos.X, pos.Y + this.yOffset * h - t, w, t), color);
|
|
return false;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override bool EndsHere(Code other) {
|
|
return other is UnderlineCode || other is ResetFormattingCode;
|
|
}
|
|
|
|
}
|
|
} |