20.09.2020
+ Instance Drawing + Text and Font ~ Made "DrawBackground" forced Background for 2D - DrawEmpty
This commit is contained in:
parent
acccf5f0e7
commit
c4a0847567
29 changed files with 365 additions and 85 deletions
83
SMCode/SM.Base/Text/TextDrawingBasis.cs
Normal file
83
SMCode/SM.Base/Text/TextDrawingBasis.cs
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
using System;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using SM.Base.Contexts;
|
||||
using SM.Base.Scene;
|
||||
using SM.Data.Fonts;
|
||||
|
||||
namespace SM.Base.Text
|
||||
{
|
||||
public abstract class TextDrawingBasis<TTransform> : DrawingBasis<TTransform>
|
||||
where TTransform : GenericTransformation, new()
|
||||
{
|
||||
protected Instance[] _modelMatrixs;
|
||||
protected string _text;
|
||||
|
||||
public Font Font
|
||||
{
|
||||
get => (Font) _material.Texture;
|
||||
set
|
||||
{
|
||||
_material.Texture = value;
|
||||
GenerateMatrixes();
|
||||
}
|
||||
}
|
||||
|
||||
public string Text
|
||||
{
|
||||
get => _text;
|
||||
set
|
||||
{
|
||||
_text = value;
|
||||
GenerateMatrixes();
|
||||
}
|
||||
}
|
||||
|
||||
public Color4 Color
|
||||
{
|
||||
get => _material.Tint;
|
||||
set => _material.Tint = value;
|
||||
}
|
||||
|
||||
protected TextDrawingBasis(Font font)
|
||||
{
|
||||
_material.Texture = font;
|
||||
}
|
||||
|
||||
public override void Draw(DrawContext context)
|
||||
{
|
||||
base.Draw(context);
|
||||
if (_modelMatrixs == null) GenerateMatrixes();
|
||||
}
|
||||
|
||||
public void GenerateMatrixes()
|
||||
{
|
||||
if (!Font.WasCompiled) Font.RegenerateTexture();
|
||||
|
||||
_modelMatrixs = new Instance[_text.Length];
|
||||
|
||||
float x = 0;
|
||||
for (var i = 0; i < _text.Length; i++)
|
||||
{
|
||||
CharParameter parameter;
|
||||
try
|
||||
{
|
||||
parameter = Font.Positions[_text[i]];
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new Exception("Font doesn't contain '"+_text[i]+"'");
|
||||
}
|
||||
|
||||
Matrix4 matrix = Matrix4.CreateScale(parameter.Width, Font.Height, 1) * Matrix4.CreateTranslation(x, 0, 0);
|
||||
_modelMatrixs[i] = new Instance
|
||||
{
|
||||
ModelMatrix = matrix,
|
||||
TexturePosition = new Vector2(parameter.RelativeX, 0),
|
||||
TextureScale = new Vector2(parameter.RelativeWidth, 1)
|
||||
};
|
||||
x += parameter.Width;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue