1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-05-29 11:33:37 +02:00
MLEM/MLEM/Formatting/Codes/LinkCode.cs

45 lines
1.7 KiB
C#
Raw Normal View History

2020-05-15 22:15:24 +02:00
using System;
using System.Text.RegularExpressions;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MLEM.Font;
namespace MLEM.Formatting.Codes {
/// <inheritdoc />
2020-05-15 22:15:24 +02:00
public class LinkCode : UnderlineCode {
private readonly Func<Token, bool> isSelected;
private readonly Color? color;
2020-05-15 22:15:24 +02:00
/// <inheritdoc />
public LinkCode(Match match, Regex regex, float thickness, float yOffset, Func<Token, bool> isSelected, Color? color = null) : base(match, regex, thickness, yOffset) {
2020-05-15 22:15:24 +02:00
this.isSelected = isSelected;
this.color = color;
2020-05-15 22:15:24 +02:00
}
/// <summary>
/// Returns true if this link formatting code is currently selected or hovered over, based on the selection function.
/// </summary>
/// <returns>True if this code is currently selected</returns>
public virtual bool IsSelected() {
foreach (var token in this.Tokens) {
if (this.isSelected(token))
return true;
}
return false;
2020-05-15 22:15:24 +02:00
}
/// <inheritdoc />
public override Color? GetColor(Color defaultPick) {
return this.color;
}
/// <inheritdoc />
public override bool DrawCharacter(GameTime time, SpriteBatch batch, char c, string cString, Token token, int indexInToken, ref Vector2 pos, GenericFont font, ref Color color, ref float scale, float depth) {
2020-05-15 22:15:24 +02:00
// since we inherit from UnderlineCode, we can just call base if selected
return this.IsSelected() && base.DrawCharacter(time, batch, c, cString, token, indexInToken, ref pos, font, ref color, ref scale, depth);
2020-05-15 22:15:24 +02:00
}
}
2022-06-17 18:23:47 +02:00
}