1.0.11
+ 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:
parent
a921eb827e
commit
51f8dfd522
14 changed files with 78 additions and 24 deletions
|
|
@ -84,7 +84,7 @@ namespace SM.Base.Animation
|
||||||
|
|
||||||
private void SetTarget(Vector4 vec)
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -27,5 +27,8 @@ namespace SM.Base.Drawing.Text
|
||||||
|
|
||||||
|
|
||||||
public Matrix3 TextureMatrix;
|
public Matrix3 TextureMatrix;
|
||||||
|
|
||||||
|
public Vector2 Offset;
|
||||||
|
public Vector2 Scale;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -47,7 +47,7 @@ namespace SM.Base.Drawing.Text
|
||||||
_fontFace.LoadChar(c, LoadFlags.Render, LoadTarget.Normal);
|
_fontFace.LoadChar(c, LoadFlags.Render, LoadTarget.Normal);
|
||||||
|
|
||||||
pos.Add(c, new []{(float)_fontFace.Glyph.Bitmap.Width, Width});
|
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);
|
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 bBoxHeight = (Math.Abs(_fontFace.BBox.Bottom) + _fontFace.BBox.Top);
|
||||||
float bBoxTopScale = _fontFace.BBox.Top / bBoxHeight;
|
float bBoxTopScale = _fontFace.BBox.Top / bBoxHeight;
|
||||||
float baseline = Height * bBoxTopScale;
|
float baseline = Height * bBoxTopScale + 1;
|
||||||
|
|
||||||
Map = new Bitmap(Width, Height);
|
Map = new Bitmap(Width, Height);
|
||||||
using (Graphics g = Graphics.FromImage(Map))
|
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);
|
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()
|
Positions.Add(keyvalue.Key, new CharParameter()
|
||||||
{
|
{
|
||||||
Advance = (int)_fontFace.Glyph.LinearHorizontalAdvance,
|
Advance = (int)_fontFace.Glyph.LinearHorizontalAdvance,
|
||||||
|
|
@ -79,8 +81,11 @@ namespace SM.Base.Drawing.Text
|
||||||
|
|
||||||
Width = keyvalue.Value[0],
|
Width = keyvalue.Value[0],
|
||||||
|
|
||||||
TextureMatrix = TextureTransformation.CalculateMatrix(new Vector2(keyvalue.Value[1] / Width, 0),
|
TextureMatrix = TextureTransformation.CalculateMatrix(offset,
|
||||||
new Vector2(keyvalue.Value[0] / Width, 1), 0),
|
scale, 0),
|
||||||
|
|
||||||
|
Offset = offset,
|
||||||
|
Scale = scale
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,6 @@ namespace SM.Base.Drawing.Text
|
||||||
|
|
||||||
float x = 0;
|
float x = 0;
|
||||||
float y = 0;
|
float y = 0;
|
||||||
var _last = new CharParameter();
|
|
||||||
for (var i = 0; i < _text.Length; i++)
|
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) *
|
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
|
_instances[i] = new Instance
|
||||||
{
|
{
|
||||||
ModelMatrix = matrix,
|
ModelMatrix = matrix,
|
||||||
TextureMatrix = parameter.TextureMatrix
|
TextureMatrix = parameter.TextureMatrix
|
||||||
};
|
};
|
||||||
|
|
||||||
x += Math.Max(parameter.Advance, 6);
|
Width = Math.Max(Width, x);
|
||||||
_last = parameter;
|
x += parameter.Advance;
|
||||||
}
|
}
|
||||||
|
|
||||||
Width = Math.Max(Width, x);
|
|
||||||
Height = y + Font.Height;
|
Height = y + Font.Height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,9 @@
|
||||||
<EmbeddedResource Include="Shaders\Extensions\fragment\textureGamma.glsl" />
|
<EmbeddedResource Include="Shaders\Extensions\fragment\textureGamma.glsl" />
|
||||||
<EmbeddedResource Include="Shaders\Extensions\fragment\noise.glsl" />
|
<EmbeddedResource Include="Shaders\Extensions\fragment\noise.glsl" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup />
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Include="Window\winIcon.ico" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ namespace SM.Base.Types
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Set(params float[] parameters)
|
public override void SetRaw(params float[] parameters)
|
||||||
{
|
{
|
||||||
X = parameters[0];
|
X = parameters[0];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -87,9 +87,9 @@ namespace SM.Base.Types
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Set(params float[] parameters)
|
public override void SetRaw(params float[] parameters)
|
||||||
{
|
{
|
||||||
base.Set(parameters);
|
base.SetRaw(parameters);
|
||||||
Y = parameters[1];
|
Y = parameters[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,9 +82,9 @@ namespace SM.Base.Types
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Set(params float[] parameters)
|
public override void SetRaw(params float[] parameters)
|
||||||
{
|
{
|
||||||
base.Set(parameters);
|
base.SetRaw(parameters);
|
||||||
Z = parameters[2];
|
Z = parameters[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -66,9 +66,9 @@ namespace SM.Base.Types
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Set(params float[] parameters)
|
public override void SetRaw(params float[] parameters)
|
||||||
{
|
{
|
||||||
base.Set(parameters);
|
base.SetRaw(parameters);
|
||||||
W = parameters[3];
|
W = parameters[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ namespace SM.Base.Types
|
||||||
/// Sets the values of the vector, by providing the values over an array.
|
/// Sets the values of the vector, by providing the values over an array.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="parameters"></param>
|
/// <param name="parameters"></param>
|
||||||
public abstract void Set(params float[] parameters);
|
public abstract void SetRaw(params float[] parameters);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This triggers the <see cref="Changed"/> event.
|
/// This triggers the <see cref="Changed"/> event.
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Drawing;
|
||||||
using System.Drawing.Text;
|
using System.Drawing.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
@ -138,9 +139,15 @@ namespace SM.Base.Window
|
||||||
Loading = false;
|
Loading = false;
|
||||||
Loaded?.Invoke(this);
|
Loaded?.Invoke(this);
|
||||||
AppliedSetup?.Loaded(this);
|
AppliedSetup?.Loaded(this);
|
||||||
|
OnLoaded();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual void OnLoaded()
|
||||||
|
{
|
||||||
|
Icon ??= new Icon(AssemblyUtility.GetAssemblyStream("SM.Base.Window.winIcon.ico"));
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void OnUpdateFrame(FrameEventArgs e)
|
protected override void OnUpdateFrame(FrameEventArgs e)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
BIN
SMCode/SM.Base/Window/winIcon.ico
Normal file
BIN
SMCode/SM.Base/Window/winIcon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 66 KiB |
|
|
@ -28,7 +28,7 @@ namespace SM2D.Controls
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static Vector2 InWorld(Camera cam)
|
public static Vector2 InWorld(Camera cam)
|
||||||
{
|
{
|
||||||
return InWorld(cam.WorldScale) + cam.Position;
|
return InWorld(cam.CalculatedWorldScale) + cam.Position;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,10 @@ using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
|
using OpenTK.Graphics.OpenGL;
|
||||||
using SM.Base.Animation;
|
using SM.Base.Animation;
|
||||||
using SM.Base.Controls;
|
using SM.Base.Controls;
|
||||||
|
using SM.Base.Drawing;
|
||||||
using SM.Base.Drawing.Text;
|
using SM.Base.Drawing.Text;
|
||||||
using SM.Base.Time;
|
using SM.Base.Time;
|
||||||
using SM.Base.Window;
|
using SM.Base.Window;
|
||||||
|
|
@ -27,16 +29,54 @@ namespace SM_TEST
|
||||||
{
|
{
|
||||||
Font font = new Font(@"C:\Windows\Fonts\Arial.ttf")
|
Font font = new Font(@"C:\Windows\Fonts\Arial.ttf")
|
||||||
{
|
{
|
||||||
FontSize = 20,
|
FontSize = 30,
|
||||||
CharSet = new List<char>(){'H', 'i', 'I', ','}
|
|
||||||
};
|
};
|
||||||
|
font.RegenerateTexture();
|
||||||
|
|
||||||
window = new GLWindow(1280, 720, "0ms", WindowFlags.Window, VSyncMode.Off);
|
window = new GLWindow(1280, 720, "0ms", WindowFlags.Window, VSyncMode.Off);
|
||||||
window.ApplySetup(new Window2DSetup());
|
window.ApplySetup(new Window2DSetup());
|
||||||
|
|
||||||
window.SetScene(scene = new Scene());
|
window.SetScene(scene = new Scene());
|
||||||
|
|
||||||
scene.Background.Color = Color4.Blue;
|
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.UpdateFrame += WindowOnUpdateFrame;
|
||||||
window.RenderFrame += Window_RenderFrame;
|
window.RenderFrame += Window_RenderFrame;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue