1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-05 06:49:09 +01:00
MLEM/MLEM.Extended/Font/GenericBitmapFont.cs

47 lines
1.9 KiB
C#
Raw Normal View History

2019-08-09 14:26:20 +02:00
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MLEM.Font;
using MonoGame.Extended.BitmapFonts;
namespace MLEM.Extended.Font {
/// <inheritdoc/>
2020-03-28 22:25:06 +01:00
public class GenericBitmapFont : GenericFont {
2019-08-09 14:26:20 +02:00
/// <summary>
/// The <see cref="BitmapFont"/> that is being wrapped by this generic font
/// </summary>
2019-08-09 14:26:20 +02:00
public readonly BitmapFont Font;
/// <inheritdoc/>
public override GenericFont Bold { get; }
/// <inheritdoc/>
public override GenericFont Italic { get; }
/// <inheritdoc/>
2020-03-28 22:25:06 +01:00
public override float LineHeight => this.Font.LineHeight;
2019-08-09 14:26:20 +02:00
/// <summary>
/// Creates a new generic font using <see cref="BitmapFont"/>.
/// 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 GenericBitmapFont(BitmapFont font, BitmapFont bold = null, BitmapFont italic = null) {
2019-08-09 14:26:20 +02:00
this.Font = font;
this.Bold = bold != null ? new GenericBitmapFont(bold) : this;
this.Italic = italic != null ? new GenericBitmapFont(italic) : this;
2019-08-09 14:26:20 +02:00
}
/// <inheritdoc />
protected override float MeasureCharacter(int codePoint) {
var region = this.Font.GetCharacterRegion(codePoint);
return region != null ? new Vector2(region.XAdvance, region.Height).X : 0;
2019-08-09 14:26:20 +02:00
}
2021-12-22 12:46:17 +01:00
/// <inheritdoc />
protected override void DrawCharacter(SpriteBatch batch, int codePoint, string character, Vector2 position, Color color, float rotation, Vector2 scale, SpriteEffects effects, float layerDepth) {
batch.DrawString(this.Font, character, position, color, rotation, Vector2.Zero, scale, effects, layerDepth);
2019-08-09 14:26:20 +02:00
}
}
2022-06-17 18:23:47 +02:00
}