Struct Brush
- Namespace
- Northwoods.Go
- Assembly
- Northwoods.GoDiagram.Avalonia.dll
A Brush holds color information and describes how to draw the inside of a Shape or the stroke of a shape or a TextBlock or the background of any GraphObject.
[TypeConverter(typeof(BrushTypeConverter))]
[JsonConverter(typeof(BrushJsonConverter))]
public struct Brush
- Inherited Members
Remarks
A Brush contains a Paint which describes how the color(s) will be drawn.
Constructors
Brush(Paint)
Constructs a Brush with the given Paint.
public Brush(Paint paint)
Parameters
paintPaintthe Paint for this Brush
Brush(string)
Constructs a Brush with a SolidPaint.
public Brush(string color)
Parameters
colorstringa color string
Brush(string, (float, string)[])
Constructs a Brush with a GradientPaint.
public Brush(string painttype, (float, string)[] stops)
Parameters
painttypestringa gradient paint type, either "linear" or "radial"
stops(float, string)[]an array of tuples mapping fractional stops to color strings
Properties
Paint
This read-only property returns the Paint this Brush uses for drawing.
public readonly Paint Paint { get; }
Property Value
Methods
Darken(double, ColorSpace)
Modifies all colors within this Brush, darkening them by some fraction.
public Brush Darken(double fraction = 0.2, ColorSpace mode = ColorSpace.Lab)
Parameters
fractiondoubleFraction to darken the colors by. Defaults to 0.2, must be between 0 and 1 (inclusive).
modeColorSpaceColor space to use for adjusting. Must be Lab or HSL, defaults to Lab.
Returns
- Brush
A new Brush with modified color values.
Darken(object)
This is a convenience method for Darken(string, double, ColorSpace) that can be used as a Converter.
public static object Darken(object color)
Parameters
colorobject
Returns
Darken(string, double, ColorSpace)
This static function takes a color and darkens it.
public static string Darken(string color, double fraction = 0.2, ColorSpace mode = ColorSpace.Lab)
Parameters
colorstringA valid color string
fractiondoubleFraction to darken the color by. Defaults to 0.2, must be between 0 and 1 (inclusive).
modeColorSpaceColor space to use for adjusting. Must be Lab or HSL, defaults to Lab.
Returns
- string
A string for the darkened color in RGBA or HSLA.
Equals(object)
Indicates whether the given Brush is equal to this Brush.
public override bool Equals(object obj)
Parameters
objobjectThe Brush to compare to the current Brush.
Returns
- bool
True if the two Brushes have identical Color and Paint values, false otherwise.
GetHashCode()
Creates a hash code for the Brush.
public override int GetHashCode()
Returns
- int
A hash code for the current Brush structure.
IsDark()
Determines whether this Brush is "dark."
public bool IsDark()
Returns
IsDark(string)
This static function takes a color and determines whether it is "dark." Does not account for transparency.
public static bool IsDark(string color)
Parameters
colorstringA valid color string
Returns
Examples
myDiagram.NodeTemplate =
new Node("Auto")
.Add(
new Shape { Figure = "RoundedRectangle", StrokeWidth = 0 }
.Bind("Fill", "Color"),
new TextBlock { Margin = 8 }
.Bind("Stroke", "ColorStr", (c, _) => {
// Dark nodes use white text, light nodes use black text
return Brush.IsDark((string)c) ? "white" : "black";
})
.Bind("Text", "Key")
);
IsValidColor(string)
This static function returns true if a given color string is well-formed for drawing.
public static bool IsValidColor(string color)
Parameters
colorstringA color string to validate.
Returns
Lighten(double, ColorSpace)
Modifies all colors within this Brush, lightening them by some fraction.
public Brush Lighten(double fraction = 0.2, ColorSpace mode = ColorSpace.Lab)
Parameters
fractiondoubleFraction to lighten the colors by. Defaults to 0.2, must be between 0 and 1 (inclusive).
modeColorSpaceColor space to use for adjusting. Must be Lab or HSL, defaults to Lab.
Returns
- Brush
A new Brush with modified color values.
Lighten(object)
This is a convenience method for Lighten(string, double, ColorSpace) that can be used as a Converter.
public static object Lighten(object color)
Parameters
colorobject
Returns
Lighten(string, double, ColorSpace)
This static function takes a color and lightens it.
public static string Lighten(string color, double fraction = 0.2, ColorSpace mode = ColorSpace.Lab)
Parameters
colorstringA valid color string.
fractiondoubleFraction to lighten the colors by. Defaults to 0.2, must be between 0 and 1 (inclusive).
modeColorSpaceColor space to use for adjusting. Must be Lab or HSL, defaults to Lab.
Returns
- string
A string for the lightened color in RGBA or HSLA.
Mix(string, string, double)
This static function takes two colors and mixes them together, using the (optionally) specified amount of the second color.
public static string Mix(string color1, string color2, double fraction = 0.5)
Parameters
color1stringA valid color string.
color2stringAnother valid color string to mix.
fractiondoubleFraction specifying how much color2 to mix into color1. Defaults to .5, must be between 0 and 1 (inclusive).
Returns
RandomColor(int, int)
This static function can be used to generate a random color.
public static string RandomColor(int min = 128, int max = 255)
Parameters
minintAn int between 0 and 255, defaults to 128.
maxintAn int between 0 and 255, defaults to 255.
Returns
- string
A color value in # hexadecimal format.
ToString()
Returns a string representation of the Brush.
public override string ToString()
Returns
- string
A string representation of the current Brush.
Operators
operator ==(Brush, Brush)
Compares if two Brushes are equal by checking their Paints.
public static bool operator ==(Brush left, Brush right)
Parameters
Returns
implicit operator Brush(string)
Implicitly converts a string to a Brush.
public static implicit operator Brush(string c)
Parameters
cstring
Returns
operator !=(Brush, Brush)
Compares if two Brushes are not equal by checking their Paints.
public static bool operator !=(Brush left, Brush right)