Table of Contents

Struct Brush

Namespace
Northwoods.Go
Assembly
Northwoods.GoDiagram.WinForms.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

paint Paint

the Paint for this Brush

Brush(string)

Constructs a Brush with a SolidPaint.

public Brush(string color)

Parameters

color string

a color string

Brush(string, (float, string)[])

Constructs a Brush with a GradientPaint.

public Brush(string painttype, (float, string)[] stops)

Parameters

painttype string

a 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

Paint

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

fraction double

Fraction to darken the colors by. Defaults to 0.2, must be between 0 and 1 (inclusive).

mode ColorSpace

Color 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

color object

Returns

object

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

color string

A valid color string

fraction double

Fraction to darken the color by. Defaults to 0.2, must be between 0 and 1 (inclusive).

mode ColorSpace

Color 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

obj object

The 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

bool

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

color string

A valid color string

Returns

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.

public static bool IsValidColor(string color)

Parameters

color string

A color string to validate.

Returns

bool

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

fraction double

Fraction to lighten the colors by. Defaults to 0.2, must be between 0 and 1 (inclusive).

mode ColorSpace

Color 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

color object

Returns

object

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

color string

A valid color string.

fraction double

Fraction to lighten the colors by. Defaults to 0.2, must be between 0 and 1 (inclusive).

mode ColorSpace

Color 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

color1 string

A valid color string.

color2 string

Another valid color string to mix.

fraction double

Fraction specifying how much color2 to mix into color1. Defaults to .5, must be between 0 and 1 (inclusive).

Returns

string

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

min int

An int between 0 and 255, defaults to 128.

max int

An 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

left Brush
right Brush

Returns

bool

implicit operator Brush(string)

Implicitly converts a string to a Brush.

public static implicit operator Brush(string c)

Parameters

c string

Returns

Brush

operator !=(Brush, Brush)

Compares if two Brushes are not equal by checking their Paints.

public static bool operator !=(Brush left, Brush right)

Parameters

left Brush
right Brush

Returns

bool