▼ |  | The Racket Drawing Toolkit

1 | Overview
2 | bitmap%
3 | bitmap-dc%
4 | brush%
5 | brush-list%
6 | color%
7 | color-database<%>
8 | dc<%>
9 | dc-path%
10 | font%
11 | font-list%
12 | font-name-directory<%>
13 | gl-config%
14 | gl-context<%>
15 | linear-gradient%
16 | pdf-dc%
17 | pen%
18 | pen-list%
19 | point%
20 | post-script-dc%
21 | ps-setup%
22 | radial-gradient%
23 | record-dc%
24 | region%
25 | svg-dc%
26 | Drawing Functions
27 | Signature and Unit
28 | Unsafe Libraries
29 | Platform Dependencies
| Bibliography
| Index

On this page:

new
get-color
get-gradient
get-handle
get-stipple
get-style
get-transformation
is-immutable?
set-color
set-stipple
set-style

top ← prev up next →

> class

> brush% : class?

superclass: object%

A brush is a drawing tool with a color and a style that is used for filling in areas, such as the interior of a rectangle or ellipse. In a monochrome destination, all non-white brushes are drawn as black.

In addition to its color and style, a brush can have a brush stipple bitmap. Painting with a stipple brush is similar to calling draw-bitmap with the stipple bitmap in the filled region.

As an alternative to a color, style, and stipple, a brush can have a gradient that is a linear-gradient% or radial-gradient%. When a brush has a gradient and the target for drawing is not monochrome, then other brush settings are ignored. With a gradient, for each point in a drawing destination, the gradient associates a color to the point based on starting and ending colors and starting and ending lines (for a linear gradient) or circles (for a radial gradient); a gradient-assigned color is applied for each point that is touched when drawing with the brush.

By default, coordinates in a stipple or gradient are transformed by the drawing context’s transformation when the brush is used, but a brush can have its own brush transformation that is used, instead. A brush transformation has the same representation and meaning as for get-transformation in dc<%>.

A brush style is one of the following (but is ignored if the brush has a gradient and the target is not monochrome):

- 'transparent — Draws with no effect (on the interior of the drawn shape).

- 'solid — Draws using the brush’s color. If a monochrome brush stipple is installed into the brush, black pixels from the stipple are transferred to the destination using the brush’s color, and white pixels from the stipple are not transferred.

- 'opaque — The same as 'solid for a color brush stipple. For a monochrome stipple, white pixels from the stipple are transferred to the destination using the destination’s background color.

- 'xor — The same as 'solid, accepted only for partial backward compatibility.

- 'hilite — Draws with black and a 0.3 alpha.

- 'panel — The same as 'solid, accepted only for partial backward compatibility.

- The following modes correspond to built-in brush stipples drawn in 'solid mode:

  - 'bdiagonal-hatch — diagonal lines, top-left to bottom-right

  - 'crossdiag-hatch — crossed diagonal lines

  - 'fdiagonal-hatch — diagonal lines, top-right to bottom-left

  - 'cross-hatch — crossed horizontal and vertical lines

  - 'horizontal-hatch — horizontal lines

  - 'vertical-hatch — vertical lines

  However, when a specific brush stipple is installed into the brush, the above modes are ignored and 'solid is used, instead.

To draw outline shapes (such as unfilled boxes and ellipses), use the 'transparent brush style.

To avoid creating multiple brushes with the same characteristics, use the global brush-list% object the-brush-list, or provide a color and style to set-brush in dc<%>.

See also make-brush.

> > constructor

> > ( new brush% |
> > | [ | [color color] |
> > |  | [style style] |
> > |  | [stipple stipple] |
> > |  | [gradient gradient] |
> > |  | [transformation transformation]]) |

> → ( is-a?/c brush% )
> color : ( or/c string? ( is-a?/c color% )) = "black"

> style

> :

> ( or/c 'transparent 'solid 'opaque
> 'xor 'hilite 'panel
> 'bdiagonal-hatch 'crossdiag-hatch
> 'fdiagonal-hatch 'cross-hatch
> 'horizontal-hatch 'vertical-hatch)

