diff --git a/SMCode/SM.Base/Animation/InterpolationProcess.cs b/SMCode/SM.Base/Animation/InterpolationProcess.cs index 83b6de8..7fa1bc8 100644 --- a/SMCode/SM.Base/Animation/InterpolationProcess.cs +++ b/SMCode/SM.Base/Animation/InterpolationProcess.cs @@ -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); } } } \ No newline at end of file diff --git a/SMCode/SM.Base/Drawing/Text/CharParameter.cs b/SMCode/SM.Base/Drawing/Text/CharParameter.cs index aec2380..6f9661a 100644 --- a/SMCode/SM.Base/Drawing/Text/CharParameter.cs +++ b/SMCode/SM.Base/Drawing/Text/CharParameter.cs @@ -27,5 +27,8 @@ namespace SM.Base.Drawing.Text public Matrix3 TextureMatrix; + + public Vector2 Offset; + public Vector2 Scale; } } \ No newline at end of file diff --git a/SMCode/SM.Base/Drawing/Text/Font.cs b/SMCode/SM.Base/Drawing/Text/Font.cs index 9a66924..9b2383c 100644 --- a/SMCode/SM.Base/Drawing/Text/Font.cs +++ b/SMCode/SM.Base/Drawing/Text/Font.cs @@ -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 }); } } diff --git a/SMCode/SM.Base/Drawing/Text/TextDrawingBasis.cs b/SMCode/SM.Base/Drawing/Text/TextDrawingBasis.cs index ee25586..ab6e358 100644 --- a/SMCode/SM.Base/Drawing/Text/TextDrawingBasis.cs +++ b/SMCode/SM.Base/Drawing/Text/TextDrawingBasis.cs @@ -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; } } diff --git a/SMCode/SM.Base/SM.Base.csproj b/SMCode/SM.Base/SM.Base.csproj index 7f23c7e..5e201f9 100644 --- a/SMCode/SM.Base/SM.Base.csproj +++ b/SMCode/SM.Base/SM.Base.csproj @@ -151,7 +151,9 @@ - + + + diff --git a/SMCode/SM.Base/Types/CVector1.cs b/SMCode/SM.Base/Types/CVector1.cs index 1dcb6ba..b2a80f9 100644 --- a/SMCode/SM.Base/Types/CVector1.cs +++ b/SMCode/SM.Base/Types/CVector1.cs @@ -53,7 +53,7 @@ namespace SM.Base.Types } /// - public override void Set(params float[] parameters) + public override void SetRaw(params float[] parameters) { X = parameters[0]; } diff --git a/SMCode/SM.Base/Types/CVector2.cs b/SMCode/SM.Base/Types/CVector2.cs index 521458b..8063c6b 100644 --- a/SMCode/SM.Base/Types/CVector2.cs +++ b/SMCode/SM.Base/Types/CVector2.cs @@ -87,9 +87,9 @@ namespace SM.Base.Types } /// - public override void Set(params float[] parameters) + public override void SetRaw(params float[] parameters) { - base.Set(parameters); + base.SetRaw(parameters); Y = parameters[1]; } diff --git a/SMCode/SM.Base/Types/CVector3.cs b/SMCode/SM.Base/Types/CVector3.cs index 3281510..64231f0 100644 --- a/SMCode/SM.Base/Types/CVector3.cs +++ b/SMCode/SM.Base/Types/CVector3.cs @@ -82,9 +82,9 @@ namespace SM.Base.Types } /// - public override void Set(params float[] parameters) + public override void SetRaw(params float[] parameters) { - base.Set(parameters); + base.SetRaw(parameters); Z = parameters[2]; } diff --git a/SMCode/SM.Base/Types/CVector4.cs b/SMCode/SM.Base/Types/CVector4.cs index 368e870..2f88938 100644 --- a/SMCode/SM.Base/Types/CVector4.cs +++ b/SMCode/SM.Base/Types/CVector4.cs @@ -66,9 +66,9 @@ namespace SM.Base.Types } /// - public override void Set(params float[] parameters) + public override void SetRaw(params float[] parameters) { - base.Set(parameters); + base.SetRaw(parameters); W = parameters[3]; } diff --git a/SMCode/SM.Base/Types/CVectorBase.cs b/SMCode/SM.Base/Types/CVectorBase.cs index e740a39..2340b84 100644 --- a/SMCode/SM.Base/Types/CVectorBase.cs +++ b/SMCode/SM.Base/Types/CVectorBase.cs @@ -52,7 +52,7 @@ namespace SM.Base.Types /// Sets the values of the vector, by providing the values over an array. /// /// - public abstract void Set(params float[] parameters); + public abstract void SetRaw(params float[] parameters); /// /// This triggers the event. diff --git a/SMCode/SM.Base/Window/GLWindow.cs b/SMCode/SM.Base/Window/GLWindow.cs index 43a55ff..51b9016 100644 --- a/SMCode/SM.Base/Window/GLWindow.cs +++ b/SMCode/SM.Base/Window/GLWindow.cs @@ -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")); + } + /// protected override void OnUpdateFrame(FrameEventArgs e) { diff --git a/SMCode/SM.Base/Window/winIcon.ico b/SMCode/SM.Base/Window/winIcon.ico new file mode 100644 index 0000000..1036f8f Binary files /dev/null and b/SMCode/SM.Base/Window/winIcon.ico differ diff --git a/SMCode/SM2D/Controls/Mouse2D.cs b/SMCode/SM2D/Controls/Mouse2D.cs index 2690cef..fcac15d 100644 --- a/SMCode/SM2D/Controls/Mouse2D.cs +++ b/SMCode/SM2D/Controls/Mouse2D.cs @@ -28,7 +28,7 @@ namespace SM2D.Controls /// public static Vector2 InWorld(Camera cam) { - return InWorld(cam.WorldScale) + cam.Position; + return InWorld(cam.CalculatedWorldScale) + cam.Position; } /// diff --git a/SM_TEST/Program.cs b/SM_TEST/Program.cs index 0ffc516..95e70ae 100644 --- a/SM_TEST/Program.cs +++ b/SM_TEST/Program.cs @@ -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(){'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;