Style types

The types a style is made of.

Blend

Blend()

How new shapes combine with what is already drawn.

kiln.blend(Blend.ADD) and kiln.blend("add") are the same. With colour src, alpha a and the colour already drawn dst:

  • REPLACE: src replaces dst, alpha included (no anti-aliasing). A pixel is drawn when the shape covers at least half of it, and a stroke thinner than one pixel (1 pt, or 0.5 pt on a Retina display) when it covers half its own width, so a thin line still shows (one pixel wide). The target’s alpha becomes src’s, so drawing a translucent colour leaves translucent pixels; call clear_alpha to make them opaque again.
  • ALPHA: src * a + dst * (1 - a), the default.
  • ADD: dst + src * a.
  • SUBTRACT: dst - src * a.
  • MULTIPLY: dst * (1 - a + a * src), which is src * dst at full alpha.
  • SCREEN: dst + src * a * (1 - dst).

RectMode

RectMode()

How rect and image.draw read their x, y.

Ellipses and circles are always centred on (x, y), whatever the rect mode.

  • CORNER: (x, y) is the top-left corner, the default.
  • CENTER: (x, y) is the centre.

Style

Style(
    fill=(255, 255, 255, 255),
    stroke=None,
    stroke_width=1.0,
    tint=(255, 255, 255, 255),
    blend=Blend.ALPHA,
    rect_mode=RectMode.CORNER,
    winding=Winding.ODD,
    curve_resolution=20,
)

The current drawing style.

current_style returns a copy and style applies one, so a style can be kept, compared and restored. A style is plain data: edit a copy’s fields, then pass it to style. with style(): saves and restores every field (through copy).

Shapes are filled in fill and then outlined in stroke; lines take stroke, else fill; text takes fill and is never outlined; an Image, Texture, Fbo, Mesh, Vbo or Field .draw() takes tint. A colour of None draws nothing.

Attributes

Name Type Description
fill _RGBA | ColorLike | None The fill colour as four numbers in 0-255 (r, g, b, a), not clamped, or None for no fill. style() accepts every form fill() does.
stroke _RGBA | ColorLike | None The outline colour the same way, or None (the default) for no outline.
stroke_width float Outline and line width in points (>= 0) on screen, whatever the current transform.
tint _RGBA | ColorLike The colour that multiplies images, textures, Fbos, meshes, Vbos and fields as they are drawn, 0-255; white by default.
blend Blend | BlendValue How shapes blend with the target. Change it only through Renderer2D.set_blend_mode or Renderer2D.restore_style, which keep draw segments in order.
rect_mode RectMode | RectModeValue Whether rectangle coordinates are the corner or the centre.
winding Winding | WindingValue The winding rule that fills custom shapes.
curve_resolution int Points per curve_vertex stretch and per bezier (>= 1).

Methods

Name Description
copy Returns an independent copy with every field.

copy

Style.copy()

Returns an independent copy with every field.

Built field by field because style() calls it on the hot path (dataclasses.replace is ~5x slower). A new field must be added here; tests/test_transform_render.py checks that every field is copied.

Returns
Name Type Description
Style A new Style equal to this one.

typing.ColorLike

typing.ColorLike

What a colour argument accepts: a Color, a colour string, a gray level, or (r, g, b[, a]) channels (a sequence or a numpy array).

typing.BlendValue

typing.BlendValue

typing.RectModeValue

typing.RectModeValue

typing.WindingValue

typing.WindingValue

typing.TextureFormatValue

typing.TextureFormatValue

typing.TextureFilterValue

typing.TextureFilterValue

typing.TextureWrapValue

typing.TextureWrapValue

typing.PrimitiveModeValue

typing.PrimitiveModeValue

typing.BufferUsageValue

typing.BufferUsageValue