Files
Voile/DaggerFramework/Source/SceneGraph/Entities/Text2d.cs

45 lines
1.2 KiB
C#

using DaggerFramework.Rendering;
using System.Drawing;
namespace DaggerFramework.SceneGraph
{
public class Text2d : Drawable2d
{
public string Text { get => _text; set => _text = value; }
public int FontSize { get => _fontSize; set => _fontSize = value; }
public Color FontColor { get => _fontColor; set => _fontColor = value; }
public Font Font
{
get => _font; set
{
_isDirty = true;
_font = value;
}
}
public override void OnDraw(Renderer renderer)
{
if (_isDirty)
{
_fontHandle = renderer.LoadFont(_font);
_isDirty = false;
}
if (_font == null)
{
renderer.DrawDebugText(_text, _fontSize, _fontColor);
}
else
{
renderer.DrawText(_fontHandle, _text, _fontSize, _fontColor);
}
}
private string _text = string.Empty;
private int _fontSize = 16;
private Color _fontColor = Color.White;
private Font _font;
private int _fontHandle;
private bool _isDirty;
}
}