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 {
|
2020-05-22 20:32:38 +02:00
|
|
|
/// <inheritdoc/>
|
2020-03-28 22:25:06 +01:00
|
|
|
public class GenericBitmapFont : GenericFont {
|
2019-08-09 14:26:20 +02:00
|
|
|
|
2020-05-22 20:32:38 +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;
|
2020-05-22 20:32:38 +02:00
|
|
|
/// <inheritdoc/>
|
2020-05-17 00:10:29 +02:00
|
|
|
public override GenericFont Bold { get; }
|
2020-05-22 20:32:38 +02:00
|
|
|
/// <inheritdoc/>
|
2020-05-17 00:10:29 +02:00
|
|
|
public override GenericFont Italic { get; }
|
2020-05-22 20:32:38 +02:00
|
|
|
/// <inheritdoc/>
|
2020-03-28 22:25:06 +01:00
|
|
|
public override float LineHeight => this.Font.LineHeight;
|
2019-08-09 14:26:20 +02:00
|
|
|
|
2020-05-22 20:32:38 +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>
|
2020-05-17 00:10:29 +02:00
|
|
|
public GenericBitmapFont(BitmapFont font, BitmapFont bold = null, BitmapFont 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 GenericBitmapFont(bold) : this;
|
|
|
|
this.Italic = italic != null ? new GenericBitmapFont(italic) : this;
|
2019-08-09 14:26:20 +02:00
|
|
|
}
|
|
|
|
|
2020-06-20 01:18:27 +02:00
|
|
|
/// <inheritdoc />
|
2022-10-15 13:48:45 +02:00
|
|
|
protected override float MeasureCharacter(int codePoint) {
|
|
|
|
var region = this.Font.GetCharacterRegion(codePoint);
|
2021-07-28 17:22:47 +02:00
|
|
|
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 />
|
2024-04-10 20:27:00 +02:00
|
|
|
public override void DrawCharacter(SpriteBatch batch, int codePoint, string character, Vector2 position, Color color, float rotation, Vector2 scale, SpriteEffects effects, float layerDepth) {
|
2022-10-15 13:48:45 +02:00
|
|
|
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
|
|
|
}
|