mini_arcade_native_backend.ports.render

Render port implementation for the native backend. Provides functionality to draw shapes and manage rendering state.

Classes

RenderPort

Render port for the Mini Arcade native backend.

Module Contents

class mini_arcade_native_backend.ports.render.RenderPort(native_backend: mini_arcade_native_backend._native.Backend, vp: mini_arcade_core.backend.viewport.ViewportTransform)

Render port for the Mini Arcade native backend.

Parameters:
  • native_backend (native.Backend) – The native backend instance.

  • vp (ViewportTransform) – The viewport transform.

set_clear_color(r: int, g: int, b: int)

Set the clear color for the renderer.

Parameters:
  • r (int) – Red component (0-255).

  • g (int) – Green component (0-255).

  • b (int) – Blue component (0-255).

begin_frame()

Begin a new rendering frame.

end_frame()

End the current rendering frame.

draw_rect(x: int, y: int, w: int, h: int, color=(255, 255, 255))

Draw a filled rectangle.

Parameters:
  • x (int) – The x-coordinate of the rectangle.

  • y (int) – The y-coordinate of the rectangle.

  • w (int) – The width of the rectangle.

  • h (int) – The height of the rectangle.

  • color (tuple[int, int, int] | tuple[int, int, int, int]) – The color of the rectangle as an (R, G, B) or (R, G, B, A) tuple.

draw_line(x1: int, y1: int, x2: int, y2: int, color=(255, 255, 255), thickness: int = 1)

Draw a line between two points.

Parameters:
  • x1 (int) – The x-coordinate of the start point.

  • y1 (int) – The y-coordinate of the start point.

  • x2 (int) – The x-coordinate of the end point.

  • y2 (int) – The y-coordinate of the end point.

  • color (tuple[int, int, int] | tuple[int, int, int, int]) – The color of the line as an (R, G, B) or (R, G, B, A) tuple.

draw_circle(x: int, y: int, radius: int, color=(255, 255, 255))

Draw a filled circle.

Parameters:
  • x – Center x

  • y – Center y

  • radius – Radius in pixels

  • color – (R,G,B) or (R,G,B,A)

draw_poly(points: list[tuple[int, int]], color=(255, 255, 255), filled: bool = True)

Draw a polygon defined by a list of points.

Parameters:
  • points (list[tuple[int, int]]) – A list of (x, y) tuples defining the vertices of the polygon.

  • color (tuple[int, int, int] | tuple[int, int, int, int]) – The color of the polygon as an (R, G, B) or (R, G, B, A) tuple.

  • filled (bool) – Whether to draw a filled polygon (True) or an outline (False

set_clip_rect(x: int, y: int, w: int, h: int)

Set the clipping rectangle.

Parameters:
  • x (int) – The x-coordinate of the clipping rectangle.

  • y (int) – The y-coordinate of the clipping rectangle.

  • w (int) – The width of the clipping rectangle.

  • h (int) – The height of the clipping rectangle.

clear_clip_rect()

Clear the clipping rectangle.

create_texture_rgba(w: int, h: int, pixels: bytes, pitch: int | None = None) int

Create a texture from RGBA pixel data.

Parameters:
  • w (int) – The width of the texture.

  • h (int) – The height of the texture.

  • pixels (bytes) – The pixel data in RGBA format.

  • pitch (int | None) – The number of bytes in a row of pixel data. If None, defaults to w * 4.

destroy_texture(tex: int) None

Destroy a texture.

Parameters:

tex (int) – The texture ID to destroy.

draw_texture(tex: int, x: int, y: int, w: int, h: int, angle_deg: float = 0.0)

Draw a texture at the specified position and size.

Parameters:
  • tex (int) – The texture ID.

  • x (int) – The x-coordinate to draw the texture.

  • y (int) – The y-coordinate to draw the texture.

  • w (int) – The width to draw the texture.

  • h (int) – The height to draw the texture.

  • angle_deg (float) – Clockwise rotation angle in degrees around texture center. The native backend currently ignores non-zero rotation.

draw_texture_tiled_y(tex: int, x: int, y: int, w: int, h: int)

Draw a texture tiled vertically at the specified position and size.

Parameters:
  • tex (int) – The texture ID.

  • x (int) – The x-coordinate to draw the texture.

  • y (int) – The y-coordinate to draw the texture.

  • w (int) – The width to draw the texture.

  • h (int) – The height to draw the texture.