Slightly improved text renderer

This commit is contained in:
Simon Lübeß
2024-04-14 23:56:09 +02:00
parent 4d0617aff7
commit f30bcb2f89
10 changed files with 217 additions and 297 deletions
@@ -0,0 +1,20 @@
namespace GlitchyEngine.Graphics.Text;
/// <summary>
/// The horizontal alignment of text.
/// </summary>
public enum HorizontalTextAlignment : byte
{
/// <summary>
/// Aligns the text to the left.
/// </summary>
Left,
/// <summary>
/// Aligns the text to the right.
/// </summary>
Right,
/// <summary>
/// Aligns the text in the center.
/// </summary>
Center
}
@@ -1,7 +1,8 @@
using GlitchyEngine.Core;
using GlitchyEngine.Math;
using GlitchyEngine.Graphics;
namespace GlitchyEngine.Graphics;
namespace GlitchyEngine.Graphics.Text;
/// <summary>
/// Renders text.
@@ -30,6 +31,16 @@ public class TextRenderer : Component
}
set => ScriptGlue.TextRenderer_SetText(_uuid, value);
}
public float FontSize
{
get
{
ScriptGlue.TextRenderer_GetFontSize(_uuid, out float size);
return size;
}
set => ScriptGlue.TextRenderer_SetFontSize(_uuid, value);
}
/// <summary>
/// The color that will be used to render the text. This color can be overridden by rich text tags.
@@ -39,11 +50,20 @@ public class TextRenderer : Component
get
{
ScriptGlue.TextRenderer_GetColor(_uuid, out ColorRGBA color);
return color;
}
set => ScriptGlue.TextRenderer_SetColor(_uuid, value);
}
public HorizontalTextAlignment HorizontalAlignment
{
get
{
ScriptGlue.TextRenderer_GetHorizontalAlignment(_uuid, out HorizontalTextAlignment alignment);
return alignment;
}
set => ScriptGlue.TextRenderer_SetHorizontalAlignment(_uuid, value);
}
// TODO: PreparedText component
}
+13
View File
@@ -3,6 +3,7 @@ using System.Numerics;
using System.Runtime.CompilerServices;
using GlitchyEngine.Core;
using GlitchyEngine.Editor;
using GlitchyEngine.Graphics.Text;
using GlitchyEngine.Math;
using GlitchyEngine.Physics;
using GlitchyEngine.Serialization;
@@ -275,6 +276,18 @@ internal static class ScriptGlue
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void TextRenderer_SetColor(UUID entityId, ColorRGBA color);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void TextRenderer_GetHorizontalAlignment(UUID entityId, out HorizontalTextAlignment horizontalAlignment);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void TextRenderer_SetHorizontalAlignment(UUID entityId, HorizontalTextAlignment horizontalAlignment);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void TextRenderer_GetFontSize(UUID uuid, out float fontSize);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void TextRenderer_SetFontSize(UUID uuid, float fontSize);
#endregion
#region Math