From 582e6fe370f46de39952571b10a036465aea8fff Mon Sep 17 00:00:00 2001 From: Brett Story Date: Mon, 30 Jan 2023 16:02:40 -0600 Subject: [PATCH] Kerning added to TextLine --- Framework/Rendering/TextLine.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Framework/Rendering/TextLine.cs b/Framework/Rendering/TextLine.cs index c8a8307b..c74cac45 100644 --- a/Framework/Rendering/TextLine.cs +++ b/Framework/Rendering/TextLine.cs @@ -18,6 +18,7 @@ public class TextLine : RenderableEntity { private float _characterWidth; private Color _color = Color.White; private string _text = string.Empty; + private int _kerning; /// /// Initializes a new instance of the class. @@ -45,6 +46,20 @@ public Color Color { set => this.Set(ref this._color, value); } + /// + /// Gets or sets the kerning. This is the space between letters in pixels. Positive numbers will increase the space, negative numbers will decrease it. + /// + [DataMember] + public int Kerning { + get => this._kerning; + set { + if (this.Set(ref this._kerning, value)) { + this.ResetCharacterSizes(); + this.Refresh(); + } + } + } + /// /// Gets or sets the render settings. /// @@ -158,7 +173,7 @@ private BoundingArea CreateBoundingArea() { private Vector2 CreateSize() { if (this.FontReference.Asset is { } spriteSheet) { - return new Vector2(this._spriteIndexes.Count * spriteSheet.SpriteSize.X, spriteSheet.SpriteSize.Y); + return new Vector2(this._spriteIndexes.Count * (spriteSheet.SpriteSize.X + this.Kerning), spriteSheet.SpriteSize.Y); } return Vector2.Zero; @@ -182,7 +197,7 @@ private void RenderSettings_PropertyChanged(object? sender, PropertyChangedEvent private void ResetCharacterSizes() { if (this.FontReference.Asset is { } spriteSheet) { - this._characterWidth = spriteSheet.SpriteSize.X * this.Settings.UnitsPerPixel; + this._characterWidth = (spriteSheet.SpriteSize.X + this.Kerning) * this.Settings.UnitsPerPixel; this._characterHeight = spriteSheet.SpriteSize.Y * this.Settings.UnitsPerPixel; } }