Skip to content

UXCanvasGraphics

UXCanvasGraphics is the Canvas2D realization of UXGraphics. The web backend draws through it.

#use <UXKit> // or #import "UXCanvasGraphics.xc"

It is the sibling of UXGdiGraphics: the same primitives every drawRect calls, over host canvas imports instead of a device context.

Coordinates passed in are bounds-relative, and the bound origin makes them absolute, as on the other backends. Canvas2D’s y grows down, so nothing needs flipping.

The important number is how few imports there are. Together with the window group and the ring, eight drawing primitives make up the entire JS surface. That lets the structural half of the toolkit run with zero crossings.

i32 penR(i32 pen) { … } // and penG, penB

The toolkit draws with VDI pen indices. Resolving an index to a colour happens xtc-side, so the JS surface only sees r, g, b.

There are two reasons. A pen table in JS would be a second copy of the table in UXGdiGraphics, free to drift. And the import signature would have to take a pen, so the host would need to know what a pen is. The boundary exists to keep that knowledge out of the host.

The colour is split per channel instead of packed because the import signature takes three integers. Packing would save a parameter and require the host to unpack, which brings back host-side knowledge for no benefit.

hasThemeArt() // true

Unlike GDI and Cocoa, the canvas backend can draw theme slices, so drawTheme does something here.

It is one of two backends out of seven that answer yes, alongside UXGemGraphics. The capability queries track what a surface can do, not how modern it is.

strokesNatively() // true

Canvas2D has a real stroker with joins and caps, so paths go to it directly. Arrowheads stay neutral, as on every backend.