Documentation
¶
Overview ¶
Package gpupainter is a go-widgets painter.Painter that records what a widget draws into a go-gfx/gpu2d list, which a GPU back-end (gpu2d/webgpu in a browser, gpu2d/metal on a Mac) then draws in one submission. It implements every capability PixelPainter has (clip, translation, masks, images, paths, the built-in font and its scale) and the list it records renders byte-identical to what PixelPainter draws.
Index ¶
- type Painter
- func (p *Painter) DrawImage(dst painter.Rect, src []byte, srcW, srcH int)
- func (p *Painter) DrawMask(dst painter.Rect, mask []byte, stride int, ink painter.RGBA)
- func (p *Painter) FillPath(pth *painter.Path, c painter.RGBA, rule painter.FillRule)
- func (p *Painter) FillRect(r painter.Rect, c painter.RGBA)
- func (p *Painter) FillRoundRect(r painter.Rect, radius int, c painter.RGBA)
- func (p *Painter) Flush()
- func (p *Painter) List() *gpu2d.List
- func (p *Painter) PopClip()
- func (p *Painter) PopTranslate()
- func (p *Painter) PushClip(r painter.Rect)
- func (p *Painter) PushTranslate(dx, dy int)
- func (p *Painter) PutPixel(x, y int, c painter.RGBA)
- func (p *Painter) Raster()
- func (p *Painter) Reset(l *gpu2d.List)
- func (p *Painter) SetTextScale(n int)
- func (p *Painter) Size() (int, int)
- func (p *Painter) StrokePath(pth *painter.Path, c painter.RGBA, width float64)
- func (p *Painter) StrokeRect(r painter.Rect, c painter.RGBA, lineW int)
- func (p *Painter) StrokeRoundRect(r painter.Rect, radius int, c painter.RGBA, lineW int)
- func (p *Painter) Text(x, y int, s string, ink painter.RGBA)
- func (p *Painter) TextHeight() int
- func (p *Painter) TextScale() int
- func (p *Painter) TextWidth(s string) int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Painter ¶
type Painter struct {
// contains filtered or unexported fields
}
Painter records into a gpu2d list. The list is the caller's: Reset it between frames, and take it with List (or call Flush) before handing it to a renderer, so that pixels still being batched are recorded.
func (*Painter) FillRoundRect ¶
FillRoundRect fills r with anti-aliased corners of the given radius.
func (*Painter) Flush ¶ added in v0.2.0
func (p *Painter) Flush()
Flush records any pixels still pending. List flushes too; a caller that keeps the list from New and hands it to a renderer calls Flush first.
func (*Painter) PopTranslate ¶
func (p *Painter) PopTranslate()
PopTranslate removes the innermost translation.
func (*Painter) PushClip ¶
PushClip confines drawing to r, translated and intersected as PixelPainter does.
func (*Painter) PushTranslate ¶
PushTranslate shifts what is drawn after it. The painter keeps its own copy of the offset for paths, which reach the rasterizer in surface pixels.
func (*Painter) Raster ¶ added in v0.4.0
func (p *Painter) Raster()
Raster marks the Painter as a painter.RasterPainter: PutPixel lands exactly PixelPainter's pixel (batched into an image, blended identically). Code that composes pixel by pixel, such as the toolkit's bitmap font, therefore sends it the same pixels it sends PixelPainter rather than a Text call.
func (*Painter) Reset ¶ added in v0.3.0
Reset points the painter at l and returns it to the state New leaves it in: no pending pixels (they are dropped, not recorded: Flush first to keep them), no translation, text scale 1. It keeps every scratch buffer (the glyph surface, the pixel-run patch and index), so a painter reused for each frame allocates nothing once its buffers have grown. It does not reset l: call l.Reset() for a new frame, then p.Reset(l) (or p.Reset(p.List())).
func (*Painter) SetTextScale ¶
SetTextScale magnifies the built-in font by a whole number (1 at least).
func (*Painter) StrokePath ¶
StrokePath paints pth's outline width pixels wide.
func (*Painter) StrokeRect ¶
StrokeRect paints lineW concentric outlines inward from r's edge.
func (*Painter) StrokeRoundRect ¶
StrokeRoundRect paints lineW concentric rounded outlines.
func (*Painter) Text ¶
Text paints s in the built-in 5 × 7 font. PixelPainter lights each glyph bit with PutPixel (or an n × n fill when magnified) in the ink, and glyphs never overlap; so the string is drawn once in opaque white into a scratch buffer with PixelPainter itself, and its alpha goes through DrawMask with the real ink. Coverage 255 blends exactly as PutPixel(ink) does.
func (*Painter) TextHeight ¶
TextHeight is how tall a line of the built-in font is drawn.