// ReSharper disable MemberCanBePrivate.Global // ReSharper disable MemberCanBeProtected.Global // ReSharper disable ReturnTypeCanBeEnumerable.Global // ReSharper disable AutoPropertyCanBeMadeGetOnly.Global // ReSharper disable UnusedMember.Global using System; using RGB.NET.Brushes.Gradients; using RGB.NET.Core; namespace RGB.NET.Brushes { /// /// /// /// Represents a brush drawing a conical gradient. /// public class ConicalGradientBrush : AbstractBrush, IGradientBrush { #region Properties & Fields private float _origin = (float)Math.Atan2(-1, 0); /// /// Gets or sets the origin (radian-angle) this is drawn to. (default: -π/2) /// public float Origin { get => _origin; set => SetProperty(ref _origin, value); } private Point _center = new(0.5, 0.5); /// /// Gets or sets the center (as percentage in the range [0..1]) of the drawn by this . (default: 0.5, 0.5) /// public Point Center { get => _center; set => SetProperty(ref _center, value); } private IGradient? _gradient; /// /// /// Gets or sets the gradient drawn by the brush. If null it will default to full transparent. /// public IGradient? Gradient { get => _gradient; set => SetProperty(ref _gradient, value); } #endregion #region Constructors /// /// /// Initializes a new instance of the class. /// public ConicalGradientBrush() { } /// /// /// Initializes a new instance of the class. /// /// The drawn by this . public ConicalGradientBrush(IGradient gradient) { this.Gradient = gradient; } /// /// /// Initializes a new instance of the class. /// /// The center (as percentage in the range [0..1]). /// The drawn by this . public ConicalGradientBrush(Point center, IGradient gradient) { this.Center = center; this.Gradient = gradient; } /// /// /// Initializes a new instance of the class. /// /// The center (as percentage in the range [0..1]). /// The origin (radian-angle) the is drawn to. /// The drawn by this . public ConicalGradientBrush(Point center, float origin, IGradient gradient) { this.Center = center; this.Origin = origin; this.Gradient = gradient; } #endregion #region Methods /// protected override Color GetColorAtPoint(Rectangle rectangle, BrushRenderTarget renderTarget) { if (Gradient == null) return Color.Transparent; double centerX = rectangle.Size.Width * Center.X; double centerY = rectangle.Size.Height * Center.Y; double angle = Math.Atan2(renderTarget.Point.Y - centerY, renderTarget.Point.X - centerX) - Origin; if (angle < 0) angle += Math.PI * 2; double offset = angle / (Math.PI * 2); return Gradient.GetColor(offset); } #endregion } }