mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-06 05:01:53 +00:00
Start of text renderer component
- UC, LC, IC, RC tags
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
namespace GlitchyEngine.World.Components;
|
||||
|
||||
struct TextRendererComponent : IDisposableComponent
|
||||
{
|
||||
private String _text;
|
||||
|
||||
private bool _isRichText;
|
||||
|
||||
public StringView Text
|
||||
{
|
||||
get => _text;
|
||||
set mut
|
||||
{
|
||||
if (_text == null)
|
||||
_text = new String();
|
||||
|
||||
_text.Set(value);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsRichText
|
||||
{
|
||||
get => _isRichText;
|
||||
set mut => _isRichText = value;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
delete _text;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using GlitchyEngine.Content;
|
||||
using GlitchyEngine.Math;
|
||||
using System;
|
||||
using GlitchyEngine.World.Components;
|
||||
using GlitchyEngine.Renderer.Text;
|
||||
|
||||
namespace GlitchyEngine.World;
|
||||
|
||||
@@ -24,6 +25,10 @@ class SceneRenderer
|
||||
|
||||
public RenderTargetGroup CompositeTarget => _compositeTarget;
|
||||
|
||||
Font _font ~ _.ReleaseRef();
|
||||
|
||||
FontRenderer.PreparedText _smallLinesInfo;
|
||||
|
||||
public this()
|
||||
{
|
||||
RenderTargetGroupDescription desc = .(100, 100,
|
||||
@@ -47,6 +52,8 @@ class SceneRenderer
|
||||
_cameraTarget.[Friend]Identifier = "Camera Target";
|
||||
|
||||
_gammaCorrectEffect = Content.LoadAsset("Resources/Shaders/GammaCorrect.hlsl");
|
||||
|
||||
_font = new Font(@"C:\Windows\Fonts\arial.ttf", 24);
|
||||
}
|
||||
|
||||
/// Sets the size of the viewport into which the scene will be rendered.
|
||||
@@ -204,6 +211,20 @@ class SceneRenderer
|
||||
|
||||
Renderer2D.DrawCircle(transform.WorldTransform, circle, entity.Index);
|
||||
}
|
||||
|
||||
for (var (entity, transform, text, editorFlags) in Scene._ecsWorld.Enumerate<TransformComponent, TextRendererComponent, EditorFlagsComponent>())
|
||||
{
|
||||
if (editorFlags.Flags.HasFlag(.HideInScene))
|
||||
continue;
|
||||
|
||||
_smallLinesInfo = FontRenderer.PrepareText(_font, text.Text, 24, .Black);
|
||||
|
||||
FontRenderer.DrawText(_smallLinesInfo, transform.WorldTransform * Matrix.Scaling(1.0f / 24.0f));
|
||||
|
||||
_smallLinesInfo.ReleaseRef();
|
||||
}
|
||||
|
||||
//FontRenderer.DrawText(_smallLinesInfo, 0, 0);
|
||||
|
||||
Renderer2D.EndScene();
|
||||
|
||||
|
||||
@@ -249,6 +249,12 @@ class SceneSerializer
|
||||
{
|
||||
Serialize.Value(writer, "Flags", component.Flags);
|
||||
});
|
||||
|
||||
SerializeComponent<TextRendererComponent>(writer, entity, "TextRenderer", scope (component) =>
|
||||
{
|
||||
Serialize.Value(writer, "IsRichText", component.IsRichText);
|
||||
Serialize.Value(writer, "Text", component.Text);
|
||||
});
|
||||
}
|
||||
|
||||
writer.EntryEnd();
|
||||
@@ -671,6 +677,27 @@ class SceneSerializer
|
||||
{
|
||||
Try!(Deserialize.Value(reader, "Flags", out component.Flags));
|
||||
|
||||
return .Ok;
|
||||
}));
|
||||
case "TextRenderer":
|
||||
Try!(DeserializeComponent<TextRendererComponent>(reader, entity, scope (component) =>
|
||||
{
|
||||
Try!(Deserialize.Value<bool>(reader, "IsRichText", let isRichText));
|
||||
component.IsRichText = isRichText;
|
||||
|
||||
Try!(reader.EntryEnd());
|
||||
|
||||
String text = null;
|
||||
|
||||
Try!(Deserialize.Value<String>(reader, "Text", out text));
|
||||
|
||||
if (text != null)
|
||||
{
|
||||
component.Text = text;
|
||||
|
||||
delete text;
|
||||
}
|
||||
|
||||
return .Ok;
|
||||
}));
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user