mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-14 18:19:09 +01:00
74 lines
No EOL
3.4 KiB
C#
74 lines
No EOL
3.4 KiB
C#
using System.Text;
|
|
using FontStashSharp;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using MLEM.Extensions;
|
|
using MLEM.Font;
|
|
|
|
namespace MLEM.Extended.Font {
|
|
/// <inheritdoc/>
|
|
public class GenericStashFont : GenericFont {
|
|
|
|
/// <summary>
|
|
/// The <see cref="SpriteFontBase"/> that is being wrapped by this generic font
|
|
/// </summary>
|
|
public readonly SpriteFontBase Font;
|
|
/// <inheritdoc />
|
|
public override GenericFont Bold { get; }
|
|
/// <inheritdoc />
|
|
public override GenericFont Italic { get; }
|
|
/// <inheritdoc />
|
|
public override float LineHeight { get; }
|
|
|
|
/// <summary>
|
|
/// Creates a new generic font using <see cref="SpriteFontBase"/>.
|
|
/// 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>
|
|
public GenericStashFont(SpriteFontBase font, SpriteFontBase bold = null, SpriteFontBase italic = null) {
|
|
this.Font = font;
|
|
// SpriteFontBase provides no line height, so we measure the height of a new line
|
|
this.LineHeight = font.MeasureString("\n").Y;
|
|
this.Bold = bold != null ? new GenericStashFont(bold) : this;
|
|
this.Italic = italic != null ? new GenericStashFont(italic) : this;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override void DrawString(SpriteBatch batch, string text, Vector2 position, Color color) {
|
|
this.Font.DrawText(batch, text, position, color);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override void DrawString(SpriteBatch batch, string text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) {
|
|
this.Font.DrawText(batch, text, position, color, new Vector2(scale), rotation, origin, layerDepth);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override void DrawString(SpriteBatch batch, string text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) {
|
|
this.Font.DrawText(batch, text, position, color, scale, rotation, origin, layerDepth);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color) {
|
|
this.Font.DrawText(batch, text, position, color);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) {
|
|
this.Font.DrawText(batch, text, position, color, new Vector2(scale), rotation, origin, layerDepth);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) {
|
|
this.Font.DrawText(batch, text, position, color, scale, rotation, origin, layerDepth);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override Vector2 MeasureChar(char c) {
|
|
return this.Font.MeasureString(c.ToCachedString());
|
|
}
|
|
|
|
}
|
|
} |