73 lines
2.2 KiB
C#
73 lines
2.2 KiB
C#
|
using System.Collections.Generic;
|
|||
|
using System.Collections.Immutable;
|
|||
|
using System.Linq;
|
|||
|
using System.Numerics;
|
|||
|
|
|||
|
namespace Dashboard.Drawing
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Interface for all drawing extensions.
|
|||
|
/// </summary>
|
|||
|
public interface IDrawExtension
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Name of this extension.
|
|||
|
/// </summary>
|
|||
|
public string Name { get; }
|
|||
|
|
|||
|
public IReadOnlyList<IDrawExtension> Requires { get; }
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// The list of commands this extension defines, if any.
|
|||
|
/// </summary>
|
|||
|
public IReadOnlyList<IDrawCommand> Commands { get; }
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// A simple draw extension.
|
|||
|
/// </summary>
|
|||
|
public class DrawExtension : IDrawExtension
|
|||
|
{
|
|||
|
private readonly List<IDrawCommand> _drawCommands = new List<IDrawCommand>();
|
|||
|
|
|||
|
public string Name { get; }
|
|||
|
|
|||
|
public IReadOnlyList<IDrawCommand> Commands { get; }
|
|||
|
|
|||
|
public IReadOnlyList<IDrawExtension> Requires { get; }
|
|||
|
|
|||
|
public DrawExtension(string name, IEnumerable<IDrawExtension>? requires = null)
|
|||
|
{
|
|||
|
Name = name;
|
|||
|
Commands = _drawCommands.AsReadOnly();
|
|||
|
Requires = (requires ?? Enumerable.Empty<IDrawExtension>()).ToImmutableList();
|
|||
|
}
|
|||
|
|
|||
|
protected void AddCommand(IDrawCommand command)
|
|||
|
{
|
|||
|
_drawCommands.Add(command);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public static class DrawExtensionClass
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Get the draw controller for the given queue.
|
|||
|
/// </summary>
|
|||
|
/// <param name="extension">The extension instance.</param>
|
|||
|
/// <param name="queue">The draw queue.</param>
|
|||
|
/// <returns>The draw controller for this queue.</returns>
|
|||
|
public static IDrawController GetController(this IDrawExtension extension, DrawQueue queue)
|
|||
|
{
|
|||
|
return queue.GetController(extension);
|
|||
|
}
|
|||
|
|
|||
|
public static void Point(this DrawQueue queue, Vector3 position, float size, IBrush brush)
|
|||
|
{
|
|||
|
var controller = queue.GetController(DbBaseCommands.Instance);
|
|||
|
controller.EnsureSize(position);
|
|||
|
controller.Write(DbBaseCommands.Instance.DrawPoint, new PointCommandArgs(position, size, brush));
|
|||
|
}
|
|||
|
}
|
|||
|
}
|