namespace Terminal.Gui; /// /// Implementation of that uses a color gradient (including /// radial, diagonal etc.). /// public class GradientFill : IFill { private readonly Dictionary _map; /// /// Creates a new instance of the class that can return /// color for any point in the given using the provided /// and . /// /// /// /// public GradientFill (Rectangle area, Gradient gradient, GradientDirection direction) { _map = gradient.BuildCoordinateColorMapping (area.Height - 1, area.Width - 1, direction) .ToDictionary ( kvp => new Point (kvp.Key.X + area.X, kvp.Key.Y + area.Y), kvp => kvp.Value); } /// /// Returns the color to use for the given or Black if it /// lies outside the prepared gradient area (see constructor). /// /// /// public Color GetColor (Point point) { if (_map.TryGetValue (point, out Color color)) { return color; } return new (0, 0); // Default to black if point not found } }