> =

> 'solid

> stipple : ( or/c #f ( is-a?/c bitmap% )) = #f

> gradient

> :

> ( or/c #f
> ( is-a?/c linear-gradient% )
> ( is-a?/c radial-gradient% ))

> =

> #f

> transformation

> :

> ( or/c #f ( vector/c ( vector/c real? real? real?
> real? real? real? )
> real? real? real? real? real? ))

> |  |  | = |  | #f

Creates a brush with the given color, brush style, brush stipple, gradient, and brush transformation (which is kept only if the gradient or stipple is non-#f). For the case that the color is specified using a name, see color-database<%> for information about color names; if the name is not known, the brush’s color is black.

> > method

> > ( send a-brush get-color ) → ( is-a?/c color% )

Returns the brush’s color.

> > method

> > ( send a-brush get-gradient )

> > →

> > ( or/c ( is-a?/c linear-gradient% )
> > ( is-a?/c radial-gradient% )
> > #f)

Gets the gradient, or #f if the brush has no gradient.

> > method

> > ( send a-brush get-handle ) → ( or/c cpointer? #f)

Returns a low-level handle for the brush content, but only for brushes created with make-handle-brush; otherwise, the result is #f.

> > method

> > ( send a-brush get-stipple ) → ( or/c ( is-a?/c bitmap% ) #f)

Gets the brush stipple bitmap, or #f if the brush has no stipple.

> > method

> > ( send a-brush get-style )

> →

> ( or/c 'transparent 'solid 'opaque
> 'xor 'hilite 'panel
> 'bdiagonal-hatch 'crossdiag-hatch
> 'fdiagonal-hatch 'cross-hatch
> 'horizontal-hatch 'vertical-hatch)

Returns the brush style. See brush% for information about brush styles.

> > method

> > ( send a-brush get-transformation )

> →

> ( or/c #f ( vector/c ( vector/c real? real? real? real? real? real? )
> real? real? real? real? real? ))

Returns the brush’s brush transformation, if any.

If a brush with a stipple or gradient also has a transformation, then the transformation applies to the stipple or gradient’s coordinates instead of the target drawing context’s transformation; otherwise, the target drawing context’s transformation applies to stipple and gradient coordinates.

> > method

> > ( send a-brush is-immutable? ) → boolean?

Returns #t if the brush object is immutable.

> > method

> > ( send a-brush set-color color) → void?

> color : ( is-a?/c color% )
> ( send a-brush set-color color-name) → void?
> color-name : string?
> ( send a-brush set-color red green blue) → void?
> red : byte?
> green : byte?
> blue : byte?

Sets the brush’s color. A brush cannot be modified if it was obtained from a brush-list% or while it is selected into a drawing context.

For the case that the color is specified using a string, see color-database<%> for information about color names.

> > method

> > ( send a-brush set-stipple |  | bitmap |  |  |  |
> > | [ | transformation]) |  | → |  | void?

> bitmap : ( or/c ( is-a?/c bitmap% ) #f)

> transformation

> :

> ( or/c #f ( vector/c ( vector/c real? real? real?
> real? real? real? )
> real? real? real? real? real? ))

> |  |  | = |  | #f

Sets or removes the brush stipple bitmap, where #f removes the stipple. The brush transformation is set at the same time to transformation. See brush% for information about drawing with stipples.

If bitmap is modified while is associated with a brush, the effect on the brush is unspecified. A brush cannot be modified if it was obtained from a brush-list% or while it is selected into a drawing context.

> > method

> > ( send a-brush set-style style) → void?

> style

> :

> ( or/c 'transparent 'solid 'opaque
> 'xor 'hilite 'panel
> 'bdiagonal-hatch 'crossdiag-hatch
> 'fdiagonal-hatch 'cross-hatch
> 'horizontal-hatch 'vertical-hatch)

Sets the brush style. See brush% for information about the possible styles.

A brush cannot be modified if it was obtained from a brush-list% or while it is selected into a drawing context.
top ← prev up next →