Managing draw style

In previous sections we briefly talked about controlling the appearance of drawing primitives using fill, stroke and lineCap. In this section we present the existing draw style properties.

DrawStyle properties

PropertyTypeDefaultDescription
fillColorRGBa?ColorRGBa.WHITEThe fill color
strokeColorRGBa?ColorRGBa.BLACKThe stroke color
strokeWeightDouble1.0The stroke weight
smoothBooleantrueShould contours and segments look smooth or pixelated?
lineCapLineCapLineCap.BUTTThe segment cap style
lineJoinLineJoinLineJoin.MITERThe segment join style
miterLimitDouble4.0The segment join maximum miter length
fontMapFontMap?nullThe font to use
kerningKernModeKernMode.METRICThe kerning mode used for rendering text
textSettingTextSettingModeTextSettingMode.SUBPIXELThe text setting mode
colorMatrixMatrix55Matrix55.IDENTITYThe color matrix (used for images)
channelWriteMaskChannelMaskChannelMask.ALLThe channel write mask
shadeStyleShadeStyle?nullThe shade style
blendModeBlendModeBlendMode.OVERThe blend mode
qualityDrawQualityDrawQuality.QUALITYA hint that controls the quality of some primitives
cullTestPassCullTestPassCullTestPass.ALWAYSWhat fragments be rendered: back or front facing?
depthTestPassDepthTestPassDepthTestPass.ALWAYSWhen should fragments pass the depth test
depthWriteBooleanfalseShould the fragment depth be written to the depth buffer?
stencilStencilStyleStencilStyle()The stencil style
frontStencilStencilStyleStencilStyle()The stencil style for front-facing fragments
backStencilStencilStyleStencilStyle()The stencil style for back-facing fragments
clipRectangle?nullA rectangle that describes where drawing will take place

The active draw style

val active = drawer.drawStyle.copy()

The draw style stack

Styles can be pushed on and popped from a stack maintained by Drawer.

extend {
    drawer.pushStyle()
    drawer.fill = ColorRGBa.PINK
    drawer.rectangle(100.0, 100.0, 100.0, 100.0)
    drawer.popStyle()
    // colorMatrix, channelWriteMask, blendMode, quality, stencil, frontStencil, backStencil, clip
    drawer.drawStyle
}

The Drawer provides a helper function called isolated {} that pushes style and transforms on a their respective stacks, executes the user code and pops style and transforms back.

extend {
    drawer.isolated {
        fill = ColorRGBa.PINK
        rectangle(100.0, 100.0, 100.0, 100.0)
    }
}

edit on GitHub