+ Windows now have a default icon

~ Changed CVector.Set(params float[]) to CVector.SetRaw(params float[])
~ I hope, the text rendering is now fixed.
~ Mouse2D.InWorld(Camera) now uses Camera.CalculatedWorldScale.
This commit is contained in:
Michel Fedde 2021-04-22 17:49:42 +02:00
parent a921eb827e
commit 51f8dfd522
14 changed files with 78 additions and 24 deletions

View file

@ -84,7 +84,7 @@ namespace SM.Base.Animation
private void SetTarget(Vector4 vec)
{
TargetVector.Set(vec.X, vec.Y, vec.Z, vec.W);
TargetVector.SetRaw(vec.X, vec.Y, vec.Z, vec.W);
}
}
}

View file

@ -27,5 +27,8 @@ namespace SM.Base.Drawing.Text
public Matrix3 TextureMatrix;
public Vector2 Offset;
public Vector2 Scale;
}
}

View file

@ -47,7 +47,7 @@ namespace SM.Base.Drawing.Text
_fontFace.LoadChar(c, LoadFlags.Render, LoadTarget.Normal);
pos.Add(c, new []{(float)_fontFace.Glyph.Bitmap.Width, Width});
Width += (int)_fontFace.Glyph.Advance.X + 5;
Width += (int)_fontFace.Glyph.Advance.X + 2;
Height = Math.Max(_fontFace.Glyph.Bitmap.Rows, Height);
}
@ -56,7 +56,7 @@ namespace SM.Base.Drawing.Text
float bBoxHeight = (Math.Abs(_fontFace.BBox.Bottom) + _fontFace.BBox.Top);
float bBoxTopScale = _fontFace.BBox.Top / bBoxHeight;
float baseline = Height * bBoxTopScale;
float baseline = Height * bBoxTopScale + 1;
Map = new Bitmap(Width, Height);
using (Graphics g = Graphics.FromImage(Map))
@ -72,6 +72,8 @@ namespace SM.Base.Drawing.Text
g.DrawImageUnscaled(_fontFace.Glyph.Bitmap.ToGdipBitmap(Color.White), (int)keyvalue.Value[1], y);
Vector2 offset = new Vector2(keyvalue.Value[1] / Width, 0);
Vector2 scale = new Vector2(keyvalue.Value[0] / Width, 1);
Positions.Add(keyvalue.Key, new CharParameter()
{
Advance = (int)_fontFace.Glyph.LinearHorizontalAdvance,
@ -79,8 +81,11 @@ namespace SM.Base.Drawing.Text
Width = keyvalue.Value[0],
TextureMatrix = TextureTransformation.CalculateMatrix(new Vector2(keyvalue.Value[1] / Width, 0),
new Vector2(keyvalue.Value[0] / Width, 1), 0),
TextureMatrix = TextureTransformation.CalculateMatrix(offset,
scale, 0),
Offset = offset,
Scale = scale
});
}
}

View file

@ -109,7 +109,6 @@ namespace SM.Base.Drawing.Text
float x = 0;
float y = 0;
var _last = new CharParameter();
for (var i = 0; i < _text.Length; i++)
{
@ -144,18 +143,16 @@ namespace SM.Base.Drawing.Text
}
var matrix = Matrix4.CreateScale(parameter.Width, Font.Height, 1) *
Matrix4.CreateTranslation(x, -y, 0);
Matrix4.CreateTranslation(x + parameter.Width / 2, -y, 0);
_instances[i] = new Instance
{
ModelMatrix = matrix,
TextureMatrix = parameter.TextureMatrix
};
x += Math.Max(parameter.Advance, 6);
_last = parameter;
Width = Math.Max(Width, x);
x += parameter.Advance;
}
Width = Math.Max(Width, x);
Height = y + Font.Height;
}
}

View file

@ -151,7 +151,9 @@
<EmbeddedResource Include="Shaders\Extensions\fragment\textureGamma.glsl" />
<EmbeddedResource Include="Shaders\Extensions\fragment\noise.glsl" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<EmbeddedResource Include="Window\winIcon.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>

View file

