RasterPainter

from acron.raster import RasterPainter
class RasterPainter

Bases:

Bases: TypedReferenceCount

An anti-aliased 2D painter over an 8-bit RGBA pixel store: the canvas a HUD instrument (a minimap, a compass tape, a dial, a scope trace) draws into, since RmlUi has none.

Coordinates are a 2D drawing API’s – (x, y) with y growing DOWN from the top-left, texel centres at +0.5 – and angles are a canvas’s: 0 at +x, growing toward +y. Every primitive computes its coverage analytically (a distance field, about a pixel of anti-aliasing) over its own bounding box only, so a stroke costs its own size and not the raster’s, and then composites “over” once.

The store is kept in Acron’s own RAM-image layout – BGRA, bottom row first, PREMULTIPLIED – so upload() is a memcpy into the texture and “over” is one lerp across all four channels. Draw the texture with TransparencyAttrib::M_premultiplied_alpha. Compositing rounds to 8 bits per layer: invisible for the two or three layers of a HUD.

lines() and polyline() take the union of their segments’ coverage and composite it once, so joints and crossings of one call do not darken.

Inheritance diagram

digraph inheritancebd827db6d8 { bgcolor=transparent; rankdir=BT; size="8.0, 12.0"; "DTOOL_SUPER_BASE" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style=""]; "RasterPainter" [URL="acron.raster.RasterPainter.html#acron.raster.RasterPainter",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="/**"]; "TypedReferenceCount" -> "RasterPainter" [arrowsize=0.75,style=""]; "ReferenceCount" [URL="acron.core.ReferenceCount.html#acron.core.ReferenceCount",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="/**"]; "DTOOL_SUPER_BASE" -> "ReferenceCount" [arrowsize=0.75,style=""]; "TypedObject" [URL="acron.core.TypedObject.html#acron.core.TypedObject",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="/**"]; "DTOOL_SUPER_BASE" -> "TypedObject" [arrowsize=0.75,style=""]; "TypedReferenceCount" [URL="acron.core.TypedReferenceCount.html#acron.core.TypedReferenceCount",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="/**"]; "TypedObject" -> "TypedReferenceCount" [arrowsize=0.75,style=""]; "ReferenceCount" -> "TypedReferenceCount" [arrowsize=0.75,style=""]; }
__init__()

A transparent raster of the given size.

arc()

A stroked circular arc from start to end radians (0 at +x, growing toward +y, which is DOWN); the two ends are softened by a texel’s worth of angle so a short arc does not end in a staircase.

blit()

Copies a straight-alpha RGBA8 image (top row first, src_width x src_height) in at (x, y), replacing what is there.

Copies a PNMImage in at (x, y), replacing what is there (opaque if the image has no alpha).

clear()

Empties the raster: every texel transparent.

Floods the raster with a straight-alpha colour.

property dirty → bool
disc()

A filled circle.

fill_rect()

A filled axis-aligned rectangle, anti-aliased at its edges; exact (fully opaque inside, untouched outside) on integer bounds.

static get_class_type()
get_data()

A copy of the store: BGRA, bottom row first, premultiplied – a Acron RAM image.

get_height()
get_pixel()

One texel back as straight-alpha RGBA in 0..1, in the drawing frame (y down) – what a comparison expects. Out of range is transparent.

get_width()
property height → int
is_dirty()
line()

One anti-aliased segment, width texels across.

lines()

Many independent segments of one colour, as a flat x0, y0, x1, y1, … array: tick marks, graticules. One composite for the lot.

mark_dirty()
polygon()

A filled polygon (even-odd) through a flat x, y, … array, anti-aliased by 3x3 supersampling: HUD glyphs, not scenery.

polyline()

A run of segments through a flat x, y, x, y, … array; closed joins the last point back to the first. One composite, so joints do not double up.

upload()

Copies the store into the texture’s RAM image (setting the texture up as width x height RGBA8 if it is not), when anything was drawn since the last upload or force is set. Returns whether anything was sent.

property width → int