2019-08-09 14:26:20 +02:00
|
|
|
using System.Text;
|
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
|
|
|
|
namespace MLEM.Font {
|
2020-05-20 23:59:40 +02:00
|
|
|
/// <inheritdoc/>
|
2020-03-28 22:25:06 +01:00
|
|
|
public class GenericSpriteFont : GenericFont {
|
2019-08-09 14:26:20 +02:00
|
|
|
|
2020-05-21 12:53:42 +02:00
|
|
|
/// <summary>
|
|
|
|
/// The <see cref="SpriteFont"/> that is being wrapped by this generic font
|
|
|
|
/// </summary>
|
2019-08-09 14:26:20 +02:00
|
|
|
public readonly SpriteFont Font;
|
2020-05-20 23:59:40 +02:00
|
|
|
/// <inheritdoc/>
|
2020-05-17 00:10:29 +02:00
|
|
|
public override GenericFont Bold { get; }
|
2020-05-20 23:59:40 +02:00
|
|
|
/// <inheritdoc/>
|
2020-05-17 00:10:29 +02:00
|
|
|
public override GenericFont Italic { get; }
|
2020-05-20 23:59:40 +02:00
|
|
|
/// <inheritdoc/>
|
2020-03-28 22:25:06 +01:00
|
|
|
public override float LineHeight => this.Font.LineSpacing;
|
2019-08-09 14:26:20 +02:00
|
|
|
|
2020-05-20 23:59:40 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Creates a new generic font using <see cref="SpriteFont"/>.
|
|
|
|
/// Optionally, a bold and italic version of the font can be supplied.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="font">The font to wrap</param>
|
|
|
|
/// <param name="bold">A bold version of the font</param>
|
|
|
|
/// <param name="italic">An italic version of the font</param>
|
2020-05-17 00:10:29 +02:00
|
|
|
public GenericSpriteFont(SpriteFont font, SpriteFont bold = null, SpriteFont italic = null) {
|
2019-08-09 14:26:20 +02:00
|
|
|
this.Font = font;
|
2020-05-17 00:10:29 +02:00
|
|
|
this.Bold = bold != null ? new GenericSpriteFont(bold) : this;
|
|
|
|
this.Italic = italic != null ? new GenericSpriteFont(italic) : this;
|
2019-08-09 14:26:20 +02:00
|
|
|
}
|
|
|
|
|
2020-05-20 23:59:40 +02:00
|
|
|
/// <inheritdoc/>
|
2020-03-28 22:25:06 +01:00
|
|
|
public override Vector2 MeasureString(string text) {
|
2019-08-09 14:26:20 +02:00
|
|
|
return this.Font.MeasureString(text);
|
|
|
|
}
|
|
|
|
|
2020-05-20 23:59:40 +02:00
|
|
|
/// <inheritdoc/>
|
2020-03-28 22:25:06 +01:00
|
|
|
public override Vector2 MeasureString(StringBuilder text) {
|
2019-08-09 14:26:20 +02:00
|
|
|
return this.Font.MeasureString(text);
|
|
|
|
}
|
|
|
|
|
2020-05-20 23:59:40 +02:00
|
|
|
/// <inheritdoc/>
|
2020-03-28 22:25:06 +01:00
|
|
|
public override void DrawString(SpriteBatch batch, string text, Vector2 position, Color color) {
|
2019-08-09 14:26:20 +02:00
|
|
|
batch.DrawString(this.Font, text, position, color);
|
|
|
|
}
|
|
|
|
|
2020-05-20 23:59:40 +02:00
|
|
|
/// <inheritdoc/>
|
2020-03-28 22:25:06 +01:00
|
|
|
public override void DrawString(SpriteBatch batch, string text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) {
|
2019-08-09 14:26:20 +02:00
|
|
|
batch.DrawString(this.Font, text, position, color, rotation, origin, scale, effects, layerDepth);
|
|
|
|
}
|
|
|
|
|
2020-05-20 23:59:40 +02:00
|
|
|
/// <inheritdoc/>
|
2020-03-28 22:25:06 +01:00
|
|
|
public override void DrawString(SpriteBatch batch, string text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) {
|
2019-08-09 14:26:20 +02:00
|
|
|
batch.DrawString(this.Font, text, position, color, rotation, origin, scale, effects, layerDepth);
|
|
|
|
}
|
|
|
|
|
2020-05-20 23:59:40 +02:00
|
|
|
/// <inheritdoc/>
|
2020-03-28 22:25:06 +01:00
|
|
|
public override void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color) {
|
2019-08-09 14:26:20 +02:00
|
|
|
batch.DrawString(this.Font, text, position, color);
|
|
|
|
}
|
|
|
|
|
2020-05-20 23:59:40 +02:00
|
|
|
/// <inheritdoc/>
|
2020-03-28 22:25:06 +01:00
|
|
|
public override void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) {
|
2019-08-09 14:26:20 +02:00
|
|
|
batch.DrawString(this.Font, text, position, color, rotation, origin, scale, effects, layerDepth);
|
|
|
|
}
|
|
|
|
|
2020-05-20 23:59:40 +02:00
|
|
|
/// <inheritdoc/>
|
2020-03-28 22:25:06 +01:00
|
|
|
public override void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) {
|
2019-08-09 14:26:20 +02:00
|
|
|
batch.DrawString(this.Font, text, position, color, rotation, origin, scale, effects, layerDepth);
|
|
|
|
}
|
|
|
|
|
2020-06-04 22:18:53 +02:00
|
|
|
/// <inheritdoc />
|
|
|
|
public override bool HasCharacter(char c) {
|
|
|
|
return this.Font.Characters.Contains(c);
|
|
|
|
}
|
|
|
|
|
2019-08-09 14:26:20 +02:00
|
|
|
}
|
|
|
|
}
|