@ -53,7 +53,7 @@ namespace SM.Base.Types
}
/// <inheritdoc />
public override void Set(params float[] parameters)
public override void SetRaw(params float[] parameters)
{
X = parameters[0];
}

View file

@ -87,9 +87,9 @@ namespace SM.Base.Types
}
/// <inheritdoc />
public override void Set(params float[] parameters)
public override void SetRaw(params float[] parameters)
{
base.Set(parameters);
base.SetRaw(parameters);
Y = parameters[1];
}

View file

@ -82,9 +82,9 @@ namespace SM.Base.Types
}
/// <inheritdoc />
public override void Set(params float[] parameters)
public override void SetRaw(params float[] parameters)
{
base.Set(parameters);
base.SetRaw(parameters);
Z = parameters[2];
}

View file

@ -66,9 +66,9 @@ namespace SM.Base.Types
}
/// <inheritdoc />
public override void Set(params float[] parameters)
public override void SetRaw(params float[] parameters)
{
base.Set(parameters);
base.SetRaw(parameters);
W = parameters[3];
}

View file

@ -52,7 +52,7 @@ namespace SM.Base.Types
/// Sets the values of the vector, by providing the values over an array.
/// </summary>
/// <param name="parameters"></param>
public abstract void Set(params float[] parameters);
public abstract void SetRaw(params float[] parameters);
/// <summary>
/// This triggers the <see cref="Changed"/> event.

View file

@ -3,6 +3,7 @@
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Text;
using System.Threading;
using System.Windows.Forms;
@ -138,9 +139,15 @@ namespace SM.Base.Window
Loading = false;
Loaded?.Invoke(this);
AppliedSetup?.Loaded(this);
OnLoaded();
}
}
protected virtual void OnLoaded()
{
Icon ??= new Icon(AssemblyUtility.GetAssemblyStream("SM.Base.Window.winIcon.ico"));
}
/// <inheritdoc />
protected override void OnUpdateFrame(FrameEventArgs e)
{

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

View file

@ -28,7 +28,7 @@ namespace SM2D.Controls
/// </summary>
public static Vector2 InWorld(Camera cam)
{
return InWorld(cam.WorldScale) + cam.Position;
return InWorld(cam.CalculatedWorldScale) + cam.Position;
}
/// <summary>

View file

@ -3,8 +3,10 @@ using System.Collections.Generic;
using System.Diagnostics;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using SM.Base.Animation;
using SM.Base.Controls;
using SM.Base.Drawing;
using SM.Base.Drawing.Text;
using SM.Base.Time;
using SM.Base.Window;
@ -27,16 +29,54 @@ namespace SM_TEST
{
Font font = new Font(@"C:\Windows\Fonts\Arial.ttf")
{
FontSize = 20,
CharSet = new List<char>(){'H', 'i', 'I', ','}
FontSize = 30,
};
font.RegenerateTexture();
window = new GLWindow(1280, 720, "0ms", WindowFlags.Window, VSyncMode.Off);
window.ApplySetup(new Window2DSetup());
window.SetScene(scene = new Scene());
scene.Background.Color = Color4.Blue;
scene.Camera = new Camera()
{
RequestedWorldScale = new Vector2(0, 10)
};
ItemCollection col = new ItemCollection();
DrawObject2D textTex = new DrawObject2D()
{
Texture = font,
Material = {Blending = true}
};
float aspect = font.Height / (float) font.Width;
textTex.Transform.Size.Set(font.Width * aspect, font.Height * aspect);
textTex.Transform.Position.Set(textTex.Transform.Size.X / 2, 0);
Vector2 fontSize = new Vector2(font.Width * aspect, font.Height * aspect);
Material uvMaterial = new Material()
{
Tint = new Color4(1f, 0, 0, .5f),
Blending = true
};
col.Transform.Size.Set(1);
DrawText test = new DrawText(font, "Level Completed")
{
Material = uvMaterial,
Font = font
};
test.Transform.Size.Set(aspect);
test.Transform.Position.Set(0, 2);
col.Add(test, textTex);
scene.Objects.Add(col);
window.UpdateFrame += WindowOnUpdateFrame;
window.RenderFrame += Window_RenderFrame;