using System; using Azimuth; using Blacklight.Core; using Blacklight.Core.Drawables; using Prism; namespace Konis.Testbed { /// /// A ring on the ground around the selected emitter. It is a dark ring under a light one, so it shows on every /// backdrop. /// public class SelectionMarker { /// /// The ring's radius on the ground, in world units. A click this close to an emitter picks it. /// public const double Radius = 36; private static readonly Color Clear = Color.FromArgb(0, 0, 0, 0); private readonly Ellipse shadow = new Ellipse { InsideColor = Clear, ShellColor = Color.FromArgb(255, 0, 0, 0), ShellPixelThickness = 4, }; private readonly Ellipse ring = new Ellipse { InsideColor = Clear, ShellColor = Color.FromArgb(255, 255, 255, 255), ShellPixelThickness = 2, }; private ViewProjection projection; private Vector size; public SelectionMarker(ViewProjection projection) { Projection = projection; } /// /// Gets or sets how the ground lands on the screen. /// public ViewProjection Projection { get { return projection; } set { projection = value; // A ground circle seen through a turn and a squash is an ellipse lined up with the screen, and its // reach on each axis is the length of that row of the projection. Vector east = projection.Project(new Vector3(1, 0, 0)); Vector north = projection.Project(new Vector3(0, 1, 0)); size = new Vector( 2 * Radius * Math.Sqrt(east.X * east.X + north.X * north.X), 2 * Radius * Math.Sqrt(east.Y * east.Y + north.Y * north.Y)); } } /// /// Adds the ring around to . /// public void Draw(Cel cel, Vector3 position) { AffineMatrix placement = Ellipse.ModelToWorld(size, position: projection.Project(position)); cel.AddEntity(shadow, placement); cel.AddEntity(ring, placement); } } }