Allowed for the text to set a text origin.
This commit is contained in:
parent
51f8dfd522
commit
17e76a9dd4
6 changed files with 56 additions and 38 deletions
|
|
@ -27,8 +27,5 @@ namespace SM.Base.Drawing.Text
|
|||
|
||||
|
||||
public Matrix3 TextureMatrix;
|
||||
|
||||
public Vector2 Offset;
|
||||
public Vector2 Scale;
|
||||
}
|
||||
}
|
||||
|
|
@ -83,14 +83,9 @@ namespace SM.Base.Drawing.Text
|
|||
|
||||
TextureMatrix = TextureTransformation.CalculateMatrix(offset,
|
||||
scale, 0),
|
||||
|
||||
Offset = offset,
|
||||
Scale = scale
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
public override void Compile()
|
||||
|
|
|
|||
|
|
@ -3,12 +3,20 @@
|
|||
using System;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using SM.Base.Objects.Static;
|
||||
using SM.Base.Window;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Drawing.Text
|
||||
{
|
||||
public enum TextOrigin
|
||||
{
|
||||
Left,
|
||||
Center,
|
||||
Right
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Defines a basis for text drawing.
|
||||
/// </summary>
|
||||
|
|
@ -36,6 +44,12 @@ namespace SM.Base.Drawing.Text
|
|||
/// </summary>
|
||||
public float Height;
|
||||
|
||||
/// <summary>
|
||||
/// Allow to change the origin of the text.
|
||||
/// <para>Default: <see cref="TextOrigin.Center"/></para>
|
||||
/// </summary>
|
||||
public TextOrigin Origin = TextOrigin.Center;
|
||||
|
||||
/// <summary>
|
||||
/// The spacing between numbers.
|
||||
/// <para>Default: 1</para>
|
||||
|
|
@ -85,6 +99,7 @@ namespace SM.Base.Drawing.Text
|
|||
{
|
||||
Material.Texture = font;
|
||||
Material.Blending = true;
|
||||
Mesh = Plate.Object;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -111,7 +126,6 @@ namespace SM.Base.Drawing.Text
|
|||
float y = 0;
|
||||
for (var i = 0; i < _text.Length; i++)
|
||||
{
|
||||
|
||||
if (_text[i] == ' ')
|
||||
{
|
||||
x += Font.SpaceWidth * Spacing;
|
||||
|
|
@ -150,10 +164,27 @@ namespace SM.Base.Drawing.Text
|
|||
TextureMatrix = parameter.TextureMatrix
|
||||
};
|
||||
|
||||
Width = Math.Max(Width, x);
|
||||
x += parameter.Advance;
|
||||
}
|
||||
Height = y + Font.Height;
|
||||
Width = x;
|
||||
|
||||
if (Origin != TextOrigin.Left)
|
||||
{
|
||||
foreach (Instance i in _instances)
|
||||
{
|
||||
if (i == null) continue;
|
||||
switch (Origin)
|
||||
{
|
||||
case TextOrigin.Center:
|
||||
i.ModelMatrix *= Matrix4.CreateTranslation(-Width / 2, 0, 0);
|
||||
break;
|
||||
case TextOrigin.Right:
|
||||
i.ModelMatrix *= Matrix4.CreateTranslation(-Width, 0, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -102,7 +102,7 @@ namespace SM.Base.Scene
|
|||
addObject(show);
|
||||
|
||||
if (item is IScriptable scriptable)
|
||||
AddScript(scriptable);
|
||||
addScript(scriptable);
|
||||
|
||||
if (item is IFixedScriptable fixedScriptable) _fixedScriptables.Add(fixedScriptable);
|
||||
}
|
||||
|
|
@ -145,7 +145,6 @@ namespace SM.Base.Scene
|
|||
/// Adds the script to the collection.
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
[Obsolete("Please use Add()")]
|
||||
public void addScript(IScriptable item)
|
||||
{
|
||||
_scriptableObjects.Add(item);
|
||||
|
|
|
|||
|
|
@ -23,6 +23,14 @@ namespace SM2D.Drawing
|
|||
Transform.Size = new CVector2(1);
|
||||
}
|
||||
|
||||
public void SetHeight(float desiredHeight)
|
||||
{
|
||||
if (!Font.WasCompiled) Font.Compile();
|
||||
|
||||
float factor = desiredHeight / Font.Height;
|
||||
Transform.Size.Set(factor);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void DrawContext(ref DrawContext context)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue