simvx.graphics.draw2d

Immediate-mode 2D drawing API for Vulkan backend.

Canonical API: one entry point per primitive, keyword-only colour/filled/thickness:

Draw2D.draw_rect(pos, size, *, colour=None, filled=False, thickness=1.0)
Draw2D.draw_line(a, b, *, colour=None, thickness=1.0)
Draw2D.draw_circle(center, radius, *, colour=None, filled=False, segments=32)
Draw2D.draw_text(text, pos, *, colour=None, scale=1.0)

Colour values are RGBA float tuples in [0, 1] (3-tuples default alpha to 1.0). None means opaque white. Designers thinking in 0-255 / hex should use simvx.core.properties.Colour.from_rgb255(...) or Colour.hex(...) to convert to the canonical float form.

Every call appends one Op to Draw2D._ops; Draw2DPass walks that list in submission order. Submission order is the GPU order; there is no other ordering mechanism.

Module Contents

Classes

Draw2D

Vulkan-backed immediate-mode 2D drawing API.

Data

API

simvx.graphics.draw2d.__all__

[‘Draw2D’, ‘UI_VERTEX_DTYPE’]

class simvx.graphics.draw2d.Draw2D[source]

Bases: simvx.graphics.draw2d_transform.Draw2DTransformMixin, simvx.graphics.draw2d_text.Draw2DTextMixin, simvx.graphics.draw2d_texture.Draw2DTextureMixin

Vulkan-backed immediate-mode 2D drawing API.

Owns the ordered ops list (_ops) and the scissor clip stack (_clip_stack / _current_clip). Every Draw2D submission appends a single Op to _ops; Draw2DPass walks the list in order and coalesces adjacent same-(kind, clip, tex_id) ops into one GPU draw. Submission order is the GPU order; there is no other ordering mechanism. push_clip / pop_clip / reset_clip are the only public hooks that mutate state without emitting an op.

classmethod push_clip(x: int, y: int, w: int, h: int) None[source]

Push a scissor clip rect; nested clips intersect with the current clip.

classmethod pop_clip() None[source]

Pop the last clip rect, restoring the previous one.

classmethod reset_clip() None[source]

Clear the clip stack and current clip, restoring full-screen drawing.

classmethod draw_rect(pos, size, *, colour=None, filled=False, thickness=1.0, screen_space=False) None[source]

Draw a rectangle. filled=False draws an outline, filled=True fills the rect.

thickness controls outline weight (filled=False); 1 px outlines ride the line pipeline, thicker outlines emit four filled rectangles (one per edge). screen_space=True bypasses the active Camera2D transform (HUDs, minimaps, overlays).

classmethod draw_line(a, b, *, colour=None, thickness=1.0, screen_space=False) None[source]

Draw a line from a to b.

thickness <= 1 rides the 1-px line pipeline; thickness > 1 emits an oriented filled quad with perpendicular offsets so the weight is GPU-honoured rather than driver-clamped. screen_space=True bypasses the active Camera2D transform.

classmethod draw_lines(points, closed=True, colour=None)[source]

Draw a polyline (optionally closed) through the given points.

classmethod draw_circle(center, radius, *, colour=None, filled=False, segments=32, screen_space=False) None[source]

Draw a circle. filled=False draws an outline, filled=True fills a triangle fan.

Set screen_space=True to bypass the active Camera2D transform.

classmethod fill_triangle(x1, y1, x2, y2, x3, y3, *, colour=None)[source]

Emit a single filled triangle.

classmethod fill_quad(x1, y1, x2, y2, x3, y3, x4, y4, *, colour=None)[source]

Emit a filled quad from four arbitrary corners (two triangles).

classmethod draw_thick_line(x1, y1, x2, y2, width=2.0, *, colour=None)[source]

Draw a thick line as a filled quad using perpendicular offsets.

classmethod draw_polygon(vertices, *, colour=None, filled=True)[source]

Fill or outline an arbitrary polygon.

filled=True (default) triangulates via ear-clipping so concave shapes render correctly. Convex polygons hit a fast triangle-fan path. filled=False emits a closed line ring.

classmethod fill_rect_gradient(x, y, w, h, colour_top, colour_bottom)[source]

Fill rect with vertical gradient (top colour -> bottom colour).

classmethod clear(r=0, g=0, b=0)[source]
classmethod present()[source]
classmethod push_transform(a, b, c, d, tx, ty)
classmethod pop_transform()
classmethod push_identity()
classmethod screen_space()
classmethod set_font(path: str | None = None, size: int = 48) None
classmethod draw_text(text, pos=None, *, colour=None, scale=1.0, rect=None, alignment='left', vertical_alignment='top', fit_to_width=False, min_scale=None)
classmethod text_height(text, scale=1.0)
classmethod text_size(text, scale=1.0)
classmethod fit_scale(text, max_width, *, base_scale=1.0, min_scale=None)
classmethod text_width(text, scale=1)
classmethod register_texture(png_data: bytes) int
classmethod register_texture_with_id(texture_id: int, png_data: bytes) None
classmethod draw_texture(texture_id: int, x: float, y: float, w: float, h: float, colour: tuple[float, ...] | None = None, rotation: float = 0.0)
classmethod draw_texture_region(texture_id: int, x: float, y: float, w: float, h: float, u0: float = 0.0, v0: float = 0.0, u1: float = 1.0, v1: float = 1.0, colour: tuple[float, ...] | None = None, rotation: float = 0.0)
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')
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)