mini_arcade_pygame_backend.ports.render

Render port implementation for the pygame 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_pygame_backend.ports.render.RenderPort(window: mini_arcade_pygame_backend.ports.window.WindowPort, vp: mini_arcade_core.backend.viewport.ViewportTransform, background_color=(0, 0, 0))

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.

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.

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=5)

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.

create_texture_rgba(w: int, h: int, data: bytes | bytearray | memoryview, pitch: int = -1) int

Create a texture from RGBA pixel data.

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

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

  • data (bytes | bytearray | memoryview) – The pixel data in RGBA format.

  • pitch (int) – The number of bytes per row (including padding). If -1, rows are assumed to be tightly packed.

Returns:

The ID of the created texture.

Return type:

int

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 ID of the texture to draw.

  • x (int) – The x-coordinate of the top-left corner where the texture should be drawn.

  • y (int) – The y-coordinate of the top-left corner where the texture should be drawn.

  • 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.

destroy_texture(tex: int) None

Destroy a texture, freeing associated resources.

Parameters:

tex (int) – The ID of the texture to destroy.

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

Draw a texture repeated vertically to fill (w,h). Assumes you can resolve tex_id -> pygame.Surface, and supports scaling width.

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 fill the polygon (True) or draw only the outline (False).