+ 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

@ -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;
}
}