1.0.12 & 1.0.12.1

+ Utility Methods for texture transformations

~ Fixed an issue, where the horizontal & vertical flip was wrongly applied
~ Added missing summaries
This commit is contained in:
Michel Fedde 2021-05-05 17:36:12 +02:00
parent a29a2cab53
commit f11a954b5a
10 changed files with 116 additions and 21 deletions

View file

@ -18,17 +18,17 @@ namespace SM.Base.Drawing
/// <summary>
/// The camera, that was used last time the object was rendered.
/// </summary>
public GenericCamera LastDrawingCamera;
public GenericCamera LastDrawingCamera { get; private set; }
/// <summary>
/// The material it should use.
/// </summary>
public Material Material = new Material();
public Material Material { get; set; } = new Material();
/// <summary>
/// Transformation for the textures.
/// </summary>
public TextureTransformation TextureTransform = new TextureTransformation();
public TextureTransformation TextureTransform { get; set; } = new TextureTransformation();
/// <summary>
/// This allows custom shaders to add own arguments.
@ -71,7 +71,6 @@ namespace SM.Base.Drawing
DrawContext(ref context);
}
/// <inheritdoc />
public virtual void OnAdded(object sender)
{

View file

@ -18,6 +18,9 @@ namespace SM.Base.Drawing.Text
/// </summary>
public int Advance;
/// <summary>
/// The bearing for this char.
/// </summary>
public float BearingX;
/// <summary>
@ -26,6 +29,9 @@ namespace SM.Base.Drawing.Text
public float Width;
/// <summary>
/// Matrix for the texture.
/// </summary>
public Matrix3 TextureMatrix;
}
}

View file

@ -11,21 +11,45 @@ using SM.Base.Textures;
namespace SM.Base.Drawing.Text
{
/// <summary>
/// Represents a font to be used in DrawText-classes.
/// </summary>
public class Font : Texture
{
private static Library _lib;
private Face _fontFace;
/// <summary>
/// The amount the cursor should move forward when a space was found.
/// </summary>
public float SpaceWidth { get; private set; } = 0;
/// <summary>
/// The char set the font should contain.
/// <para>See <see cref="FontCharStorage"/> for some default values.</para>
/// <para>Default: <see cref="FontCharStorage.SimpleUTF8"/></para>
/// </summary>
public ICollection<char> CharSet { get; set; } = FontCharStorage.SimpleUTF8;
/// <summary>
/// The font-size defines how large the result texture should be.
/// <para>Lower equals less quality, but also less memory usage.</para>
/// <para>Higher equals high quality, but also high memory usage.</para>
/// <para>Default: 12</para>
/// </summary>
public float FontSize { get; set; } = 12;
/// <summary>
/// The character positions.
/// </summary>
public Dictionary<char, CharParameter> Positions = new Dictionary<char, CharParameter>();
/// <summary>
/// Creates a font, by using a path
/// </summary>
/// <param name="path">Path to the font-file.</param>
public Font(string path)
{
_lib ??= new Library();
@ -34,6 +58,9 @@ namespace SM.Base.Drawing.Text
UnpackAlignment = 1;
}
/// <summary>
/// (Re-)Generates the texture.
/// </summary>
public void RegenerateTexture()
{
Width = Height = 0;
@ -88,6 +115,7 @@ namespace SM.Base.Drawing.Text
}
}
/// <inheritdoc />
public override void Compile()
{
RegenerateTexture();

View file

@ -10,10 +10,22 @@ using SM.Base.Window;
namespace SM.Base.Drawing.Text
{
/// <summary>
/// Represents the options for <see cref="TextDrawingBasis{TTransform}.Origin"/>
/// </summary>
public enum TextOrigin
{
/// <summary>
/// The position equals (0,0) in the left side of the text.
/// </summary>
Left,
/// <summary>
/// The position equals (0,0) in the center of the text.
/// </summary>
Center,
/// <summary>
/// The position equals (0,0) in the right side of the text.
/// </summary>
Right
}

View file

@ -1,6 +1,8 @@
#region usings
using OpenTK;
using OpenTK.Graphics.ES10;
using SM.Base.Textures;
using SM.Base.Types;
#endregion
@ -34,6 +36,41 @@ namespace SM.Base.Drawing
return CalculateMatrix(Offset, Scale, Rotation);
}
/// <summary>
/// Sets the offset relative to the pixels of the texture.
/// </summary>
/// <param name="texture">The texture it should use.</param>
/// <param name="pixelLocation">The offset in pixel.</param>
public void SetOffsetRelative(Texture texture, Vector2 pixelLocation)
{
Vector2 textureSize = new Vector2(texture.Width, texture.Height);
Offset.Set( Vector2.Divide(pixelLocation, textureSize) );
}
/// <summary>
/// Sets the scale relative to the pixels of the texture.
/// </summary>
/// <param name="texture">The texture.</param>
/// <param name="rectangleSize">The scale in pixel.</param>
public void SetScaleRelative(Texture texture, Vector2 rectangleSize)
{
Vector2 textureSize = new Vector2(texture.Width, texture.Height);
Scale.Set( Vector2.Divide(rectangleSize, textureSize) );
}
/// <summary>
/// Sets the offset and scale relative to the pixels of the texture.
/// </summary>
/// <param name="texture">The texture.</param>
/// <param name="location">Offset in pixel</param>
/// <param name="rectangleSize">Scale in pixel.</param>
public void SetRectangleRelative(Texture texture, Vector2 location, Vector2 rectangleSize)
{
Vector2 textureSize = new Vector2(texture.Width, texture.Height);
Offset.Set(Vector2.Divide(location, textureSize));
Scale.Set(Vector2.Divide(rectangleSize, textureSize));
}
/// <summary>
/// Calculates a texture matrix.
/// </summary>