Holidays 12.10. -> 25.10.2020

~ Moved code around in files.

SM.Base:
+ PostProcessing-system
+ OnInitialization() for Scenes.
+ Shader-Extensions
+ Added option to not react while unfocused to the window.
+ Added Screenshots to the window.
+ Connected the log system to the SM.OGL-action system.

~ Replaced IShader with abstract MaterialShader.
~ When a log compression folder doesn't exist, it will create one.

SM.OGL:
+ Added support for UniformArrays
+ Added ShaderPreProcessing
+ Added Shader Extensions.
+ Added Debug actions.
+ SM.OGL settings

~ Framebuffer Size is automaticly changed, when the window and scale is set.

SM2D:
+ Added easy shader drawing.
This commit is contained in:
Michel Fedde 2020-10-24 15:10:36 +02:00
parent 2c00dbd31a
commit 03b3942732
102 changed files with 2683 additions and 1398 deletions

View file

@ -1,71 +1,74 @@
using System.Collections.Generic;
#region usings
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Text;
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;
#endregion
namespace SM.Base.Text
{
/// <summary>
/// Represents a font.
/// Represents a font.
/// </summary>
public class Font : Texture
{
/// <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>
/// The char set for the font.
/// <para>Default: <see cref="FontCharStorage.SimpleUTF8" /></para>
/// </summary>
public ICollection<char> CharSet = FontCharStorage.SimpleUTF8;
/// <summary>
/// This contains all information for the different font character.
/// The font family, that is used to find the right font.
/// </summary>
public FontFamily FontFamily;
/// <summary>
/// The font size.
/// <para>Default: 12</para>
/// </summary>
public float FontSize = 12;
/// <summary>
/// The font style.
/// <para>Default: <see cref="System.Drawing.FontStyle.Regular" /></para>
/// </summary>
public FontStyle FontStyle = FontStyle.Regular;
/// <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.
/// 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();
var pfc = new PrivateFontCollection();
pfc.AddFontFile(path);
FontFamily = pfc.Families[0];
}
/// <summary>
/// Generates a font from a specified font family.
/// Generates a font from a specified font family.
/// </summary>
/// <param name="font">Font-Family</param>
public Font(FontFamily font)
{
FontFamily = font;
}
/// <inheritdoc />
public override TextureWrapMode WrapMode { get; set; } = TextureWrapMode.ClampToEdge;
/// <summary>
/// Regenerates the texture.
/// Regenerates the texture.
/// </summary>
public void RegenerateTexture()
{
@ -74,47 +77,47 @@ namespace SM.Base.Text
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))
var map = new Bitmap(1000, 20);
var charParams = new Dictionary<char, float[]>();
using (var f = new System.Drawing.Font(FontFamily, FontSize, FontStyle))
{
using (Graphics g = Graphics.FromImage(map))
using (var g = Graphics.FromImage(map))
{
g.Clear(Color.Transparent);
foreach (char c in CharSet)
foreach (var c in CharSet)
{
string s = c.ToString();
SizeF size = g.MeasureString(s, f);
var s = c.ToString();
var size = g.MeasureString(s, f);
try
{
charParams.Add(c, new[] {size.Width, Width });
charParams.Add(c, new[] {size.Width, Width});
}
catch
{
// ignored
}
if (Height < size.Height) Height = (int)size.Height;
Width += (int)size.Width;
if (Height < size.Height) Height = (int) size.Height;
Width += (int) size.Width;
}
}
map = new Bitmap(Width, Height);
using (Graphics g = Graphics.FromImage(map))
using (var g = Graphics.FromImage(map))
{
foreach (KeyValuePair<char, float[]> keyValuePair in charParams)
foreach (var keyValuePair in charParams)
{
float normalizedX = (keyValuePair.Value[1] + 0.00001f) / Width;
float normalizedWidth = (keyValuePair.Value[0]) / Width;
var normalizedX = (keyValuePair.Value[1] + 0.00001f) / Width;
var normalizedWidth = keyValuePair.Value[0] / Width;
CharParameter parameter;
Positions.Add(keyValuePair.Key, parameter = new CharParameter()
Positions.Add(keyValuePair.Key, parameter = new CharParameter
{
NormalizedWidth = normalizedWidth,
NormalizedX = normalizedX,
Width = keyValuePair.Value[0],
X = (int)keyValuePair.Value[1]
X = (int) keyValuePair.Value[1]
});
g.DrawString(keyValuePair.Key.ToString(), f, Brushes.White, parameter.X, 0);