01.10.2020

+ Time controls (Stopwatch, Timers, Intervals)
+ Added smmeries to everything in SM.Base

~ Renamed Vectors to CVectors.
This commit is contained in:
Michel Fedde 2020-10-01 15:39:03 +02:00
parent 7acdba92f8
commit 97e638d9d9
44 changed files with 1092 additions and 289 deletions

View file

@ -7,12 +7,25 @@ using SM.Data.Fonts;
namespace SM.Base.Text
{
/// <summary>
/// Defines a basis for text drawing.
/// </summary>
/// <typeparam name="TTransform">Transformation type</typeparam>
public abstract class TextDrawingBasis<TTransform> : DrawingBasis<TTransform>
where TTransform : GenericTransformation, new()
{
protected Instance[] _modelMatrixs;
/// <summary>
/// The different instances for drawing.
/// </summary>
protected Instance[] _instances;
/// <summary>
/// The text, that is drawn.
/// </summary>
protected string _text;
/// <summary>
/// The font.
/// </summary>
public Font Font
{
get => (Font) _material.Texture;
@ -23,6 +36,9 @@ namespace SM.Base.Text
}
}
/// <summary>
/// The text, that is drawn.
/// </summary>
public string Text
{
get => _text;
@ -33,30 +49,47 @@ namespace SM.Base.Text
}
}
/// <summary>
/// The font color.
/// </summary>
public Color4 Color
{
get => _material.Tint;
set => _material.Tint = value;
}
/// <summary>
/// The spacing between numbers.
/// <para>Default: 1</para>
/// </summary>
public float Spacing = 1;
/// <summary>
/// Creates a text object with a font.
/// </summary>
/// <param name="font">The font.</param>
protected TextDrawingBasis(Font font)
{
_material.Texture = font;
}
/// <inheritdoc />
public override void Draw(DrawContext context)
{
base.Draw(context);
if (_modelMatrixs == null) GenerateMatrixes();
if (_instances == null) GenerateMatrixes();
}
/// <summary>
/// This generates the instances.
/// </summary>
/// <exception cref="Exception">The font doesn't contain a character that is needed for the text.</exception>
public void GenerateMatrixes()
{
if (!Font.WasCompiled) Font.RegenerateTexture();
_modelMatrixs = new Instance[_text.Length];
_instances = new Instance[_text.Length];
float x = 0;
CharParameter _last = new CharParameter();
@ -80,11 +113,11 @@ namespace SM.Base.Text
Matrix4 matrix = Matrix4.CreateScale(parameter.Width, Font.Height, 1) *
Matrix4.CreateTranslation(x, 0, 0);
_modelMatrixs[i] = new Instance
_instances[i] = new Instance
{
ModelMatrix = matrix,
TexturePosition = new Vector2(parameter.RelativeX, 0),
TextureScale = new Vector2(parameter.RelativeWidth, 1)
TexturePosition = new Vector2(parameter.NormalizedX, 0),
TextureScale = new Vector2(parameter.NormalizedWidth, 1)
};
x += parameter.Width * Spacing;