simvx.graphics.draw2d_texture

Textured quad drawing for Draw2D.

Handles texture source resolution, textured quad emission, and 9-patch drawing.

One entry point, texture(source, pos, size, ...), covers every way a caller can name an image: a bindless id it already holds, or any source a Sprite2D’s texture takes (a file path, encoded bytes, an RGBA array, a Texture resource, a live offscreen target). An int is used as the slot directly and never touches the running App, so the sprite hot path stays a single quad append; anything else is resolved through the App’s TextureManager and cached.

Module Contents

Classes

Draw2DTextureMixin

Mixin providing textured quad drawing for Draw2D.

Functions

nine_patch_slices

The nine quads a 9-slice decomposes into, as (pos, size, region) triples.

Data

log

API

simvx.graphics.draw2d_texture.log

‘getLogger(…)’

class simvx.graphics.draw2d_texture.Draw2DTextureMixin

Mixin providing textured quad drawing for Draw2D.

classmethod register_texture(png_data: bytes) → int

Register a CPU-side texture for streaming. Returns a texture ID.

Use this in CPU-only mode (web editor) where there’s no GPU TextureManager. The returned ID can be passed to texture() as its source.

classmethod register_texture_with_id(texture_id: int, png_data: bytes) → None

Register PNG data for a known texture ID (for streaming sync).

classmethod texture(source, pos, size, *, region=None, tint=None, rotation: float = 0.0, blend: str = 'alpha', filter: str = 'linear')

Draw an image as a quad at pos with size size.

Position and size are (x, y) pairs, as in rect / line / text: one shape for the whole draw family.

Args: source: A bindless texture index, or anything Sprite2D(texture=...) accepts: a file path, encoded image bytes, an RGBA uint8 array, a Texture resource, or a live offscreen target. pos: Top-left (x, y). size: (width, height). region: The sub-rectangle of the image to sample, as its two UV corners ((u0, v0), (u1, v1)) in 0-1. None draws the whole image. The corners may be crossed to mirror the quad. tint: RGBA multiplier on the sampled pixels (0.0-1.0 floats). None draws the image untinted; unlike a fill, a tint is not paint, so leaving it out is not asking for nothing. rotation: Rotation in radians around the quad centre. blend: "alpha" (default), "add", or "multiply". filter: Sampler used when source has to be resolved: "linear" (default) or "nearest". Ignored for an int source, whose slot already carries a sampler.

A source that cannot be resolved (no running App, a missing file) draws nothing rather than raising, so a scene keeps running with a hole in it.

classmethod nine_patch(source, pos, size, *, texture_size, margins=(0.0, 0.0, 0.0, 0.0), draw_centre: bool = True, tint=None, filter: str = 'linear')

Draw a 9-slice textured rectangle.

Divides the source image into 9 regions using the margin values. Corners keep their size, edges stretch in one direction, and the centre fills the remaining space: the standard technique for scalable UI panels, buttons and speech bubbles.

Args: source: Anything texture() takes. pos: Top-left (x, y). size: Displayed (width, height). texture_size: The source image’s (width, height) in pixels, which the margins are measured against. margins: (left, right, top, bottom) border sizes, in source pixels. draw_centre: Whether to draw the centre region (default True). tint: RGBA multiplier on the sampled pixels. None is untinted. filter: Sampler used when source has to be resolved.

simvx.graphics.draw2d_texture.nine_patch_slices(pos, size, texture_size, margins, draw_centre)

The nine quads a 9-slice decomposes into, as (pos, size, region) triples.

Corners keep their source size, edges stretch along one axis and the centre takes what is left; a slice with no area on either side is dropped, and margins are clamped so an oversized border cannot fold the destination inside out. Both live drawing surfaces walk this, so a panel drawn straight and the same panel captured into an item row are the same nine quads in the same order.