simvx.graphics.draw2d_texture

Textured quad drawing for Draw2D.

Handles texture registration, textured quad emission, and 9-patch rendering.

Module Contents

Classes

Draw2DTextureMixin

Mixin providing textured quad drawing for Draw2D.

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 draw_texture() / draw_texture_region().

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

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

classmethod draw_texture(texture_id: int, pos, size, *, colour: tuple[float, ...] | None = None, rotation: float = 0.0, blend: str = 'alpha', screen_space: bool = False)

Draw a textured quad at pos with size size.

Position and size are (x, y) pairs, as in draw_rect / draw_line / draw_text: one shape for the whole draw family.

Args: texture_id: Bindless texture index from TextureManager. pos: Top-left (x, y) in screen pixels. size: (width, height) in screen pixels. colour: Optional RGBA tint (0.0-1.0 floats). Default white. rotation: Rotation in radians around the quad center. blend: "alpha" (default), "add", or "multiply". screen_space: When True, bypass the active Camera2D transform (HUDs, minimaps, overlays) – symmetric with draw_rect / draw_text.

classmethod draw_texture_region(texture_id: int, pos, size, uv0=(0.0, 0.0), uv1=(1.0, 1.0), colour: tuple[float, ...] | None = None, rotation: float = 0.0, *, blend: str = 'alpha', screen_space: bool = False)

Draw a sub-rectangle of a texture as a quad.

Geometry is (x, y) pairs like draw_texture and the rest of the family; the source region is its two UV corners, so the region reads as two points rather than four loose scalars.

Args: texture_id: Bindless texture index. pos: Top-left (x, y) in screen pixels. size: (width, height) in screen pixels. uv0: (u, v) of the source region’s top-left corner (0-1). uv1: (u, v) of the source region’s bottom-right corner (0-1). colour: Optional RGBA tint (0.0-1.0 floats). Default white. rotation: Rotation in radians around the quad center. blend: "alpha" (default), "add", or "multiply". screen_space: When True, bypass the active Camera2D transform so a single textured overlay/HUD quad stays screen-pinned inside a world on_draw – symmetric with the other primitives.

classmethod draw_image(path: str | pathlib.Path, x: float, y: float, w: float, h: float, *, colour: tuple[float, ...] | None = None, rotation: float = 0.0, filter: str = 'linear', blend: str = 'alpha')

Draw an image file as a quad. Path-cached.

Resolves path through the running App’s TextureManager (one entry per (resolved_path, filter) pair) and emits a textured quad. Subsequent frames reuse the cached texture id, so an on_draw that calls draw_image("hero.png", ...) every frame does one disk read and one GPU upload total.

Returns silently when no App / engine is available (CPU-only mode); callers that need explicit handling should use draw_texture() with a manually-resolved id.

classmethod draw_nine_patch(texture_id: int, x: float, y: float, w: float, h: float, tex_w: float, tex_h: float, margin_left: float = 0.0, margin_right: float = 0.0, margin_top: float = 0.0, margin_bottom: float = 0.0, draw_centre: bool = True, colour: tuple[float, ...] | None = None)

Draw a 9-slice textured rectangle.

Divides the source texture into 9 regions using the margin values. Corners remain fixed-size, edges stretch in one direction, and the centre fills the remaining space. This is the standard 9-patch / 9-slice technique for scalable UI panels, buttons, and speech bubbles.

Args: texture_id: Bindless texture index from TextureManager. x, y: Top-left position in screen pixels. w, h: Display width and height in screen pixels. tex_w, tex_h: Source texture dimensions in pixels. margin_left, margin_right: Left/right border widths (pixels in source texture). margin_top, margin_bottom: Top/bottom border heights (pixels in source texture). draw_centre: Whether to draw the centre region (default True). colour: Optional RGBA tint (0.0-1.0 floats). Default white.