using System.Collections.Generic; using System.Collections.Immutable; using System.Drawing; using System.Linq; using System.Numerics; namespace Dashboard.Drawing { /// /// Interface for all drawing extensions. /// public interface IDrawExtension { /// /// Name of this extension. /// public string Name { get; } public IReadOnlyList Requires { get; } /// /// The list of commands this extension defines, if any. /// public IReadOnlyList Commands { get; } } /// /// A simple draw extension. /// public class DrawExtension : IDrawExtension { private readonly List _drawCommands = new List(); public string Name { get; } public IReadOnlyList Commands { get; } public IReadOnlyList Requires { get; } public DrawExtension(string name, IEnumerable? requires = null) { Name = name; Commands = _drawCommands.AsReadOnly(); Requires = (requires ?? Enumerable.Empty()).ToImmutableList(); } protected void AddCommand(IDrawCommand command) { _drawCommands.Add(command); } } public static class DrawExtensionClass { /// /// Get the draw controller for the given queue. /// /// The extension instance. /// The draw queue. /// The draw controller for this queue. 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) { Vector3 radius = new Vector3(size / 2f); Box3d bounds = new Box3d(position - radius, position + radius); var controller = queue.GetController(DbBaseCommands.Instance); controller.EnsureBounds(bounds); controller.Write(DbBaseCommands.Instance.DrawPoint, new PointCommandArgs(position, size, brush)); } } }