diff --git a/MLEM.Extended/Extensions/BitmapFontExtensions.cs b/MLEM.Extended/Extensions/BitmapFontExtensions.cs deleted file mode 100644 index 365c9be..0000000 --- a/MLEM.Extended/Extensions/BitmapFontExtensions.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework.Graphics; -using MLEM.Extensions; -using MonoGame.Extended.BitmapFonts; - -namespace MLEM.Extended.Extensions { - public static class BitmapFontExtensions { - - public static string SplitString(this BitmapFont font, string text, float width, float scale) { - return SpriteFontExtensions.SplitString(s => font.MeasureString(s).Width, text, width, scale); - } - - public static string TruncateString(this BitmapFont font, string text, float width, float scale, bool fromBack = false) { - return SpriteFontExtensions.TruncateString(s => font.MeasureString(s).Width, text, width, scale, fromBack); - } - - } -} \ No newline at end of file diff --git a/MLEM.Extended/Extensions/SpriteBatchExtensions.cs b/MLEM.Extended/Extensions/SpriteBatchExtensions.cs index 4d24346..f51a2a2 100644 --- a/MLEM.Extended/Extensions/SpriteBatchExtensions.cs +++ b/MLEM.Extended/Extensions/SpriteBatchExtensions.cs @@ -8,16 +8,6 @@ using MonoGame.Extended.BitmapFonts; namespace MLEM.Extended.Extensions { public static class SpriteBatchExtensions { - public static void DrawCenteredString(this SpriteBatch batch, BitmapFont font, string text, Vector2 position, float scale, Color color, bool horizontal = true, bool vertical = false, float addedScale = 0) { - var size = font.MeasureString(text); - var center = new Vector2( - horizontal ? size.Width * scale / 2F : 0, - vertical ? size.Height * scale / 2F : 0); - batch.DrawString(font, text, - position + (Vector2) size * scale / 2 - center, - color, 0, size / 2, scale + addedScale, SpriteEffects.None, 0); - } - public static void Draw(this SpriteBatch batch, Texture2D texture, RectangleF destinationRectangle, Rectangle? sourceRectangle, Color color, float rotation, Vector2 origin, SpriteEffects effects, float layerDepth) { batch.Draw(texture, destinationRectangle.ToMlem(), sourceRectangle, color, rotation, origin, effects, layerDepth); } @@ -30,6 +20,5 @@ namespace MLEM.Extended.Extensions { batch.Draw(texture, destinationRectangle, null, color); } - } } \ No newline at end of file diff --git a/MLEM.Extended/Font/GenericBitmapFont.cs b/MLEM.Extended/Font/GenericBitmapFont.cs index f4845e8..ef7119b 100644 --- a/MLEM.Extended/Font/GenericBitmapFont.cs +++ b/MLEM.Extended/Font/GenericBitmapFont.cs @@ -7,58 +7,46 @@ using MLEM.Font; using MonoGame.Extended.BitmapFonts; namespace MLEM.Extended.Font { - public class GenericBitmapFont : IGenericFont { + public class GenericBitmapFont : GenericFont { public readonly BitmapFont Font; - public float LineHeight => this.Font.LineHeight; + public override float LineHeight => this.Font.LineHeight; public GenericBitmapFont(BitmapFont font) { this.Font = font; } - public Vector2 MeasureString(string text) { + public override Vector2 MeasureString(string text) { return this.Font.MeasureString(text); } - public Vector2 MeasureString(StringBuilder text) { + public override Vector2 MeasureString(StringBuilder text) { return this.Font.MeasureString(text); } - public void DrawString(SpriteBatch batch, string text, Vector2 position, Color color) { + public override void DrawString(SpriteBatch batch, string text, Vector2 position, Color color) { batch.DrawString(this.Font, text, position, color); } - public void DrawString(SpriteBatch batch, string text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) { + public override void DrawString(SpriteBatch batch, string text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) { batch.DrawString(this.Font, text, position, color, rotation, origin, scale, effects, layerDepth); } - public void DrawString(SpriteBatch batch, string text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) { + public override void DrawString(SpriteBatch batch, string text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) { batch.DrawString(this.Font, text, position, color, rotation, origin, scale, effects, layerDepth); } - public void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color) { + public override void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color) { batch.DrawString(this.Font, text, position, color); } - public void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) { + public override void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) { batch.DrawString(this.Font, text, position, color, rotation, origin, scale, effects, layerDepth); } - public void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) { + public override void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) { batch.DrawString(this.Font, text, position, color, rotation, origin, scale, effects, layerDepth); } - public void DrawCenteredString(SpriteBatch batch, string text, Vector2 position, float scale, Color color, bool horizontal = true, bool vertical = false, float addedScale = 0) { - batch.DrawCenteredString(this.Font, text, position, scale, color, horizontal, vertical, addedScale); - } - - public string SplitString(string text, float width, float scale) { - return this.Font.SplitString(text, width, scale); - } - - public string TruncateString(string text, float width, float scale, bool fromBack = false) { - return this.Font.TruncateString(text, width, scale, fromBack); - } - } } \ No newline at end of file diff --git a/MLEM.Ui/Elements/Paragraph.cs b/MLEM.Ui/Elements/Paragraph.cs index 98ce958..73effca 100644 --- a/MLEM.Ui/Elements/Paragraph.cs +++ b/MLEM.Ui/Elements/Paragraph.cs @@ -17,9 +17,9 @@ namespace MLEM.Ui.Elements { private string text; private string splitText; public FormattingCodeCollection Formatting; - public StyleProp RegularFont; - public StyleProp BoldFont; - public StyleProp ItalicFont; + public StyleProp RegularFont; + public StyleProp BoldFont; + public StyleProp ItalicFont; public StyleProp FormatSettings; public StyleProp TextColor; diff --git a/MLEM.Ui/Elements/TextField.cs b/MLEM.Ui/Elements/TextField.cs index e72272b..2633fd0 100644 --- a/MLEM.Ui/Elements/TextField.cs +++ b/MLEM.Ui/Elements/TextField.cs @@ -26,7 +26,7 @@ namespace MLEM.Ui.Elements { public StyleProp HoveredTexture; public StyleProp HoveredColor; public StyleProp TextScale; - public StyleProp Font; + public StyleProp Font; private readonly StringBuilder text = new StringBuilder(); public string Text => this.text.ToString(); public string PlaceholderText; @@ -53,7 +53,7 @@ namespace MLEM.Ui.Elements { } } - public TextField(Anchor anchor, Vector2 size, Rule rule = null, IGenericFont font = null) : base(anchor, size) { + public TextField(Anchor anchor, Vector2 size, Rule rule = null, GenericFont font = null) : base(anchor, size) { this.InputRule = rule ?? DefaultRule; if (font != null) this.Font.Set(font); @@ -159,17 +159,17 @@ namespace MLEM.Ui.Elements { batch.Draw(tex, this.DisplayArea, color, this.Scale); if (this.displayedText != null) { - var textPos = this.DisplayArea.Location + new Vector2(this.TextOffsetX * this.Scale, this.DisplayArea.Height / 2); + var lineHeight = this.Font.Value.LineHeight * this.TextScale * this.Scale; + var textPos = this.DisplayArea.Location + new Vector2(this.TextOffsetX * this.Scale, this.DisplayArea.Height / 2 - lineHeight / 2); if (this.text.Length > 0 || this.IsSelected) { var textColor = this.TextColor.OrDefault(Color.White); - this.Font.Value.DrawCenteredString(batch, this.displayedText, textPos, this.TextScale * this.Scale, textColor * alpha, false, true); + this.Font.Value.DrawString(batch, this.displayedText, textPos, textColor * alpha, 0, Vector2.Zero, this.TextScale * this.Scale, SpriteEffects.None, 0); if (this.IsSelected && this.caretBlinkTimer >= 0.5F) { var textSize = this.Font.Value.MeasureString(this.displayedText.Substring(0, this.CaretPos - this.textOffset)) * this.TextScale * this.Scale; - var caretHeight = this.Font.Value.LineHeight * this.TextScale * this.Scale; - batch.Draw(batch.GetBlankTexture(), new RectangleF(textPos.X + textSize.X, textPos.Y - caretHeight / 2, this.CaretWidth * this.Scale, caretHeight), null, textColor * alpha); + batch.Draw(batch.GetBlankTexture(), new RectangleF(textPos.X + textSize.X, textPos.Y, this.CaretWidth * this.Scale, lineHeight), null, textColor * alpha); } } else if (this.PlaceholderText != null) { - this.Font.Value.DrawCenteredString(batch, this.PlaceholderText, textPos, this.TextScale * this.Scale, this.PlaceholderColor.OrDefault(Color.Gray) * alpha, false, true); + this.Font.Value.DrawString(batch, this.PlaceholderText, textPos, this.PlaceholderColor.OrDefault(Color.Gray) * alpha, 0, Vector2.Zero, this.TextScale * this.Scale, SpriteEffects.None, 0); } } base.Draw(time, batch, alpha, blendState, samplerState, matrix); diff --git a/MLEM.Ui/Style/UiStyle.cs b/MLEM.Ui/Style/UiStyle.cs index f261fff..cad992c 100644 --- a/MLEM.Ui/Style/UiStyle.cs +++ b/MLEM.Ui/Style/UiStyle.cs @@ -35,9 +35,9 @@ namespace MLEM.Ui.Style { public Vector2 ProgressBarProgressPadding; public NinePatch ProgressBarProgressTexture; public Color ProgressBarProgressColor; - public IGenericFont Font; - public IGenericFont BoldFont; - public IGenericFont ItalicFont; + public GenericFont Font; + public GenericFont BoldFont; + public GenericFont ItalicFont; public FormatSettings FormatSettings; public float TextScale = 1; public SoundEffect ActionSound; diff --git a/MLEM.Ui/Style/UntexturedStyle.cs b/MLEM.Ui/Style/UntexturedStyle.cs index 638b9c8..8651034 100644 --- a/MLEM.Ui/Style/UntexturedStyle.cs +++ b/MLEM.Ui/Style/UntexturedStyle.cs @@ -34,45 +34,34 @@ namespace MLEM.Ui.Style { this.Font = new EmptyFont(); } - private class EmptyFont : IGenericFont { + private class EmptyFont : GenericFont { - public float LineHeight => 1; + public override float LineHeight => 1; - public Vector2 MeasureString(string text) { + public override Vector2 MeasureString(string text) { return Vector2.One; } - public Vector2 MeasureString(StringBuilder text) { + public override Vector2 MeasureString(StringBuilder text) { return Vector2.One; } - public void DrawString(SpriteBatch batch, string text, Vector2 position, Color color) { + public override void DrawString(SpriteBatch batch, string text, Vector2 position, Color color) { } - public void DrawString(SpriteBatch batch, string text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) { + public override void DrawString(SpriteBatch batch, string text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) { } - public void DrawString(SpriteBatch batch, string text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) { + public override void DrawString(SpriteBatch batch, string text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) { } - public void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color) { + public override void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color) { } - public void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) { + public override void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) { } - public void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) { - } - - public void DrawCenteredString(SpriteBatch batch, string text, Vector2 position, float scale, Color color, bool horizontal = true, bool vertical = false, float addedScale = 0) { - } - - public string SplitString(string text, float width, float scale) { - return text; - } - - public string TruncateString(string text, float width, float scale, bool fromBack = false) { - return text; + public override void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) { } } diff --git a/MLEM/Extensions/SpriteBatchExtensions.cs b/MLEM/Extensions/SpriteBatchExtensions.cs index 6b45443..9c79969 100644 --- a/MLEM/Extensions/SpriteBatchExtensions.cs +++ b/MLEM/Extensions/SpriteBatchExtensions.cs @@ -39,16 +39,6 @@ namespace MLEM.Extensions { return new NinePatch(tex, 1); } - public static void DrawCenteredString(this SpriteBatch batch, SpriteFont font, string text, Vector2 position, float scale, Color color, bool horizontal = true, bool vertical = false, float addedScale = 0) { - var size = font.MeasureString(text); - var center = new Vector2( - horizontal ? size.X * scale / 2F : 0, - vertical ? size.Y * scale / 2F : 0); - batch.DrawString(font, text, - position + size * scale / 2 - center, - color, 0, size / 2, scale + addedScale, SpriteEffects.None, 0); - } - public static void Draw(this SpriteBatch batch, Texture2D texture, RectangleF destinationRectangle, Rectangle? sourceRectangle, Color color, float rotation, Vector2 origin, SpriteEffects effects, float layerDepth) { var source = sourceRectangle ?? new Rectangle(0, 0, texture.Width, texture.Height); var scale = new Vector2(1F / source.Width, 1F / source.Height) * destinationRectangle.Size; diff --git a/MLEM/Extensions/SpriteFontExtensions.cs b/MLEM/Font/GenericFont.cs similarity index 52% rename from MLEM/Extensions/SpriteFontExtensions.cs rename to MLEM/Font/GenericFont.cs index b7f9f5d..1799a80 100644 --- a/MLEM/Extensions/SpriteFontExtensions.cs +++ b/MLEM/Font/GenericFont.cs @@ -1,21 +1,30 @@ -using System; using System.Collections.Generic; using System.Text; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -using MLEM.Font; -namespace MLEM.Extensions { - public static class SpriteFontExtensions { +namespace MLEM.Font { + public abstract class GenericFont { - public static string SplitString(this SpriteFont font, string text, float width, float scale) { - return SplitString(s => font.MeasureString(s).X, text, width, scale); - } + public abstract float LineHeight { get; } - public static string TruncateString(this SpriteFont font, string text, float width, float scale, bool fromBack = false) { - return TruncateString(s => font.MeasureString(s).X, text, width, scale, fromBack); - } + public abstract Vector2 MeasureString(string text); - public static string TruncateString(Func widthFunc, string text, float width, float scale, bool fromBack = false) { + public abstract Vector2 MeasureString(StringBuilder text); + + public abstract void DrawString(SpriteBatch batch, string text, Vector2 position, Color color); + + public abstract void DrawString(SpriteBatch batch, string text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth); + + public abstract void DrawString(SpriteBatch batch, string text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth); + + public abstract void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color); + + public abstract void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth); + + public abstract void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth); + + public string TruncateString(string text, float width, float scale, bool fromBack = false) { var total = new StringBuilder(); for (var i = 0; i < text.Length; i++) { if (fromBack) { @@ -24,18 +33,18 @@ namespace MLEM.Extensions { total.Append(text[i]); } - if (widthFunc(total) * scale >= width) + if (this.MeasureString(total).X * scale >= width) return total.ToString(fromBack ? 1 : 0, total.Length - 1); } return total.ToString(); } - public static string SplitString(Func widthFunc, string text, float width, float scale) { + public string SplitString(string text, float width, float scale) { var total = new StringBuilder(); foreach (var line in text.Split('\n')) { var curr = new StringBuilder(); foreach (var word in line.Split(' ')) { - if (widthFunc(word) * scale >= width) { + if (this.MeasureString(word).X * scale >= width) { if (curr.Length > 0) { total.Append(curr).Append('\n'); curr.Clear(); @@ -43,7 +52,7 @@ namespace MLEM.Extensions { var wordBuilder = new StringBuilder(); for (var i = 0; i < word.Length; i++) { wordBuilder.Append(word[i]); - if (widthFunc(wordBuilder.ToString()) * scale >= width) { + if (this.MeasureString(wordBuilder.ToString()).X * scale >= width) { total.Append(wordBuilder.ToString(0, wordBuilder.Length - 1)).Append('\n'); wordBuilder.Remove(0, wordBuilder.Length - 1); } @@ -51,7 +60,7 @@ namespace MLEM.Extensions { curr.Append(wordBuilder).Append(' '); } else { curr.Append(word).Append(' '); - if (widthFunc(curr.ToString()) * scale >= width) { + if (this.MeasureString(curr.ToString()).X * scale >= width) { var len = curr.Length - word.Length - 1; if (len > 0) { total.Append(curr.ToString(0, len)).Append('\n'); @@ -65,9 +74,9 @@ namespace MLEM.Extensions { return total.ToString(0, total.Length - 2); } - public static string GetWidthString(IGenericFont font, float width, char content = ' ') { + public string GetWidthString(float width, char content = ' ') { var strg = content.ToString(); - while (font.MeasureString(strg).X < width) + while (this.MeasureString(strg).X < width) strg += content; return strg; } diff --git a/MLEM/Font/GenericSpriteFont.cs b/MLEM/Font/GenericSpriteFont.cs index ebf0e77..862eba9 100644 --- a/MLEM/Font/GenericSpriteFont.cs +++ b/MLEM/Font/GenericSpriteFont.cs @@ -5,58 +5,46 @@ using Microsoft.Xna.Framework.Graphics; using MLEM.Extensions; namespace MLEM.Font { - public class GenericSpriteFont : IGenericFont { + public class GenericSpriteFont : GenericFont { public readonly SpriteFont Font; - public float LineHeight => this.Font.LineSpacing; + public override float LineHeight => this.Font.LineSpacing; public GenericSpriteFont(SpriteFont font) { this.Font = font; } - public Vector2 MeasureString(string text) { + public override Vector2 MeasureString(string text) { return this.Font.MeasureString(text); } - public Vector2 MeasureString(StringBuilder text) { + public override Vector2 MeasureString(StringBuilder text) { return this.Font.MeasureString(text); } - public void DrawString(SpriteBatch batch, string text, Vector2 position, Color color) { + public override void DrawString(SpriteBatch batch, string text, Vector2 position, Color color) { batch.DrawString(this.Font, text, position, color); } - public void DrawString(SpriteBatch batch, string text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) { + public override void DrawString(SpriteBatch batch, string text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) { batch.DrawString(this.Font, text, position, color, rotation, origin, scale, effects, layerDepth); } - public void DrawString(SpriteBatch batch, string text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) { + public override void DrawString(SpriteBatch batch, string text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) { batch.DrawString(this.Font, text, position, color, rotation, origin, scale, effects, layerDepth); } - public void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color) { + public override void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color) { batch.DrawString(this.Font, text, position, color); } - public void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) { + public override void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) { batch.DrawString(this.Font, text, position, color, rotation, origin, scale, effects, layerDepth); } - public void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) { + public override void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) { batch.DrawString(this.Font, text, position, color, rotation, origin, scale, effects, layerDepth); } - public void DrawCenteredString(SpriteBatch batch, string text, Vector2 position, float scale, Color color, bool horizontal = true, bool vertical = false, float addedScale = 0) { - batch.DrawCenteredString(this.Font, text, position, scale, color, horizontal, vertical, addedScale); - } - - public string SplitString(string text, float width, float scale) { - return this.Font.SplitString(text, width, scale); - } - - public string TruncateString(string text, float width, float scale, bool fromBack = false) { - return this.Font.TruncateString(text, width, scale, fromBack); - } - } } \ No newline at end of file diff --git a/MLEM/Font/IGenericFont.cs b/MLEM/Font/IGenericFont.cs deleted file mode 100644 index 0ce0de2..0000000 --- a/MLEM/Font/IGenericFont.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System.Collections.Generic; -using System.Text; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; - -namespace MLEM.Font { - public interface IGenericFont { - - float LineHeight { get; } - - Vector2 MeasureString(string text); - - Vector2 MeasureString(StringBuilder text); - - void DrawString(SpriteBatch batch, string text, Vector2 position, Color color); - - void DrawString(SpriteBatch batch, string text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth); - - void DrawString(SpriteBatch batch, string text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth); - - void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color); - - void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth); - - void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth); - - void DrawCenteredString(SpriteBatch batch, string text, Vector2 position, float scale, Color color, bool horizontal = true, bool vertical = false, float addedScale = 0); - - string SplitString(string text, float width, float scale); - - string TruncateString(string text, float width, float scale, bool fromBack = false); - - } -} \ No newline at end of file diff --git a/MLEM/Formatting/FormattingCode.cs b/MLEM/Formatting/FormattingCode.cs index 1485d86..4e0290c 100644 --- a/MLEM/Formatting/FormattingCode.cs +++ b/MLEM/Formatting/FormattingCode.cs @@ -37,8 +37,8 @@ namespace MLEM.Formatting { this.CodeType = Type.Animation; } - public virtual string GetReplacementString(IGenericFont font) { - return this.CodeType == Type.Icon ? SpriteFontExtensions.GetWidthString(font, font.LineHeight) : string.Empty; + public virtual string GetReplacementString(GenericFont font) { + return this.CodeType == Type.Icon ? font.GetWidthString(font.LineHeight) : string.Empty; } public enum Type { diff --git a/MLEM/Formatting/TextAnimation.cs b/MLEM/Formatting/TextAnimation.cs index b1a7622..869d9f3 100644 --- a/MLEM/Formatting/TextAnimation.cs +++ b/MLEM/Formatting/TextAnimation.cs @@ -20,7 +20,7 @@ namespace MLEM.Formatting { font.DrawString(batch, charSt, position, color, 0, Vector2.Zero, scale, SpriteEffects.None, layerDepth); }; - public delegate void DrawCharacter(FormatSettings settings, IGenericFont font, SpriteBatch batch, string totalText, int index, int effectStartIndex, string charSt, Vector2 position, Color color, float scale, float layerDepth, TimeSpan timeIntoAnimation); + public delegate void DrawCharacter(FormatSettings settings, GenericFont font, SpriteBatch batch, string totalText, int index, int effectStartIndex, string charSt, Vector2 position, Color color, float scale, float layerDepth, TimeSpan timeIntoAnimation); } } \ No newline at end of file diff --git a/MLEM/Formatting/TextFormatting.cs b/MLEM/Formatting/TextFormatting.cs index a9455fe..af1080a 100644 --- a/MLEM/Formatting/TextFormatting.cs +++ b/MLEM/Formatting/TextFormatting.cs @@ -44,14 +44,14 @@ namespace MLEM.Formatting { formatRegex = new Regex($"{op}[^{op}{cl}]*{cl}"); } - public static string RemoveFormatting(this string s, IGenericFont font) { + public static string RemoveFormatting(this string s, GenericFont font) { return formatRegex.Replace(s, match => { var code = FromMatch(match); return code != null ? code.GetReplacementString(font) : match.Value; }); } - public static FormattingCodeCollection GetFormattingCodes(this string s, IGenericFont font) { + public static FormattingCodeCollection GetFormattingCodes(this string s, GenericFont font) { var codes = new FormattingCodeCollection(); var codeLengths = 0; foreach (Match match in formatRegex.Matches(s)) { @@ -70,7 +70,7 @@ namespace MLEM.Formatting { return codes; } - public static void DrawFormattedString(this IGenericFont regularFont, SpriteBatch batch, Vector2 pos, string unformattedText, FormattingCodeCollection formatting, Color color, float scale, IGenericFont boldFont = null, IGenericFont italicFont = null, float depth = 0, TimeSpan timeIntoAnimation = default, FormatSettings formatSettings = null) { + public static void DrawFormattedString(this GenericFont regularFont, SpriteBatch batch, Vector2 pos, string unformattedText, FormattingCodeCollection formatting, Color color, float scale, GenericFont boldFont = null, GenericFont italicFont = null, float depth = 0, TimeSpan timeIntoAnimation = default, FormatSettings formatSettings = null) { var settings = formatSettings ?? FormatSettings.Default; var currColor = color; var currFont = regularFont;