2.3.3 brush%

► |  | GUI: Racket Graphics Toolkit

1 | Overview
2 | Reference
3 | Configuration
4 | Dynamic Loading
| Bibliography
| Index

► | 2 | Reference

2.1 | Windowing Classes
2.2 | Windowing Functions
2.3 | Drawing Classes
2.4 | Drawing Functions
2.5 | Editor Classes
2.6 | Editor Functions
2.7 | WXME Decoding

▼ | 2.3 | Drawing Classes

2.3.1 | bitmap%
2.3.2 | bitmap-dc%
2.3.3 | brush%
2.3.4 | brush-list%
2.3.5 | color%
2.3.6 | color-database<%>
2.3.7 | dc<%>
2.3.8 | dc-path%
2.3.9 | font%
2.3.10 | font-list%
2.3.11 | font-name-directory<%>
2.3.12 | gl-config%
2.3.13 | gl-context<%>
2.3.14 | pen%
2.3.15 | pen-list%
2.3.16 | point%
2.3.17 | post-script-dc%
2.3.18 | printer-dc%
2.3.19 | ps-setup%
2.3.20 | region%

On this page:

get-color
get-stipple
get-style
set-color
set-stipple
set-style

top← prev up next →

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. On a monochrome display, all non-white brushes are drawn as black.

In addition to its color and style, a brush can have a stipple bitmap. This stipple is used only in unsmoothed mode (see set-smoothing) or in a PostScript drawing context. Painting with a stipple brush is similar to calling draw-bitmap with the stipple bitmap in the filled region, except that the bitmap may not be scaled in the same way (depending on the platform and device).

A brush’s style is one of the following:

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

- 'solid – Draws using the brush’s color. If a monochrome 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 – Same as 'solid, except when a monochrome stipple is installed for unsmoothed or PostScript drawing; in that case, white pixels from the stipple are transferred to the destination using the destination’s background color.

- 'xor – In a smoothing mode or if a color stipple is installed, 'xor is treated as 'solid. Otherwise, the brush’s color or colored (monochrome) stipple is xor-ed with existing destination pixel values. The 'xor mapping is unspecified for arbitrary color combinations, but the mapping provides two guarantees:

  - Black-and-white drawing to a color or monochrome destination always works as expected: black xor white = black, white xor black = black, black xor black = white, and white xor white = white.

  - Performing the same drawing operation twice in a row with 'xor is equivalent to a no-op.

- 'hilite – In unsmoothed mode, existing destination pixels are “highlighted” in a platform-specific way when the brush color is black. Under Windows and X for a color drawing context, the inverted RGB components of destination pixel are combined with the RGB components of the system-wide highlight color using a bitwise “or”, and the combination is used. (Under X, the color is specified by the 'GRacket:hiliteColor preference preference; see Preferences.) Under Mac OS X for a color drawing context, the inverted RGB components of the system-wide highlight color are subtracted from the RGB components of each destination pixel, and the difference (or 0 for a negative result) is used. For any monochrome drawing context, 'hilite is the same as 'xor. For PostScript output, 'hilite uses a stipple that is an array of small dots (essentially a halftone), otherwise 'hilite is treated like 'solid in a smoothing mode.

- 'panel – In unsmoothed mode, draws with the same color and pattern as a top-level panel background, if the brush’s color is the same as the color returned by get-panel-background and if the brush has no stipple. To create a canvas% object that is drawn like a control, use the 'transparent canvas style instead, because certain kinds of nested panels have different background colors (e.g., a tab-panel% under Mac OS X). In a smoothing mode, 'panel is treated as 'solid.

- The following modes correspond to built-in 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 stipple is installed into the brush for when drawing with a smoothing mode into a non-PostScript context, 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. See set-style for more information about styles.

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<%>.

( make-object brush%) → ( is-a?/c brush%)
( make-object brush% color style) → ( is-a?/c brush%)
color : ( is-a?/c color%)

style

:

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

( make-object brush% color-name style) → ( is-a?/c brush%)
color-name : string?

style

:

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

When no argument are provided, the result is a solid black brush. Otherwise, the result is a brush with the given color and style. 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.

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

Returns the brush’s color.

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

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

( send a-brush get-style)

→

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

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

( 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 : ( integer-in 0 255)
green : ( integer-in 0 255)
blue : ( integer-in 0 255)

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.

( send a-brush set-stipple bitmap) → void?
bitmap : ( or/c ( is-a?/c bitmap%) false/c)

Sets or removes the stipple bitmap, where #f removes the stipple. See brush% for information about drawing with stipples.

A bitmap cannot be used as a stipple if it is selected into a bitmap-dc% object; if the given bitmap is selected into a bitmap-dc% object, an exn:fail:contract exception is raised. A brush cannot be modified if it was obtained from a brush-list% or while it is selected into a drawing context.

A pen’s stipple is not used in a smoothing mode, except for a post-script-dc% (which is always in a smoothing mode).

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

style

:

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

Sets the brush’s 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 →