1234567891011121314151617181920212223242526272829303132333435 |
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Terminal.Gui.TextEffects;
- /// <summary>
- /// Implementation of <see cref="IFill"/> that uses a color gradient (including
- /// radial, diagonal etc).
- /// </summary>
- public class GradientFill : IFill
- {
- private Dictionary<Point, Terminal.Gui.Color> _map;
- public GradientFill (Rectangle area, Gradient gradient, Gradient.Direction direction)
- {
- _map =
- gradient.BuildCoordinateColorMapping (area.Height, area.Width, direction)
- .ToDictionary (
- (k) => new Point (k.Key.Column, k.Key.Row),
- (v) => new Terminal.Gui.Color (v.Value.R, v.Value.G, v.Value.B));
- }
- public Terminal.Gui.Color GetColor (Point point)
- {
- if (_map.TryGetValue (point, out var color))
- {
- return color;
- }
- return new Terminal.Gui.Color (0, 0, 0); // Default to black if point not found
- }
- }
|