Struct Brush
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.
Namespace: Northwoods.Go
Assembly: Northwoods.GoDiagram.WinForms.dll
Syntax
[TypeConverter(typeof(BrushTypeConverter))]
[JsonConverter(typeof(BrushJsonConverter))]
public struct Brush
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.
Declaration
public Brush(Paint paint)
Parameters
Type | Name | Description |
---|---|---|
Paint | paint | the Paint for this Brush |
Brush(string, (float, string)[])
Constructs a Brush with a GradientPaint.
Declaration
public Brush(string painttype, (float, string)[] stops)
Parameters
Type | Name | Description |
---|---|---|
string | painttype | a gradient paint type, either "linear" or "radial" |
(float, string)[] | stops | an array of tuples mapping fractional stops to color strings |
Brush(string)
Constructs a Brush with a SolidPaint.
Declaration
public Brush(string color)
Parameters
Type | Name | Description |
---|---|---|
string | color | a color string |
Properties
Paint
This read-only property returns the Paint this Brush uses for drawing.
Declaration
public readonly Paint Paint { get; }
Property Value
Type | Description |
---|---|
Paint |
Methods
Darken(double, ColorSpace)
Modifies all colors within this Brush, darkening them by some fraction.
Declaration
public Brush Darken(double fraction = 0.2, ColorSpace mode = ColorSpace.Lab)
Parameters
Type | Name | Description |
---|---|---|
double | fraction | Fraction to darken the colors by. Defaults to 0.2, must be between 0 and 1 (inclusive). |
ColorSpace | mode | Color space to use for adjusting. Must be Lab or HSL, defaults to Lab. |
Returns
Type | Description |
---|---|
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.
Declaration
public static object Darken(object color)
Parameters
Type | Name | Description |
---|---|---|
object | color |
Returns
Type | Description |
---|---|
object |
Darken(string, double, ColorSpace)
This static function takes a color and darkens it.
Declaration
public static string Darken(string color, double fraction = 0.2, ColorSpace mode = ColorSpace.Lab)
Parameters
Type | Name | Description |
---|---|---|
string | color | A valid color string |
double | fraction | Fraction to darken the color by. Defaults to 0.2, must be between 0 and 1 (inclusive). |
ColorSpace | mode | Color space to use for adjusting. Must be Lab or HSL, defaults to Lab. |
Returns
Type | Description |
---|---|
string | A string for the darkened color in RGBA or HSLA. |
Equals(object)
Indicates whether the given Brush is equal to this Brush.
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
object | obj | The Brush to compare to the current Brush. |
Returns
Type | Description |
---|---|
bool | True if the two Brushes have identical Color and Paint values, false otherwise. |
Overrides
GetHashCode()
Creates a hash code for the Brush.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int | A hash code for the current Brush structure. |
Overrides
IsDark()
Determines whether this Brush is "dark."
Declaration
public bool IsDark()
Returns
Type | Description |
---|---|
bool |
IsDark(string)
This static function takes a color and determines whether it is "dark." Does not account for transparency.
Declaration
public static bool IsDark(string color)
Parameters
Type | Name | Description |
---|---|---|
string | color | A valid color string |
Returns
Type | Description |
---|---|
bool |
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.
Declaration
public static bool IsValidColor(string color)
Parameters
Type | Name | Description |
---|---|---|
string | color | A color string to validate. |
Returns
Type | Description |
---|---|
bool |
Lighten(double, ColorSpace)
Modifies all colors within this Brush, lightening them by some fraction.
Declaration
public Brush Lighten(double fraction = 0.2, ColorSpace mode = ColorSpace.Lab)
Parameters
Type | Name | Description |
---|---|---|
double | fraction | Fraction to lighten the colors by. Defaults to 0.2, must be between 0 and 1 (inclusive). |
ColorSpace | mode | Color space to use for adjusting. Must be Lab or HSL, defaults to Lab. |
Returns
Type | Description |
---|---|
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.
Declaration
public static object Lighten(object color)
Parameters
Type | Name | Description |
---|---|---|
object | color |
Returns
Type | Description |
---|---|
object |
Lighten(string, double, ColorSpace)
This static function takes a color and lightens it.
Declaration
public static string Lighten(string color, double fraction = 0.2, ColorSpace mode = ColorSpace.Lab)
Parameters
Type | Name | Description |
---|---|---|
string | color | A valid color string. |
double | fraction | Fraction to lighten the colors by. Defaults to 0.2, must be between 0 and 1 (inclusive). |
ColorSpace | mode | Color space to use for adjusting. Must be Lab or HSL, defaults to Lab. |
Returns
Type | Description |
---|---|
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.
Declaration
public static string Mix(string color1, string color2, double fraction = 0.5)
Parameters
Type | Name | Description |
---|---|---|
string | color1 | A valid color string. |
string | color2 | Another valid color string to mix. |
double | fraction | Fraction specifying how much color2 to mix into color1. Defaults to .5, must be between 0 and 1 (inclusive). |
Returns
Type | Description |
---|---|
string |
RandomColor(int, int)
This static function can be used to generate a random color.
Declaration
public static string RandomColor(int min = 128, int max = 255)
Parameters
Type | Name | Description |
---|---|---|
int | min | An int between 0 and 255, defaults to 128. |
int | max | An int between 0 and 255, defaults to 255. |
Returns
Type | Description |
---|---|
string | A color value in # hexadecimal format. |
ToString()
Returns a string representation of the Brush.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string | A string representation of the current Brush. |
Overrides
Operators
operator ==(Brush, Brush)
Compares if two Brushes are equal by checking their Paints.
Declaration
public static bool operator ==(Brush left, Brush right)
Parameters
Type | Name | Description |
---|---|---|
Brush | left | |
Brush | right |
Returns
Type | Description |
---|---|
bool |
implicit operator Brush(string)
Implicitly converts a string to a Brush.
Declaration
public static implicit operator Brush(string c)
Parameters
Type | Name | Description |
---|---|---|
string | c |
Returns
Type | Description |
---|---|
Brush |
operator !=(Brush, Brush)
Compares if two Brushes are not equal by checking their Paints.
Declaration
public static bool operator !=(Brush left, Brush right)
Parameters
Type | Name | Description |
---|---|---|
Brush | left | |
Brush | right |
Returns
Type | Description |
---|---|
bool |