01.10.2020
+ Time controls (Stopwatch, Timers, Intervals) + Added smmeries to everything in SM.Base ~ Renamed Vectors to CVectors.
This commit is contained in:
parent
7acdba92f8
commit
97e638d9d9
44 changed files with 1092 additions and 289 deletions
|
|
@ -5,28 +5,50 @@ using System.Security.Policy;
|
|||
using OpenTK;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using OpenTK.Input;
|
||||
using SM.Base.Textures;
|
||||
using SM.Data.Fonts;
|
||||
using SM.OGL.Texture;
|
||||
|
||||
namespace SM.Base.Text
|
||||
{
|
||||
public class Font : TextureBase
|
||||
/// <summary>
|
||||
/// Represents a font.
|
||||
/// </summary>
|
||||
public class Font : Texture
|
||||
{
|
||||
public Dictionary<char, CharParameter> Positions = new Dictionary<char, CharParameter>();
|
||||
|
||||
public override TextureMinFilter Filter { get; set; } = TextureMinFilter.Linear;
|
||||
/// <inheritdoc />
|
||||
public override TextureWrapMode WrapMode { get; set; } = TextureWrapMode.ClampToEdge;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The font family, that is used to find the right font.
|
||||
/// </summary>
|
||||
public FontFamily FontFamily;
|
||||
|
||||
/// <summary>
|
||||
/// The font style.
|
||||
/// <para>Default: <see cref="System.Drawing.FontStyle.Regular"/></para>
|
||||
/// </summary>
|
||||
public FontStyle FontStyle = FontStyle.Regular;
|
||||
/// <summary>
|
||||
/// The font size.
|
||||
/// <para>Default: 12</para>
|
||||
/// </summary>
|
||||
public float FontSize = 12;
|
||||
/// <summary>
|
||||
/// The char set for the font.
|
||||
/// <para>Default: <see cref="FontCharStorage.SimpleUTF8"/></para>
|
||||
/// </summary>
|
||||
public ICollection<char> CharSet = FontCharStorage.SimpleUTF8;
|
||||
|
||||
public int Width { get; private set; }
|
||||
public int Height { get; private set; }
|
||||
public Bitmap Texture { get; private set; }
|
||||
/// <summary>
|
||||
/// This contains all information for the different font character.
|
||||
/// </summary>
|
||||
public Dictionary<char, CharParameter> Positions = new Dictionary<char, CharParameter>();
|
||||
|
||||
/// <summary>
|
||||
/// Generates a font from a font family from the specified path.
|
||||
/// </summary>
|
||||
/// <param name="path">The specified path</param>
|
||||
public Font(string path)
|
||||
{
|
||||
PrivateFontCollection pfc = new PrivateFontCollection();
|
||||
|
|
@ -34,16 +56,26 @@ namespace SM.Base.Text
|
|||
FontFamily = pfc.Families[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a font from a specified font family.
|
||||
/// </summary>
|
||||
/// <param name="font">Font-Family</param>
|
||||
public Font(FontFamily font)
|
||||
{
|
||||
FontFamily = font;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Regenerates the texture.
|
||||
/// </summary>
|
||||
public void RegenerateTexture()
|
||||
{
|
||||
Bitmap map = new Bitmap(1000,20);
|
||||
Width = 0;
|
||||
Height = 0;
|
||||
Positions = new Dictionary<char, CharParameter>();
|
||||
|
||||
|
||||
Bitmap map = new Bitmap(1000, 20);
|
||||
Dictionary<char, float[]> charParams = new Dictionary<char, float[]>();
|
||||
using (System.Drawing.Font f = new System.Drawing.Font(FontFamily, FontSize, FontStyle))
|
||||
{
|
||||
using (Graphics g = Graphics.FromImage(map))
|
||||
|
|
@ -56,7 +88,7 @@ namespace SM.Base.Text
|
|||
SizeF size = g.MeasureString(s, f);
|
||||
try
|
||||
{
|
||||
Positions.Add(c, new CharParameter() { Width = size.Width, X = Width });
|
||||
charParams.Add(c, new[] {size.Width, Width });
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
@ -71,25 +103,34 @@ namespace SM.Base.Text
|
|||
map = new Bitmap(Width, Height);
|
||||
using (Graphics g = Graphics.FromImage(map))
|
||||
{
|
||||
foreach (KeyValuePair<char, CharParameter> keyValuePair in Positions)
|
||||
foreach (KeyValuePair<char, float[]> keyValuePair in charParams)
|
||||
{
|
||||
keyValuePair.Value.RelativeX = (keyValuePair.Value.X + 0.00001f) / Width;
|
||||
keyValuePair.Value.RelativeWidth = (keyValuePair.Value.Width) / Width;
|
||||
float normalizedX = (keyValuePair.Value[1] + 0.00001f) / Width;
|
||||
float normalizedWidth = (keyValuePair.Value[0]) / Width;
|
||||
|
||||
g.DrawString(keyValuePair.Key.ToString(), f, Brushes.White, keyValuePair.Value.X, 0);
|
||||
CharParameter parameter;
|
||||
Positions.Add(keyValuePair.Key, parameter = new CharParameter()
|
||||
{
|
||||
NormalizedWidth = normalizedWidth,
|
||||
NormalizedX = normalizedX,
|
||||
Width = keyValuePair.Value[0],
|
||||
X = (int)keyValuePair.Value[1]
|
||||
});
|
||||
|
||||
g.DrawString(keyValuePair.Key.ToString(), f, Brushes.White, parameter.X, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Texture = map;
|
||||
|
||||
_id = SM.Base.Textures.Texture.GenerateTexture(map, Filter, WrapMode);
|
||||
Map = map;
|
||||
Recompile();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Compile()
|
||||
{
|
||||
base.Compile();
|
||||
RegenerateTexture();
|
||||
base.Compile();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue