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:
parent
a29a2cab53
commit
f11a954b5a
10 changed files with 116 additions and 21 deletions
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -33,6 +33,9 @@ namespace SM.Base.Textures
|
|||
private int? _height;
|
||||
private int? _width;
|
||||
|
||||
/// <summary>
|
||||
/// The unpack alignment for this texture.
|
||||
/// </summary>
|
||||
public int UnpackAlignment = 4;
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -120,6 +123,7 @@ namespace SM.Base.Textures
|
|||
/// <param name="filter">The filter</param>
|
||||
/// <param name="wrapMode">The wrap mode</param>
|
||||
/// <param name="dispose">Auto dispose of the bitmap? Default: false</param>
|
||||
/// <param name="unpackAlignment">The unpack alignment for this texture.</param>
|
||||
/// <returns></returns>
|
||||
public static int GenerateTexture(Bitmap map, TextureMinFilter filter, TextureWrapMode wrapMode,
|
||||
bool dispose = false, int unpackAlignment = 4)
|
||||
|
|
|
|||
|
|
@ -143,6 +143,9 @@ namespace SM.Base.Window
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This gets called, when the window completed with all initilization steps.
|
||||
/// </summary>
|
||||
protected virtual void OnLoaded()
|
||||
{
|
||||
Icon ??= new Icon(AssemblyUtility.GetAssemblyStream("SM.Base.Window.winIcon.ico"));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue