diff --git a/MLEM.Extended/Font/GenericStashFont.cs b/MLEM.Extended/Font/GenericStashFont.cs
new file mode 100644
index 0000000..aa52ee3
--- /dev/null
+++ b/MLEM.Extended/Font/GenericStashFont.cs
@@ -0,0 +1,74 @@
+using System.Text;
+using FontStashSharp;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+using MLEM.Extensions;
+using MLEM.Font;
+
+namespace MLEM.Extended.Font {
+ ///
+ public class GenericStashFont : GenericFont {
+
+ ///
+ /// The that is being wrapped by this generic font
+ ///
+ public readonly SpriteFontBase Font;
+ ///
+ public override GenericFont Bold { get; }
+ ///
+ public override GenericFont Italic { get; }
+ ///
+ public override float LineHeight { get; }
+
+ ///
+ /// Creates a new generic font using .
+ /// Optionally, a bold and italic version of the font can be supplied.
+ ///
+ /// The font to wrap
+ /// A bold version of the font
+ /// An italic version of the font
+ 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;
+ }
+
+ ///
+ public override void DrawString(SpriteBatch batch, string text, Vector2 position, Color color) {
+ this.Font.DrawText(batch, text, position, color);
+ }
+
+ ///
+ 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);
+ }
+
+ ///
+ 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);
+ }
+
+ ///
+ public override void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color) {
+ this.Font.DrawText(batch, text, position, color);
+ }
+
+ ///
+ 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);
+ }
+
+ ///
+ 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);
+ }
+
+ ///
+ protected override Vector2 MeasureChar(char c) {
+ return this.Font.MeasureString(c.ToCachedString());
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/MLEM.Extended/MLEM.Extended.csproj b/MLEM.Extended/MLEM.Extended.csproj
index 0283c23..b795e50 100644
--- a/MLEM.Extended/MLEM.Extended.csproj
+++ b/MLEM.Extended/MLEM.Extended.csproj
@@ -6,7 +6,7 @@
Ellpeck
- MLEM Library for Extending MonoGame extension that ties in with MonoGame.Extended
+ MLEM Library for Extending MonoGame extension that ties in with MonoGame.Extended and other MonoGame libraries
monogame ellpeck mlem utility extensions monogame.extended extended
https://mlem.ellpeck.de/
https://github.com/Ellpeck/MLEM
@@ -21,6 +21,9 @@
all
+
+ all
+
all
diff --git a/Sandbox/Content/Content.mgcb b/Sandbox/Content/Content.mgcb
index 7749651..afa7c9c 100644
--- a/Sandbox/Content/Content.mgcb
+++ b/Sandbox/Content/Content.mgcb
@@ -14,6 +14,9 @@
#---------------------------------- Content ---------------------------------#
+#begin Fonts/Cadman_Roman.otf
+/copy:Fonts/Cadman_Roman.otf
+
#begin Fonts/Regular.fnt
/importer:BitmapFontImporter
/processor:BitmapFontProcessor
diff --git a/Sandbox/Content/Fonts/Cadman_Roman.otf b/Sandbox/Content/Fonts/Cadman_Roman.otf
new file mode 100644
index 0000000..9cbadd6
Binary files /dev/null and b/Sandbox/Content/Fonts/Cadman_Roman.otf differ
diff --git a/Sandbox/GameImpl.cs b/Sandbox/GameImpl.cs
index ef2dbcb..42032db 100644
--- a/Sandbox/GameImpl.cs
+++ b/Sandbox/GameImpl.cs
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Text.RegularExpressions;
+using FontStashSharp;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
@@ -10,6 +11,7 @@ using MLEM.Data.Content;
using MLEM.Extended.Font;
using MLEM.Extended.Tiled;
using MLEM.Extensions;
+using MLEM.Font;
using MLEM.Formatting;
using MLEM.Formatting.Codes;
using MLEM.Input;
@@ -68,8 +70,11 @@ namespace Sandbox {
textureData[textureData.FromIndex(textureData.ToIndex(25, 9))] = Color.Yellow;
}
+ var system = new FontSystem(this.GraphicsDevice, 1024, 1024);
+ system.AddFont(File.ReadAllBytes("Content/Fonts/Cadman_Roman.otf"));
//var font = new GenericSpriteFont(LoadContent("Fonts/TestFont"));
- var font = new GenericBitmapFont(LoadContent("Fonts/Regular"));
+ //var font = new GenericBitmapFont(LoadContent("Fonts/Regular"));
+ var font = new GenericStashFont(system.GetFont(32));
this.UiSystem.Style = new UntexturedStyle(this.SpriteBatch) {
Font = font,
TextScale = 0.1F,
@@ -124,8 +129,9 @@ namespace Sandbox {
var res = this.Content.LoadJson("Test");
Console.WriteLine("The res is " + res);
- /*this.OnDraw += (game, time) => {
+ this.OnDraw += (game, time) => {
this.SpriteBatch.Begin();
+ system.GetFont(32).DrawText(this.SpriteBatch, "Left Aligned\nover multiple lines", new Vector2(640, 0), Color.White);
font.DrawString(this.SpriteBatch, "Left Aligned\nover multiple lines", new Vector2(640, 0), TextAlign.Left, Color.White);
font.DrawString(this.SpriteBatch, "Center Aligned\nover multiple lines", new Vector2(640, 100), TextAlign.Center, Color.White);
font.DrawString(this.SpriteBatch, "Right Aligned\nover multiple lines", new Vector2(640, 200), TextAlign.Right, Color.White);
@@ -138,7 +144,7 @@ namespace Sandbox {
font.DrawString(this.SpriteBatch, font.TruncateString("This is a very long string", 200, 1, true), new Vector2(200, 500), Color.White);
font.DrawString(this.SpriteBatch, font.TruncateString("This is a very long string", 200, 1, true, "..."), new Vector2(200, 550), Color.White);
this.SpriteBatch.End();
- };*/
+ };
var sc = 4;
var formatter = new TextFormatter();
diff --git a/Sandbox/Sandbox.csproj b/Sandbox/Sandbox.csproj
index 1e8b101..247a876 100644
--- a/Sandbox/Sandbox.csproj
+++ b/Sandbox/Sandbox.csproj
@@ -18,6 +18,7 @@
+