mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-06 05:01:53 +00:00
Slightly improved text renderer
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using GlitchyEngine.Math;
|
||||
using static GlitchyEngine.Renderer.Text.FontRenderer;
|
||||
namespace GlitchyEngine.World.Components;
|
||||
|
||||
@@ -14,6 +15,12 @@ struct TextRendererComponent : IDisposableComponent, ICopyComponent<TextRenderer
|
||||
|
||||
private PreparedText _preparedText;
|
||||
|
||||
public float FontSize = 1.0f;
|
||||
|
||||
public ColorRGBA Color = ColorRGBA.White;
|
||||
|
||||
public HorizontalTextAlignment HorizontalAlignment = .Left;
|
||||
|
||||
private TextRendererFlags _flags;
|
||||
|
||||
public StringView Text
|
||||
@@ -56,6 +63,9 @@ struct TextRendererComponent : IDisposableComponent, ICopyComponent<TextRenderer
|
||||
{
|
||||
target.Text = source.Text;
|
||||
|
||||
target.FontSize = source.FontSize;
|
||||
target.Color = source.Color;
|
||||
target.HorizontalAlignment = source.HorizontalAlignment;
|
||||
target._flags = source._flags;
|
||||
target.NeedsRebuild = true;
|
||||
}
|
||||
|
||||
@@ -800,20 +800,7 @@ namespace GlitchyEngine.World
|
||||
{
|
||||
if (textRenderer.NeedsRebuild || textRenderer.PreparedText == null)
|
||||
{
|
||||
if (textRenderer.PreparedText == null)
|
||||
{
|
||||
textRenderer.PreparedText = new FontRenderer.PreparedText(_font);
|
||||
}
|
||||
else
|
||||
{
|
||||
textRenderer.PreparedText.AddRef();
|
||||
}
|
||||
|
||||
FontRenderer.PrepareText(textRenderer.PreparedText, _font, textRenderer.Text, 24, .Black);
|
||||
|
||||
textRenderer.PreparedText.ReleaseRef();
|
||||
|
||||
textRenderer.NeedsRebuild = false;
|
||||
FontRenderer.PrepareText(textRenderer, _font);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ class SceneRenderer
|
||||
if (editorFlags.Flags.HasFlag(.HideInScene) || text.PreparedText == null)
|
||||
continue;
|
||||
|
||||
FontRenderer.DrawText(text.PreparedText, transform.WorldTransform * Matrix.Scaling(1.0f / 24.0f));
|
||||
FontRenderer.DrawText(text.PreparedText, transform.WorldTransform, text.Color);
|
||||
}
|
||||
|
||||
Renderer2D.EndScene();
|
||||
@@ -225,7 +225,7 @@ class SceneRenderer
|
||||
if (editorFlags.Flags.HasFlag(.HideInScene) || text.PreparedText == null)
|
||||
continue;
|
||||
|
||||
FontRenderer.DrawText(text.PreparedText, transform.WorldTransform * Matrix.Scaling(1.0f / 24.0f));
|
||||
FontRenderer.DrawText(text.PreparedText, transform.WorldTransform, text.Color);
|
||||
}
|
||||
|
||||
//FontRenderer.DrawText(_smallLinesInfo, 0, 0);
|
||||
|
||||
@@ -279,6 +279,9 @@ class SceneSerializer
|
||||
{
|
||||
Serialize.Value(writer, "IsRichText", component.IsRichText);
|
||||
Serialize.Value(writer, "Text", component.Text);
|
||||
Serialize.Value(writer, "Color", component.Color);
|
||||
Serialize.Value(writer, "FontSize", component.FontSize);
|
||||
Serialize.Value(writer, "HorizontalAlignment", component.HorizontalAlignment);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -765,6 +768,12 @@ class SceneSerializer
|
||||
Try!(Deserialize.Value<String>(reader, let text));
|
||||
component.Text = text;
|
||||
delete text;
|
||||
case "Color":
|
||||
Try!(Deserialize.Value(reader, out component.Color));
|
||||
case "FontSize":
|
||||
Try!(Deserialize.Value(reader, out component.FontSize));
|
||||
case "HorizontalAlignment":
|
||||
Try!(Deserialize.Value(reader, out component.HorizontalAlignment));
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user