Module gui::gui_canvas
GUI: the anti-aliased 2D vector canvas.
A software rasterizer with the drawing model of the HTML canvas / Skia / Cairo family, drawing into a GuiWindow's pixel buffer or a GuiImage:
paths move/line/quadratic/cubic/arc/close (gui_path.h), filled by
the nonzero or even-odd rule, stroked with any width, miter/
round/bevel joins, butt/round/square caps and dash patterns
paint solid colors, linear / radial (two-circle) / sweep
gradients with up to 16 stops and pad/repeat/reflect spread,
and image patterns (any transform, clamp/repeat/none,
nearest or bilinear sampling)
state an affine transform, global alpha, blend mode, rectangular
and path clipping, all saved/restored with save()/restore()
compositing premultiplied alpha; 12 Porter-Duff operators and 12
separable blend modes (multiply, screen, overlay, ...)
images drawn scaled/rotated/cropped with filtering
text TrueType glyphs from gui_text.h, anti-aliased and cached
Anti-aliasing is exact in x and 16x supersampled in y: each pixel row is cut by 16 sample lines and every edge crossing contributes its exact horizontal coverage, accumulated in a difference buffer and integrated once per row — so a pixel's coverage is the true area inside the shape to within 1/16 of a pixel vertically, for either fill rule, with overlapping and self-intersecting paths. Compositing runs four channels at a time on SIMD vectors (vec<float, 4>, std/simd's f32x4); solid opaque spans are filled with plain 32-bit stores. Everything is deterministic: the same calls produce the same bytes on every platform.
struct GuiCanvas c = GuiCanvas::for_window(&win);
c.clear(GuiColor::hex(0xFFFFFFU));
c.set_fill_color(GuiColor::hex(0x3366CCU));
c.fill_rounded_rect(20.0f, 20.0f, 120.0f, 40.0f, 8.0f);
c.set_stroke_color(GuiColor::hex(0x000000U));
c.set_line_width(2.0f);
c.begin_path(); c.move_to(20.0f, 80.0f); c.line_to(140.0f, 120.0f); c.stroke();
c.set_font(GuiTypeface::fallback(), 16.0f);
c.fill_text("Hello", 20.0f, 150.0f);
c.free();
win.present();
A canvas holds no copy of the pixels, only a pointer: after the window is resized (its buffer reallocated), point the canvas at it again with retarget_window().
Structs
| GuiColorStop | |
| GuiPaint | What to fill or stroke with. A value type: build one, add stops, hand it to set_fill_paint()/set_stroke_paint() (which copy it). |
| GuiCanvasState | Everything save()/restore() saves. |
| GuiEdge | A line segment of a flattened path, in device space (internal). |
| GuiCanvas |