factoriax.playground.ui.scaling#

Fixed-resolution canvas with integer scaling to a pygame window.

All menu and UI drawing happens on a fixed-size pygame surface. At the end of each frame the canvas is integer-scaled and centered on the actual display surface with black letterboxing. This ensures pixel-perfect layout regardless of the window size.

class factoriax.playground.ui.scaling.ScaledCanvas(base_size: int, ui_scale: int, window: Surface)#

A fixed-size pygame surface that integer-scales to the window.

handle_resize(window_w: int, window_h: int) → None#

Recompute scale and offsets after a window resize event.

Parameters:
  • window_w – New window width in pixels.

  • window_h – New window height in pixels.

property height: int#

Canvas height in pixels.

present(screen: Surface) → None#

Scale the canvas and blit it centered onto the display surface.

Fills the screen with black for letterboxing, integer-scales the canvas, and blits it centered.

Parameters:

screen – The pygame display surface.

property surface: Surface#

The fixed-size drawing target.

to_canvas(window_x: int, window_y: int) → tuple[int, int]#

Transform window pixel coordinates to canvas coordinates.

Parameters:
  • window_x – X position in window pixels.

  • window_y – Y position in window pixels.

property width: int#

Canvas width in pixels.