diff --git a/SMCode/SM.Base/Drawing/DrawingBasis.cs b/SMCode/SM.Base/Drawing/DrawingBasis.cs
index 7aa9180..144c9c8 100644
--- a/SMCode/SM.Base/Drawing/DrawingBasis.cs
+++ b/SMCode/SM.Base/Drawing/DrawingBasis.cs
@@ -18,17 +18,17 @@ namespace SM.Base.Drawing
///
/// The camera, that was used last time the object was rendered.
///
- public GenericCamera LastDrawingCamera;
+ public GenericCamera LastDrawingCamera { get; private set; }
///
/// The material it should use.
///
- public Material Material = new Material();
+ public Material Material { get; set; } = new Material();
///
/// Transformation for the textures.
///
- public TextureTransformation TextureTransform = new TextureTransformation();
+ public TextureTransformation TextureTransform { get; set; } = new TextureTransformation();
///
/// This allows custom shaders to add own arguments.
@@ -71,7 +71,6 @@ namespace SM.Base.Drawing
DrawContext(ref context);
}
-
///
public virtual void OnAdded(object sender)
{
diff --git a/SMCode/SM.Base/Drawing/Text/CharParameter.cs b/SMCode/SM.Base/Drawing/Text/CharParameter.cs
index aec2380..8a1026b 100644
--- a/SMCode/SM.Base/Drawing/Text/CharParameter.cs
+++ b/SMCode/SM.Base/Drawing/Text/CharParameter.cs
@@ -18,6 +18,9 @@ namespace SM.Base.Drawing.Text
///
public int Advance;
+ ///
+ /// The bearing for this char.
+ ///
public float BearingX;
///
@@ -26,6 +29,9 @@ namespace SM.Base.Drawing.Text
public float Width;
+ ///
+ /// Matrix for the texture.
+ ///
public Matrix3 TextureMatrix;
}
}
\ 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 e49fdbb..f9c9667 100644
--- a/SMCode/SM.Base/Drawing/Text/Font.cs
+++ b/SMCode/SM.Base/Drawing/Text/Font.cs
@@ -11,21 +11,45 @@ using SM.Base.Textures;
namespace SM.Base.Drawing.Text
{
+ ///
+ /// Represents a font to be used in DrawText-classes.
+ ///
public class Font : Texture
{
private static Library _lib;
private Face _fontFace;
+ ///
+ /// The amount the cursor should move forward when a space was found.
+ ///
public float SpaceWidth { get; private set; } = 0;
+ ///
+ /// The char set the font should contain.
+ /// See for some default values.
+ /// Default:
+ ///
public ICollection CharSet { get; set; } = FontCharStorage.SimpleUTF8;
+ ///
+ /// The font-size defines how large the result texture should be.
+ /// Lower equals less quality, but also less memory usage.
+ /// Higher equals high quality, but also high memory usage.
+ /// Default: 12
+ ///
public float FontSize { get; set; } = 12;
+ ///
+ /// The character positions.
+ ///
public Dictionary Positions = new Dictionary();
+ ///
+ /// Creates a font, by using a path
+ ///
+ /// Path to the font-file.
public Font(string path)
{
_lib ??= new Library();
@@ -34,6 +58,9 @@ namespace SM.Base.Drawing.Text
UnpackAlignment = 1;
}
+ ///
+ /// (Re-)Generates the texture.
+ ///
public void RegenerateTexture()
{
Width = Height = 0;
@@ -88,6 +115,7 @@ namespace SM.Base.Drawing.Text
}
}
+ ///
public override void Compile()
{
RegenerateTexture();
diff --git a/SMCode/SM.Base/Drawing/Text/TextDrawingBasis.cs b/SMCode/SM.Base/Drawing/Text/TextDrawingBasis.cs
index cb07159..206a63c 100644
--- a/SMCode/SM.Base/Drawing/Text/TextDrawingBasis.cs
+++ b/SMCode/SM.Base/Drawing/Text/TextDrawingBasis.cs
@@ -10,10 +10,22 @@ using SM.Base.Window;
namespace SM.Base.Drawing.Text
{
+ ///
+ /// Represents the options for
+ ///
public enum TextOrigin
{
+ ///
+ /// The position equals (0,0) in the left side of the text.
+ ///
Left,
+ ///
+ /// The position equals (0,0) in the center of the text.
+ ///
Center,
+ ///
+ /// The position equals (0,0) in the right side of the text.
+ ///
Right
}
diff --git a/SMCode/SM.Base/Drawing/TextureTransformation.cs b/SMCode/SM.Base/Drawing/TextureTransformation.cs
index d20d6de..8f08600 100644
--- a/SMCode/SM.Base/Drawing/TextureTransformation.cs
+++ b/SMCode/SM.Base/Drawing/TextureTransformation.cs
@@ -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);
}
+ ///
+ /// Sets the offset relative to the pixels of the texture.
+ ///
+ /// The texture it should use.
+ /// The offset in pixel.
+ public void SetOffsetRelative(Texture texture, Vector2 pixelLocation)
+ {
+ Vector2 textureSize = new Vector2(texture.Width, texture.Height);
+ Offset.Set( Vector2.Divide(pixelLocation, textureSize) );
+ }
+ ///
+ /// Sets the scale relative to the pixels of the texture.
+ ///
+ /// The texture.
+ /// The scale in pixel.
+ public void SetScaleRelative(Texture texture, Vector2 rectangleSize)
+ {
+ Vector2 textureSize = new Vector2(texture.Width, texture.Height);
+ Scale.Set( Vector2.Divide(rectangleSize, textureSize) );
+ }
+
+ ///
+ /// Sets the offset and scale relative to the pixels of the texture.
+ ///
+ /// The texture.
+ /// Offset in pixel
+ /// Scale in pixel.
+ 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));
+ }
+
///
/// Calculates a texture matrix.
///
diff --git a/SMCode/SM.Base/Textures/Texture.cs b/SMCode/SM.Base/Textures/Texture.cs
index d3fa7a5..9d6080f 100644
--- a/SMCode/SM.Base/Textures/Texture.cs
+++ b/SMCode/SM.Base/Textures/Texture.cs
@@ -33,6 +33,9 @@ namespace SM.Base.Textures
private int? _height;
private int? _width;
+ ///
+ /// The unpack alignment for this texture.
+ ///
public int UnpackAlignment = 4;
///
@@ -120,6 +123,7 @@ namespace SM.Base.Textures
/// The filter
/// The wrap mode
/// Auto dispose of the bitmap? Default: false
+ /// The unpack alignment for this texture.
///
public static int GenerateTexture(Bitmap map, TextureMinFilter filter, TextureWrapMode wrapMode,
bool dispose = false, int unpackAlignment = 4)
diff --git a/SMCode/SM.Base/Window/GLWindow.cs b/SMCode/SM.Base/Window/GLWindow.cs
index 51b9016..d82d2e3 100644
--- a/SMCode/SM.Base/Window/GLWindow.cs
+++ b/SMCode/SM.Base/Window/GLWindow.cs
@@ -143,6 +143,9 @@ namespace SM.Base.Window
}
}
+ ///
+ /// This gets called, when the window completed with all initilization steps.
+ ///
protected virtual void OnLoaded()
{
Icon ??= new Icon(AssemblyUtility.GetAssemblyStream("SM.Base.Window.winIcon.ico"));
diff --git a/SMCode/SM2D/Drawing/DrawText.cs b/SMCode/SM2D/Drawing/DrawText.cs
index b65465c..3708e5c 100644
--- a/SMCode/SM2D/Drawing/DrawText.cs
+++ b/SMCode/SM2D/Drawing/DrawText.cs
@@ -23,6 +23,10 @@ namespace SM2D.Drawing
Transform.Size = new CVector2(1);
}
+ ///
+ /// Sets the height of the text.
+ ///
+ /// The height it should be.
public void SetHeight(float desiredHeight)
{
if (!Font.WasCompiled) Font.Compile();
diff --git a/SMCode/SM2D/Types/Transformation.cs b/SMCode/SM2D/Types/Transformation.cs
index 31fa815..af6b564 100644
--- a/SMCode/SM2D/Types/Transformation.cs
+++ b/SMCode/SM2D/Types/Transformation.cs
@@ -54,9 +54,7 @@ namespace SM2D.Types
{
float z = 1 / (float) ZIndexPercision * ZIndex;
- return Matrix4.CreateScale(Size.X, Size.Y, 1) *
- Matrix4.CreateRotationX(MathHelper.DegreesToRadians(HorizontalFlip ? 180 : 0)) *
- Matrix4.CreateRotationY(MathHelper.DegreesToRadians(VerticalFlip ? 180 : 0)) *
+ return Matrix4.CreateScale(Size.X * (VerticalFlip ? -1 : 1), Size.Y * (HorizontalFlip ? -1 : 1), 1) *
Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(Rotation)) *
Matrix4.CreateTranslation(Position.X, Position.Y, z);
}
@@ -100,5 +98,15 @@ namespace SM2D.Types
{
Size.Set(width, width / texture.Aspect);
}
+
+ ///
+ /// Adjusts for the texture transform.
+ /// In this way you can make sure, the texture is not stretched.
+ ///
+ ///
+ public void AdjustSizeToTextureTransform(TextureTransformation transform)
+ {
+ Size.Set(transform.Scale * Size);
+ }
}
}
\ No newline at end of file
diff --git a/SM_TEST/Program.cs b/SM_TEST/Program.cs
index f9bc283..940dcf7 100644
--- a/SM_TEST/Program.cs
+++ b/SM_TEST/Program.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
+using System.Drawing;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
@@ -8,13 +9,13 @@ using SM.Base;
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;
using SM2D;
using SM2D.Drawing;
using SM2D.Object;
using SM2D.Scene;
+using Font = SM.Base.Drawing.Text.Font;
namespace SM_TEST
{
@@ -34,8 +35,6 @@ namespace SM_TEST
};
font.RegenerateTexture();
- SMRenderer.DefaultMesh = new Polygon(new[] { new Vector2(0, 0), new Vector2(0, 1), new Vector2(1, 1), new Vector2(1, 0) });
-
window = new GLWindow(1280, 720, "0ms", WindowFlags.Window, VSyncMode.Off);
window.ApplySetup(new Window2DSetup());
@@ -49,19 +48,14 @@ namespace SM_TEST
};
- Material uvMaterial = new Material()
+ DrawObject2D test = new DrawObject2D()
{
- Tint = new Color4(1f, 0, 0, .5f),
- Blending = true,
- Texture = font
+ Texture = new Bitmap("test.png")
};
-
- DrawText test = new DrawText(font, "Level Completed")
- {
- Material = uvMaterial,
- };
- test.Transform.Position.Set(0, 2);
- test.Transform.Size.Set(.5f);
+ test.Material.Blending = true;
+ test.Transform.Size.Set(100);
+ test.TextureTransform.SetRectangleRelative(test.Texture, new Vector2(234, 0), new Vector2(220, 201));
+ test.Transform.AdjustSizeToTextureTransform(test.TextureTransform);
scene.Objects.Add(test);