Skip to content

Commit

Permalink
Xml comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikasoukhov committed Feb 18, 2025
1 parent bf0d6ce commit e6646ce
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Drawing/Brush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,57 @@

using Ecng.Common;

/// <summary>
/// Represents a base class for drawing brushes.
/// </summary>
public abstract class Brush
{
/// <summary>
/// Initializes a new instance of the <see cref="Brush"/> class.
/// </summary>
protected Brush()
{
}
}

/// <summary>
/// Represents a brush that paints a solid color.
/// </summary>
/// <param name="color">The solid color to use for painting.</param>
public class SolidBrush(Color color) : Brush
{
/// <summary>
/// Gets the solid <see cref="Color"/> used by the brush.
/// </summary>
public Color Color { get; } = color;
}

/// <summary>
/// Represents a brush that paints a gradient between multiple colors.
/// </summary>
/// <param name="linearColors">An array of colors defining the gradient stops.</param>
/// <param name="rectangle">The rectangle that defines the bounds of the gradient.</param>
public class LinearGradientBrush(Color[] linearColors, Rectangle rectangle) : Brush
{
/// <summary>
/// Initializes a new instance of the <see cref="LinearGradientBrush"/> class using two points and two colors.
/// </summary>
/// <param name="stop0">The first point of the gradient.</param>
/// <param name="stop1">The second point of the gradient.</param>
/// <param name="color0">The color at the first point.</param>
/// <param name="color1">The color at the second point.</param>
public LinearGradientBrush(Point stop0, Point stop1, Color color0, Color color1)
: this([color0, color1], new(stop0, new((stop1.X - stop0.X).Abs(), (stop1.Y - stop0.Y).Abs())))
{
}

/// <summary>
/// Gets the array of colors defining the gradient stops.
/// </summary>
public Color[] LinearColors { get; } = linearColors ?? throw new ArgumentNullException(nameof(linearColors));

/// <summary>
/// Gets the rectangle that defines the bounds of the gradient.
/// </summary>
public Rectangle Rectangle { get; } = rectangle;
}
20 changes: 20 additions & 0 deletions Drawing/DrawingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,26 @@
#endif
using System.Drawing;

/// <summary>
/// Provides extension methods for converting between integer, HTML color string representations and <see cref="Color"/>.
/// </summary>
public static class DrawingExtensions
{
/// <summary>
/// Creates a Color from the specified ARGB integer.
/// </summary>
/// <param name="argb">An integer representing the ARGB value.</param>
/// <returns>A <see cref="Color"/> corresponding to the ARGB value specified.</returns>
public static Color ToColor(this int argb)
=> Color.FromArgb(argb);

/// <summary>
/// Converts an HTML color representation to a <see cref="Color"/>.
/// </summary>
/// <param name="htmlColor">
/// A string representing the HTML color. Accepts formats such as "#RRGGBB", "#RGB" or the special case "LightGrey".
/// </param>
/// <returns>A <see cref="Color"/> corresponding to the HTML color provided.</returns>
public static Color ToColor(this string htmlColor)
{
#if NETSTANDARD2_0
Expand Down Expand Up @@ -77,6 +92,11 @@ public static Color ToColor(this string htmlColor)
#endif
}

/// <summary>
/// Converts a <see cref="Color"/> to its HTML representation.
/// </summary>
/// <param name="color">The <see cref="Color"/> to convert.</param>
/// <returns>A string representing the HTML color value. Returns an empty string if the color is empty.</returns>
public static string ToHtml(this Color color)
{
#if NETSTANDARD2_0
Expand Down

0 comments on commit e6646ce

Please sign in to comment.